code format

This commit is contained in:
Jakub Miazek
2024-04-24 10:37:08 +02:00
parent 43fe665608
commit c2975fd260
19 changed files with 358 additions and 173 deletions

View File

@@ -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