Commit 52a0c926 authored by Hansi rathnayaka's avatar Hansi rathnayaka

API modifications

parent 4f75f520
......@@ -5,7 +5,7 @@ import re
from os import error
from bson.objectid import ObjectId
from schemas.doctor import doctorEntity, doctorsEntity
from schemas.doctor import doctorEntity, doctorsEntity, doctorGetEntity
from schemas.availability import availabilityEntity, availabilitiesEntity
from fastapi import APIRouter
from models.doctor import Doctor
......@@ -30,8 +30,7 @@ async def find_one_doctor(id):
async def create_doctor(doctor: Doctor):
try:
conn.skinDiseaseDB.doctor.insert_one(dict(doctor))
return doctorEntity(conn.skinDiseaseDB.doctor.find_one({"id":doctor.id}))
#return {"success": True}
return {"success": True}
except error:
return {"success": False, "msg": error}
......@@ -39,7 +38,7 @@ async def create_doctor(doctor: Doctor):
async def update_doctor(id, doctor: Doctor):
try:
conn.skinDiseaseDB.doctor.find_one_and_update({"id":id},{"$set": dict(doctor)})
return doctorEntity(conn.skinDiseaseDB.doctor.find_one({"id": id}))
return {"success": True}
except error:
return {"success": False, "msg": error}
......
def doctorEntity(item) -> dict:
return {
"id":item["id"],
"id":str(item["id"]),
"title": item["title"],
"name": item["name"],
"phone": item["phone"],
......@@ -9,5 +9,15 @@ def doctorEntity(item) -> dict:
"address": item["address"],
"availability": item["availability"]
}
def doctorGetEntity(item) -> dict:
return {
"id":str(item["id"]),
"title": item["title"],
"name": item["name"],
"phone": item["phone"],
"email": item["email"]
}
def doctorsEntity(entity) -> list:
return [doctorEntity(item) for item in entity]
\ No newline at end of file
return [doctorGetEntity(item) for item in entity]
\ No newline at end of file
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