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:
@@ -20,22 +20,10 @@ class Nonsense(Base):
|
||||
# TODO: apply relation to other tables
|
||||
|
||||
@classmethod
|
||||
async def find(cls, db_session: AsyncSession, name: str):
|
||||
"""
|
||||
|
||||
:param db_session:
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
async def get_by_name(cls, db_session: AsyncSession, name: str):
|
||||
stmt = select(cls).where(cls.name == name)
|
||||
result = await db_session.execute(stmt)
|
||||
instance = result.scalars().first()
|
||||
if instance is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail={
|
||||
"Record not found": f"There is no record for requested name value : {name}"
|
||||
},
|
||||
)
|
||||
else:
|
||||
return instance
|
||||
return instance
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Stuff(Base):
|
||||
|
||||
@classmethod
|
||||
@compile_sql_or_scalar
|
||||
async def find(cls, db_session: AsyncSession, name: str, compile_sql=False):
|
||||
async def get_by_name(cls, db_session: AsyncSession, name: str, compile_sql=False):
|
||||
stmt = select(cls).options(joinedload(cls.nonsense)).where(cls.name == name)
|
||||
return stmt
|
||||
|
||||
|
||||
Reference in New Issue
Block a user