Skip to content

Commit bfab454

Browse files
Merge pull request #13 from TebogoYungMercykay/feature_01
The Python FastAPI Implementation Files
2 parents 8947c7c + 414e445 commit bfab454

File tree

9 files changed

+128
-92
lines changed

9 files changed

+128
-92
lines changed

app/calculations.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/database.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,3 @@ def get_db():
2424
yield db
2525
finally:
2626
db.close()
27-
28-
29-
# while True:
30-
31-
# try:
32-
# conn = psycopg2.connect(host='localhost', database='fastapi', user='postgres',
33-
# password='password123', cursor_factory=RealDictCursor)
34-
# cursor = conn.cursor()
35-
# print("Database connection was succesfull!")
36-
# break
37-
# except Exception as error:
38-
# print("Connecting to database failed")
39-
# print("Error: ", error)
40-
# time.sleep(2)

app/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from . import models
55
from .database import engine
6-
from .routers import post, user, auth, vote
6+
from .routers import post, user, auth, vote, consultations, disease_prediction, chats
77
from .config import settings
88

99
models.Base.metadata.create_all(bind=engine)
@@ -24,6 +24,9 @@
2424
app.include_router(user.router)
2525
app.include_router(auth.router)
2626
app.include_router(vote.router)
27+
app.include_router(consultations.router)
28+
app.include_router(disease_prediction.router)
29+
app.include_router(chats.router)
2730

2831

2932
@app.get("/")

app/routers/auth.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def login(user_credentials: OAuth2PasswordRequestForm = Depends(), db: Session =
2121
raise HTTPException(
2222
status_code=status.HTTP_403_FORBIDDEN, detail=f"Invalid Credentials")
2323

24-
# create a token
25-
# return token
26-
2724
access_token = oauth2.create_access_token(data={"user_id": user.id})
2825

2926
return {"access_token": access_token, "token_type": "bearer"}
27+
28+
@router.post('/logout')
29+
def logout():
30+
return { "status":"pending", "message": "Functionality Under Construction." }

app/routers/chats.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from fastapi import FastAPI, Response, status, HTTPException, Depends, APIRouter
2+
from sqlalchemy.orm import Session
3+
from typing import List, Optional
4+
5+
from sqlalchemy import func
6+
from .. import models, schemas, oauth2
7+
from ..database import get_db
8+
9+
10+
MESSAGE_UNDER_CONSTRUCTION = "Functionality Under Construction."
11+
12+
router = APIRouter(
13+
prefix="/chats",
14+
tags=['Chats']
15+
)
16+
17+
@router.get('/')
18+
def chat_messages():
19+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
20+
21+
22+
@router.get('/get_feedback')
23+
def get_feedback():
24+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
25+
26+
27+
@router.post('/post_feedback')
28+
def post_feedback():
29+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
30+
31+
32+
@router.post('/whatsapp')
33+
def whatsapp():
34+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
35+
36+
37+
@router.post('/meeting')
38+
def meeting():
39+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
40+

app/routers/consultations.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from fastapi import FastAPI, Response, status, HTTPException, Depends, APIRouter
2+
from sqlalchemy.orm import Session
3+
from typing import List, Optional
4+
5+
from sqlalchemy import func
6+
from .. import models, schemas, oauth2
7+
from ..database import get_db
8+
9+
MESSAGE_UNDER_CONSTRUCTION = "Functionality Under Construction."
10+
11+
router = APIRouter(
12+
prefix="/consultations",
13+
tags=['Consultations']
14+
)
15+
16+
@router.get('/')
17+
def consult_a_doctor():
18+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
19+
20+
21+
@router.post('/make_consultation')
22+
def make_consultation():
23+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
24+
25+
26+
@router.get('/consultation_history')
27+
def consultation_history():
28+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
29+
30+
31+
@router.get('/consultation_view')
32+
def consultation_view():
33+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
34+
35+
36+
@router.post('/close_consultation')
37+
def close_consultation():
38+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
39+
40+
41+
@router.post('/rate_review')
42+
def rate_review():
43+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
44+

app/routers/disease_prediction.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from fastapi import FastAPI, Response, status, HTTPException, Depends, APIRouter
2+
from sqlalchemy.orm import Session
3+
from typing import List, Optional
4+
5+
from sqlalchemy import func
6+
from .. import models, schemas, oauth2
7+
from ..database import get_db
8+
9+
MESSAGE_UNDER_CONSTRUCTION = "Functionality Under Construction."
10+
11+
router = APIRouter(
12+
prefix="/disease_prediction",
13+
tags=['Disease Prediction Model']
14+
)
15+
16+
@router.get('/')
17+
def checkdisease():
18+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
19+
20+
21+
@router.post('/checkdisease')
22+
def checkdisease():
23+
return { "status":"pending", "message": MESSAGE_UNDER_CONSTRUCTION }
24+

app/routers/post.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,12 @@
88

99

1010
router = APIRouter(
11-
prefix="/posts", # prefix for all routes
11+
prefix="/posts",
1212
tags=['Posts']
1313
)
1414

15-
16-
# @router.get("/", response_model=List[schemas.Post])
1715
@router.get("/", response_model=List[schemas.PostOut])
1816
def get_posts(db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user), limit: int = 10, skip: int = 0, search: Optional[str] = ""):
19-
# results = db.query(models.Post, func.count(models.Vote.post_id).label("votes")).join(
20-
# models.Vote, models.Vote.post_id == models.Post.id, isouter=True).group_by(models.Post.id)
21-
22-
# cursor.execute("""SELECT * FROM posts """)
23-
# posts = cursor.fetchall()
24-
25-
# posts = db.execute(
26-
# 'select posts.*, COUNT(votes.post_id) as votes from posts LEFT JOIN votes ON posts.id=votes.post_id group by posts.id')
27-
# results = []
28-
# for post in posts:
29-
# results.append(dict(post))
30-
# print(results)
31-
# posts = db.query(models.Post).filter(
32-
# models.Post.title.contains(search)).limit(limit).offset(skip).all()
3317

