add response_validation_exception_handler

This commit is contained in:
grillazz
2025-08-23 20:04:23 +02:00
parent 8312f06c0b
commit e2f01f89c5
6 changed files with 62 additions and 34 deletions

View File

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

View File

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