feat: Add endpoint to retrieve sounds with optional type filtering and implement corresponding repository method
Some checks failed
Backend CI / lint (push) Successful in 9m41s
Backend CI / test (push) Failing after 1m39s

This commit is contained in:
JSC
2025-08-01 22:03:09 +02:00
parent d2d0240fdb
commit 4bbae4c5d4
3 changed files with 127 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
"""Sound repository for database operations."""
from sqlalchemy import func
from sqlmodel import select
from sqlmodel import col, select
from sqlmodel.ext.asyncio.session import AsyncSession
from app.core.logging import get_logger
@@ -95,3 +95,15 @@ class SoundRepository(BaseRepository[Sound]):
sound_type,
)
raise
async def get_by_types(self, sound_types: list[str] | None = None) -> list[Sound]:
"""Get sounds by types. If types is None or empty, return all sounds."""
try:
statement = select(Sound)
if sound_types:
statement = statement.where(col(Sound.type).in_(sound_types))
result = await self.session.exec(statement)
return list(result.all())
except Exception:
logger.exception("Failed to get sounds by types: %s", sound_types)
raise