mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
code format
This commit is contained in:
@@ -12,7 +12,9 @@ router = APIRouter(prefix="/v1/nonsense")
|
||||
|
||||
|
||||
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=NonsenseResponse)
|
||||
async def create_nonsense(payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_nonsense(
|
||||
payload: NonsenseSchema, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
nonsense = Nonsense(**payload.model_dump())
|
||||
await nonsense.save(db_session)
|
||||
return nonsense
|
||||
@@ -103,7 +105,9 @@ async def import_nonsense(
|
||||
# If an error occurs, roll back the session
|
||||
await db_session.rollback()
|
||||
# Raise an HTTP exception with a 422 status code
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)) from ex
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=repr(ex)
|
||||
) from ex
|
||||
finally:
|
||||
# Ensure that the database session is closed, regardless of whether an error occurred or not
|
||||
await db_session.close()
|
||||
@@ -147,4 +151,4 @@ async def import_nonsense(
|
||||
#
|
||||
|
||||
# TODO: https://medium.com/@amitosh/full-text-search-fts-with-postgresql-and-sqlalchemy-edc436330a0c
|
||||
# TODO: https://www.postgresql.org/docs/13/textsearch-intro.html
|
||||
# TODO: https://www.postgresql.org/docs/13/textsearch-intro.html
|
||||
|
||||
Reference in New Issue
Block a user