pycdn/routes/user_routes.py

21 lines
594 B
Python
Raw Permalink Normal View History

2023-04-06 23:58:56 +03:00
from fastapi import APIRouter
from db.models.User import User
from fastapi import HTTPException
user_route = APIRouter()
@user_route.post("/user/", response_model=User, response_model_exclude={"password_hash"})
async def create_user(user: User):
res = user.create()
if hasattr(res, 'is_db'):
raise HTTPException(status_code=500, detail="DB error {err}".format(err=res.msg))
return res
@user_route.get("/user/{user_id}", response_model=User, response_model_exclude={"password_hash"})
async def get_user(user_id: int):
user = User.get_by_id(user_id)
return user