-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastapi_test.py
38 lines (31 loc) · 1.14 KB
/
fastapi_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
///////////////////////////////////////////////////////
#blog\schemas.py
#Added "ShowUserId" schema for id
class ShowUserId(BaseModel):
id: int
class Config():
orm_mode = True
///////////////////////////////////////////////////////
#user.py
#Added "showId" funtion for retrive users id
def showId(email:str,db:Session):
userId = db.query(models.User.id).filter(models.User.email == email).first()
if userId is None:
return null
return userId
///////////////////////////////////////////////////////
# repository\blog.py
# Changed get_all to New CODE
def get_all(userid:int,db: Session):
if userid is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
detail= f'Blog not Found')
blogs = db.query(models.Blog).filter(models.Blog.user_id == userid).all()
return blogs
///////////////////////////////////////////////////////
# routers\blog.py
# Changed routers CODE
@router.get('/',status_code=200)
def all(db: Session = Depends(get_db),current_user: schemas.User = Depends(oauth2.get_current_user)):
userid = user.showId(current_user,db).id
return blog.get_all(userid,db)