Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Skin disease Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Skin disease
Skin disease Server
Commits
9ecdd57a
Commit
9ecdd57a
authored
Sep 16, 2021
by
Hansi rathnayaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API implementation
parent
d9dd7112
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
117 additions
and
9 deletions
+117
-9
config/db.py
config/db.py
+1
-1
index.py
index.py
+2
-0
models/doctor.py
models/doctor.py
+10
-0
routes/doctor.py
routes/doctor.py
+86
-0
schemas/availability.py
schemas/availability.py
+9
-0
schemas/doctor.py
schemas/doctor.py
+9
-8
No files found.
config/db.py
View file @
9ecdd57a
from
pymongo
import
MongoClient
conn
=
MongoClient
(
"mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/
myFirstDatabase
?retryWrites=true&w=majority"
)
conn
=
MongoClient
(
"mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/
skinDiseaseDB
?retryWrites=true&w=majority"
)
#mongodb+srv://skin-disease:skindis123@cluster0.bv8ia.mongodb.net/test
\ No newline at end of file
index.py
View file @
9ecdd57a
from
fastapi
import
FastAPI
from
routes.doctor
import
doctor
app
=
FastAPI
()
app
.
include_router
(
doctor
)
models/doctor.py
View file @
9ecdd57a
from
pydantic
import
BaseModel
from
typing
import
List
from
typing
import
Optional
from
models.isAvailable
import
IsAvailable
class
Doctor
(
BaseModel
):
id
:
str
name
:
str
phone
:
str
isAvailable
:
Optional
[
List
[
IsAvailable
]]
=
[]
\ No newline at end of file
routes/doctor.py
0 → 100644
View file @
9ecdd57a
from
typing
import
List
from
models.isAvailable
import
IsAvailable
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
fastapi
import
APIRouter
from
models.doctor
import
Doctor
from
config.db
import
conn
doctor
=
APIRouter
()
@
doctor
.
get
(
'/api/doctors'
)
async
def
find_all_doctors
():
return
doctorsEntity
(
conn
.
skinDiseaseDB
.
doctor
.
find
())
@
doctor
.
get
(
'/api/doctor/{id}'
)
async
def
find_one_doctor
(
id
):
try
:
return
doctorEntity
(
conn
.
skinDiseaseDB
.
doctor
.
find_one
({
"id"
:
id
}))
except
error
:
print
(
error
)
return
{
"success"
:
False
,
"msg"
:
error
}
@
doctor
.
post
(
'/api/doctor'
)
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}
except
error
:
return
{
"success"
:
False
,
"msg"
:
error
}
@
doctor
.
put
(
'/api/doctor/{id}'
)
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
}))
except
error
:
return
{
"success"
:
False
,
"msg"
:
error
}
@
doctor
.
delete
(
'/api/doctor/{id}'
)
async
def
delete_doctor
(
id
):
try
:
result
=
doctorEntity
(
conn
.
skinDiseaseDB
.
doctor
.
find_one_and_delete
({
"id"
:
id
}))
return
{
"success"
:
True
}
except
:
return
{
"success"
:
False
}
@
doctor
.
put
(
'/api/availability/{id}'
)
async
def
update_availability
(
id
,
availabilities
:
List
[
IsAvailable
]):
try
:
available_dic
=
dict
()
for
available
in
availabilities
:
print
(
available
)
#conn.skinDiseaseDB.doctor.find_one_and_update({"id":id},{"$set": {'isAvailable': isAvailable}})
return
availabilities
except
error
:
return
{
"success"
:
False
,
"msg"
:
error
}
schemas/availability.py
0 → 100644
View file @
9ecdd57a
def
availableEntity
(
item
)
->
dict
:
return
{
"day"
:
item
[
"day"
],
"availability"
:
item
[
"availability"
]
}
def
availablesEntity
(
entity
)
->
list
:
print
(
entity
)
return
[
availableEntity
(
item
)
for
item
in
entity
]
\ No newline at end of file
schemas/doctor.py
View file @
9ecdd57a
from
pydantic
import
BaseModel
from
typing
import
List
from
models.isAvailable
import
IsAvailable
class
Doctor
(
BaseModel
):
name
:
str
phone
:
str
IsAvailable
:
List
[
IsAvailable
]
\ No newline at end of file
def
doctorEntity
(
item
)
->
dict
:
return
{
"id"
:
str
(
item
[
"id"
]),
"name"
:
item
[
"name"
],
"phone"
:
item
[
"phone"
],
"isAvailable"
:
item
[
"isAvailable"
]
}
def
doctorsEntity
(
entity
)
->
list
:
return
[
doctorEntity
(
item
)
for
item
in
entity
]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment