mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
add response_validation_exception_handler
This commit is contained in:
@@ -22,11 +22,12 @@ async def create_nonsense(
|
||||
|
||||
|
||||
@router.get("/", response_model=NonsenseResponse)
|
||||
async def find_nonsense(
|
||||
async def get_nonsense(
|
||||
name: str,
|
||||
db_session: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await Nonsense.find(db_session, name)
|
||||
nonsense = await Nonsense.get_by_name(db_session, name)
|
||||
return nonsense
|
||||
|
||||
|
||||
@router.delete("/")
|
||||
|
||||
@@ -52,13 +52,8 @@ async def create_stuff(
|
||||
|
||||
|
||||
@router.get("/{name}", response_model=StuffResponse)
|
||||
async def find_stuff(name: str, db_session: AsyncSession = Depends(get_db)):
|
||||
result = await Stuff.find(db_session, name)
|
||||
if not result:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Stuff with name {name} not found.",
|
||||
)
|
||||
async def get_stuff(name: str, db_session: AsyncSession = Depends(get_db)):
|
||||
result = await Stuff.get_by_name(db_session, name)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user