feat: Add endpoint to retrieve sounds with optional type filtering and implement corresponding repository method
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from app.core.database import get_db, get_session_factory
|
||||
from app.core.dependencies import get_current_active_user_flexible
|
||||
from app.models.credit_action import CreditActionType
|
||||
from app.models.sound import Sound
|
||||
from app.models.user import User
|
||||
from app.repositories.sound import SoundRepository
|
||||
from app.services.credit import CreditService, InsufficientCreditsError
|
||||
@@ -34,6 +35,27 @@ async def get_sound_repository(
|
||||
return SoundRepository(session)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def get_sounds(
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)], # noqa: ARG001
|
||||
sound_repo: Annotated[SoundRepository, Depends(get_sound_repository)],
|
||||
types: Annotated[
|
||||
list[str] | None,
|
||||
Query(description="Filter by sound types (e.g., SDB, TTS, EXT)"),
|
||||
] = None,
|
||||
) -> dict[str, list[Sound]]:
|
||||
"""Get all sounds, optionally filtered by types."""
|
||||
try:
|
||||
sounds = await sound_repo.get_by_types(types)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to get sounds: {e!s}",
|
||||
) from e
|
||||
else:
|
||||
return {"sounds": sounds}
|
||||
|
||||
|
||||
|
||||
# VLC PLAYER
|
||||
@router.post("/play/{sound_id}")
|
||||
|
||||
Reference in New Issue
Block a user