refactor: Improve code readability by formatting query parameters in user endpoints and enhancing error handling in sound playback
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Annotated, Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
|
||||
from app.core.dependencies import get_current_user, get_dashboard_service
|
||||
from app.models.user import User
|
||||
@@ -17,7 +17,13 @@ async def get_soundboard_statistics(
|
||||
dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)],
|
||||
) -> dict[str, Any]:
|
||||
"""Get soundboard statistics."""
|
||||
return await dashboard_service.get_soundboard_statistics()
|
||||
try:
|
||||
return await dashboard_service.get_soundboard_statistics()
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to fetch soundboard statistics: {e!s}",
|
||||
) from e
|
||||
|
||||
|
||||
@router.get("/track-statistics")
|
||||
@@ -26,7 +32,13 @@ async def get_track_statistics(
|
||||
dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)],
|
||||
) -> dict[str, Any]:
|
||||
"""Get track statistics."""
|
||||
return await dashboard_service.get_track_statistics()
|
||||
try:
|
||||
return await dashboard_service.get_track_statistics()
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to fetch track statistics: {e!s}",
|
||||
) from e
|
||||
|
||||
|
||||
@router.get("/top-sounds")
|
||||
@@ -49,8 +61,14 @@ async def get_top_sounds(
|
||||
] = 10,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Get top sounds by play count for a specific period."""
|
||||
return await dashboard_service.get_top_sounds(
|
||||
sound_type=sound_type,
|
||||
period=period,
|
||||
limit=limit,
|
||||
)
|
||||
try:
|
||||
return await dashboard_service.get_top_sounds(
|
||||
sound_type=sound_type,
|
||||
period=period,
|
||||
limit=limit,
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to fetch top sounds: {e!s}",
|
||||
) from e
|
||||
|
||||
Reference in New Issue
Block a user