3418
posts = db.query(models.Post, func.count(models.Vote.post_id).label("votes")).join(
3519
models.Vote, models.Vote.post_id == models.Post.id, isouter=True).group_by(models.Post.id).filter(models.Post.title.contains(search)).limit(limit).offset(skip).all()
@@ -38,11 +22,6 @@ def get_posts(db: Session = Depends(get_db), current_user: int = Depends(oauth2.
3822

3923
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=schemas.Post)
4024
def create_posts(post: schemas.PostCreate, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):
41-
# cursor.execute("""INSERT INTO posts (title, content, published) VALUES (%s, %s, %s) RETURNING * """,
42-
# (post.title, post.content, post.published))
43-
# new_post = cursor.fetchone()
44-
45-
# conn.commit()
4625

4726
new_post = models.Post(owner_id=current_user.id, **post.dict())
4827
db.add(new_post)
@@ -54,9 +33,6 @@ def create_posts(post: schemas.PostCreate, db: Session = Depends(get_db), curren
5433

5534
@router.get("/{id}", response_model=schemas.PostOut)
5635
def get_post(id: int, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):
57-
# cursor.execute("""SELECT * from posts WHERE id = %s """, (str(id),))
58-
# post = cursor.fetchone()
59-
# post = db.query(models.Post).filter(models.Post.id == id).first()
6036

6137
post = db.query(models.Post, func.count(models.Vote.post_id).label("votes")).join(
6238
models.Vote, models.Vote.post_id == models.Post.id, isouter=True).group_by(models.Post.id).filter(models.Post.id == id).first()
@@ -66,16 +42,11 @@ def get_post(id: int, db: Session = Depends(get_db), current_user: int = Depends
6642
detail=f"post with id: {id} was not found")
6743

6844
return post
69-
# return { 'status': "success", "data": post }
7045

7146

7247
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT)
7348
def delete_post(id: int, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):
7449

75-
# cursor.execute(
76-
# """DELETE FROM posts WHERE id = %s returning *""", (str(id),))
77-
# deleted_post = cursor.fetchone()
78-
# conn.commit()
7950
post_query = db.query(models.Post).filter(models.Post.id == id)
8051

8152
post = post_query.first()
@@ -97,12 +68,6 @@ def delete_post(id: int, db: Session = Depends(get_db), current_user: int = Depe
9768
@router.put("/{id}", response_model=schemas.Post)
9869
def update_post(id: int, updated_post: schemas.PostCreate, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):
9970

100-
# cursor.execute("""UPDATE posts SET title = %s, content = %s, published = %s WHERE id = %s RETURNING *""",
101-
# (post.title, post.content, post.published, str(id)))
102-
103-
# updated_post = cursor.fetchone()
104-
# conn.commit()
105-
10671
post_query = db.query(models.Post).filter(models.Post.id == id)
10772

10873
post = post_query.first()
@@ -120,3 +85,8 @@ def update_post(id: int, updated_post: schemas.PostCreate, db: Session = Depends
12085
db.commit()
12186

12287
return post_query.first()
88+
89+
90+
@router.get('/create_reply')
91+
def create_reply():
92+
return { "status":"pending", "message": "Functionality Under Construction." }

app/routers/user.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
router = APIRouter(
77
prefix="/users",
8-
tags=['Users']
8+
tags=['Accounts']
99
)
1010

1111
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=schemas.UserOut)
1212
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
1313

14-
# hash the password - user.password
1514
hashed_password = utils.hash(user.password)
1615
user.password = hashed_password
1716

@@ -31,3 +30,8 @@ def get_user(id: int, db: Session = Depends(get_db), ):
3130
detail=f"User with id: {id} does not exist")
3231

3332
return user
33+
34+
35+
@router.put('/savedata')
36+
def savedata():
37+
return { "status":"pending", "message": "Functionality Under Construction." }

0 commit comments

Comments
 (0)