mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
code format
This commit is contained in:
@@ -13,7 +13,9 @@ router = APIRouter(prefix="/v1/user")
|
||||
|
||||
|
||||
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=UserResponse)
|
||||
async def create_user(payload: UserSchema, request: Request, db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_user(
|
||||
payload: UserSchema, request: Request, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
logger.info(f"Creating user: {payload}")
|
||||
_user: User = User(**payload.model_dump())
|
||||
await _user.save(db_session)
|
||||
@@ -23,15 +25,23 @@ async def create_user(payload: UserSchema, request: Request, db_session: AsyncSe
|
||||
return _user
|
||||
|
||||
|
||||
@router.post("/token", status_code=status.HTTP_201_CREATED, response_model=TokenResponse)
|
||||
async def get_token_for_user(user: UserLogin, request: Request, db_session: AsyncSession = Depends(get_db)):
|
||||
@router.post(
|
||||
"/token", status_code=status.HTTP_201_CREATED, response_model=TokenResponse
|
||||
)
|
||||
async def get_token_for_user(
|
||||
user: UserLogin, request: Request, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
_user: User = await User.find(db_session, [User.email == user.email])
|
||||
|
||||
# TODO: out exception handling to external module
|
||||
if not _user:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="User not found"
|
||||
)
|
||||
if not _user.check_password(user.password):
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Password is incorrect")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Password is incorrect"
|
||||
)
|
||||
|
||||
# TODO: add refresh token
|
||||
_token = await create_access_token(_user, request)
|
||||
|
||||
Reference in New Issue
Block a user