mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
add proper repr for exceptions
This commit is contained in:
parent
240784611c
commit
5b4d83a4aa
@ -9,9 +9,10 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=StuffResponse)
|
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=StuffResponse)
|
||||||
async def create_stuff(stuff: StuffSchema, db_session: AsyncSession = Depends(get_db)):
|
async def create_stuff(payload: StuffSchema, db_session: AsyncSession = Depends(get_db)):
|
||||||
stuff_instance = await Stuff.create(db_session, stuff)
|
stuff = Stuff(**payload.dict())
|
||||||
return stuff_instance
|
await stuff.save(db_session)
|
||||||
|
return stuff
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=StuffResponse)
|
@router.get("/", response_model=StuffResponse)
|
||||||
|
@ -18,15 +18,6 @@ class Stuff(Base):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
@classmethod
|
|
||||||
async def create(cls, db_session: AsyncSession, schema: StuffSchema):
|
|
||||||
stuff = Stuff(
|
|
||||||
name=schema.name,
|
|
||||||
description=schema.description,
|
|
||||||
)
|
|
||||||
await stuff.save(db_session)
|
|
||||||
return stuff
|
|
||||||
|
|
||||||
async def update(self, db_session: AsyncSession, schema: StuffSchema):
|
async def update(self, db_session: AsyncSession, schema: StuffSchema):
|
||||||
self.name = schema.name
|
self.name = schema.name
|
||||||
self.description = schema.description
|
self.description = schema.description
|
||||||
|
Loading…
x
Reference in New Issue
Block a user