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
class IsAvailable(BaseModel):
class Availability(BaseModel):
day: str
availability: str
\ No newline at end of file
availableTime: str
\ No newline at end of file
from pydantic import BaseModel
from typing import List
from typing import Optional
from models.isAvailable import IsAvailable
from models.availability import Availability
class Doctor(BaseModel):
id: str
title: str
name: str
phone: str
isAvailable: Optional[List[IsAvailable]] = []
\ No newline at end of file
email: str
permitNo: str
address: str
availability: Optional[List[Availability]] = []
\ No newline at end of file
from typing import List
from models.isAvailable import IsAvailable
from models.availability import Availability
from re import A
import re
from os import error
from bson.objectid import ObjectId
from schemas.doctor import doctorEntity, doctorsEntity
from schemas.availability import availableEntity, availablesEntity
from schemas.doctor import doctorEntity, doctorsEntity, doctorGetEntity
from schemas.availability import availabilityEntity, availabilitiesEntity
from fastapi import APIRouter
from models.doctor import Doctor
from config.db import conn
......@@ -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}
......@@ -53,7 +52,7 @@ async def delete_doctor(id):
@doctor.put('/api/availability/{id}')
async def update_availability(id, availabilities: List[IsAvailable]):
async def update_availability(id, availabilities: List[Availability]):
try:
available_dic = dict()
for available in availabilities:
......
def availableEntity(item) -> dict:
def availabilityEntity(item) -> dict:
return {
"day": item["day"],
"availability": item["availability"]
"availableTime": item["availableTime"]
}
def availablesEntity(entity) -> list:
def availabilitiesEntity(entity) -> list:
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:
return {
"id":str(item["id"]),
"title": item["title"],
"name": item["name"],
"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:
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