mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
lint code + format
This commit is contained in:
@@ -9,7 +9,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.dict())
|
||||
await nonsense.save(db_session)
|
||||
return nonsense
|
||||
|
||||
@@ -13,21 +13,31 @@ logger = get_logger(__name__)
|
||||
|
||||
|
||||
@router.post("/add_many", status_code=status.HTTP_201_CREATED)
|
||||
async def create_multi_stuff(payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_multi_stuff(
|
||||
payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
try:
|
||||
stuff_instances = [Stuff(name=stuf.name, description=stuf.description) for stuf in payload]
|
||||
stuff_instances = [
|
||||
Stuff(name=stuf.name, description=stuf.description) for stuf in payload
|
||||
]
|
||||
db_session.add_all(stuff_instances)
|
||||
await db_session.commit()
|
||||
except SQLAlchemyError as ex:
|
||||
# logger.exception(ex)
|
||||
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
|
||||
else:
|
||||
logger.info(f"{len(stuff_instances)} instances of Stuff inserted into database.")
|
||||
logger.info(
|
||||
f"{len(stuff_instances)} instances of Stuff inserted into database."
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_201_CREATED, response_model=StuffResponse)
|
||||
async def create_stuff(payload: StuffSchema, db_session: AsyncSession = Depends(get_db)):
|
||||
async def create_stuff(
|
||||
payload: StuffSchema, db_session: AsyncSession = Depends(get_db)
|
||||
):
|
||||
stuff = Stuff(name=payload.name, description=payload.description)
|
||||
await stuff.save(db_session)
|
||||
return stuff
|
||||
|
||||
Reference in New Issue
Block a user