21 lines
594 B
Python
21 lines
594 B
Python
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
|