Skip to content

Commit

Permalink
Move AppUser to user schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
anarute committed Oct 10, 2023
1 parent 2e83126 commit 621cc30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 3 additions & 12 deletions api/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Annotated, Optional, List
from typing import Annotated
from fastapi import Depends, HTTPException
from sqlalchemy.orm import Session
from fastapi.security import OAuth2PasswordBearer
from pydantic import BaseModel
from decouple import config
from db.db_connection import get_db
from auth.auth_handler import decode_token
from schemas.user import AppUser
from services.user import UserService


Expand All @@ -17,16 +17,7 @@
oauth2_scheme = OAuth2PasswordBearer(tokenUrl=OIDC_TOKEN_ENDPOINT)


class AppUser(BaseModel):
id: Optional[int] = None
username: Optional[str] = None
email: Optional[str] = None
first_name: Optional[str] = None
last_name: Optional[str] = None
roles: Optional[List[str]] = None


async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)], db: Session = Depends(get_db)):
async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)], db: Session = Depends(get_db)) -> AppUser:
decoded = decode_token(token)
username = decoded[OIDC_USERNAME_PROPERTY]
user_in_db = UserService(db).get_user(username=username)
Expand Down
10 changes: 10 additions & 0 deletions api/schemas/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import List, Optional
from pydantic import ConfigDict, BaseModel


Expand All @@ -16,3 +17,12 @@ class UserGroup(BaseModel):
class UserRoles(BaseModel):
role: UserGroup
model_config = ConfigDict(from_attributes=True)


class AppUser(BaseModel):
id: Optional[int] = None
username: Optional[str] = None
email: Optional[str] = None
first_name: Optional[str] = None
last_name: Optional[str] = None
roles: Optional[List[str]] = None

0 comments on commit 621cc30

Please sign in to comment.