Commit 2322bc6c by mohammed.shibili

exception

parent ce9b003c
......@@ -5,6 +5,9 @@ from script.config.appconfig import csv_path
# reading csv
def csv_read():
dataset = pd.read_csv(csv_path)
dict_dataset = dataset.to_dict(orient='records')
return dict_dataset
try:
dataset = pd.read_csv(csv_path)
dict_dataset = dataset.to_dict(orient='records')
return dict_dataset
except Exception as e:
print("reading error", e)
......@@ -13,41 +13,56 @@ app = FastAPI()
# read --> get
@app.get("/get_all")
async def get_element():
datas = table_1.objects.to_json()
datas_list = json.loads(datas)
return datas_list
try:
datas = table_1.objects.to_json()
datas_list = json.loads(datas)
return datas_list
except Exception as e:
print("error in get", e)
# insert many -->post
@app.post("/insertall", tags=['FIRST'])
async def post_all_element():
collection_name.insert_many(dict_from_file)
return "data inserted"
try:
collection_name.insert_many(dict_from_file)
return "data inserted"
except Exception as e:
print("error in post all", e)
#
# insert --> post
@app.post("/insert", tags=['FIRST'])
async def post_element(body: insert_post):
new_data = insert_post(id=body.id, first_name=body.first_name, last_name=body.last_name, gender=body.gender)
collection_name.insert_one(dict(new_data))
return {"inserted data": dict(new_data)}
try:
new_data = insert_post(id=body.id, first_name=body.first_name, last_name=body.last_name, gender=body.gender)
collection_name.insert_one(dict(new_data))
return {"inserted data": dict(new_data)}
except Exception as e:
print("error in insert", e)
# update --> put
@app.put("/update", tags=['FIRST'])
async def put_element(user_id: int, body: dict):
collection_name.update_one({"id": user_id}, {"$set": {"first_name": body["first_name"]}})
return {
"data": f'name updated'
}
try:
collection_name.update_one({"id": user_id}, {"$set": {"first_name": body["first_name"]}})
return {
"data": f'name updated'
}
except Exception as e:
print("error while update", e)
# delete
@app.delete("/delete", tags=['FIRST'])
async def delete_element(user_id: int):
collection_name.delete_one({"id": user_id})
return {"data": f'details of {user_id} deleted'}
try:
collection_name.delete_one({"id": user_id})
return {"data": f'details of {user_id} deleted'}
except Exception as e:
print("delete error", e)
collection_name = mongo_connection()
......
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