Commit 388cbd21 authored by Kavindu Randika's avatar Kavindu Randika

Merge branch 'dev-it17170062' into 'master'

API modifications

See merge request !3
parents 74f73062 444e47ac
from pydantic import BaseModel from pydantic import BaseModel
class IsAvailable(BaseModel): class Availability(BaseModel):
day: str day: str
availability: str availableTime: str
\ No newline at end of file \ No newline at end of file
from pydantic import BaseModel from pydantic import BaseModel
from typing import List from typing import List
from typing import Optional from typing import Optional
from models.isAvailable import IsAvailable from models.availability import Availability
class Doctor(BaseModel): class Doctor(BaseModel):
id: str id: str
title: str
name: str name: str
phone: str phone: str
isAvailable: Optional[List[IsAvailable]] = [] email: str
\ No newline at end of file permitNo: str
address: str
availability: Optional[List[Availability]] = []
\ No newline at end of file
from typing import List from typing import List
from models.isAvailable import IsAvailable from models.availability import Availability
from re import A from re import A
import re import re
from os import error from os import error
from bson.objectid import ObjectId from bson.objectid import ObjectId
from schemas.doctor import doctorEntity, doctorsEntity from schemas.doctor import doctorEntity, doctorsEntity, doctorGetEntity
from schemas.availability import availableEntity, availablesEntity from schemas.availability import availabilityEntity, availabilitiesEntity
from fastapi import APIRouter from fastapi import APIRouter
from models.doctor import Doctor from models.doctor import Doctor
from config.db import conn from config.db import conn
...@@ -30,8 +30,7 @@ async def find_one_doctor(id): ...@@ -30,8 +30,7 @@ async def find_one_doctor(id):
async def create_doctor(doctor: Doctor): async def create_doctor(doctor: Doctor):
try: try:
conn.skinDiseaseDB.doctor.insert_one(dict(doctor)) 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: except error:
return {"success": False, "msg": error} return {"success": False, "msg": error}
...@@ -39,7 +38,7 @@ async def create_doctor(doctor: Doctor): ...@@ -39,7 +38,7 @@ async def create_doctor(doctor: Doctor):
async def update_doctor(id, doctor: Doctor): async def update_doctor(id, doctor: Doctor):
try: try:
conn.skinDiseaseDB.doctor.find_one_and_update({"id":id},{"$set": dict(doctor)}) 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: except error:
return {"success": False, "msg": error} return {"success": False, "msg": error}
...@@ -53,7 +52,7 @@ async def delete_doctor(id): ...@@ -53,7 +52,7 @@ async def delete_doctor(id):
@doctor.put('/api/availability/{id}') @doctor.put('/api/availability/{id}')
async def update_availability(id, availabilities: List[IsAvailable]): async def update_availability(id, availabilities: List[Availability]):
try: try:
available_dic = dict() available_dic = dict()
for available in availabilities: for available in availabilities:
......
def availableEntity(item) -> dict: def availabilityEntity(item) -> dict:
return { return {
"day": item["day"], "day": item["day"],
"availability": item["availability"] "availableTime": item["availableTime"]
} }
def availablesEntity(entity) -> list: def availabilitiesEntity(entity) -> list:
print(entity) print(entity)
return [availableEntity(item) for item in entity] return [availabilityEntity(item) for item in entity]
\ No newline at end of file
def doctorEntity(item) -> dict: def doctorEntity(item) -> dict:
return { return {
"id":str(item["id"]), "id":str(item["id"]),
"title": item["title"],
"name": item["name"], "name": item["name"],
"phone": item["phone"], "phone": item["phone"],
"isAvailable": item["isAvailable"] "email": item["email"],
"permitNo": item["permitNo"],
"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: def doctorsEntity(entity) -> list:
return [doctorEntity(item) for item in entity] return [doctorGetEntity(item) for item in entity]
\ No newline at end of file \ 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