Commit 9079c3c0 by arjun.b

debug the project

parent 3c3c1ada
import logging
from fastapi import FastAPI, UploadFile
from mongoengine import connect
from scripts.config.application_config import port_connect
from scripts.constants.end_points import EndPoints
from scripts.core.handlers.fastapi_handler import fastAPIHandler
from scripts.database.model import employee_insert, employee_update
import pandas as pd
app = FastAPI()
connect(db="employees", host="localhost", port=int(port_connect))
@app.get("/")
async def root():
return {"data": "FastAPI CRUD Operations"}
# upload and insert into database
@app.post(EndPoints.upload, tags=["upload file"])
async def upload_file(file: UploadFile):
try:
file_content = pd.read_csv(file.file)
fastAPIHandler.file_upload(file_content)
return {"data": "CSV data uploaded successfully"}
except Exception as e:
logging.error(f'upload file failed:{e}')
print(e)
# insert data using post method
@app.post(EndPoints.send_data, tags=['send data'])
def send_data(emp: employee_insert):
try:
fastAPIHandler.insert_data(emp)
return {"message": "new data has been inserted"}
except Exception as e:
logging.error(f'inserting a document failed {e}')
# update data
@app.put(EndPoints.update, tags=["update database"])
def update_data(doc_id: int, details: employee_update):
try:
fastAPIHandler.update_data(doc_id, details)
return {"data": "data updated"}
except Exception as e:
logging.error(f'updating the data failed {e}')
# delete data
@app.delete(EndPoints.delete, tags=["delete data"])
def delete_data(doc_id: int):
try:
fastAPIHandler.delete_data(doc_id)
return {"data": "data deleted"}
except Exception as e:
logging.error(f'deleting a document failed {e}')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment