feat: Add dashboard API endpoints and service for sound statistics
Some checks failed
Backend CI / lint (push) Failing after 4m52s
Backend CI / test (push) Failing after 3m42s

This commit is contained in:
JSC
2025-08-11 11:16:45 +02:00
parent bb1f036caa
commit 49ad6c8581
5 changed files with 133 additions and 0 deletions

46
app/services/dashboard.py Normal file
View File

@@ -0,0 +1,46 @@
"""Dashboard service for statistics and analytics."""
from typing import Any
from app.core.logging import get_logger
from app.repositories.sound import SoundRepository
logger = get_logger(__name__)
class DashboardService:
"""Service for dashboard statistics and analytics."""
def __init__(self, sound_repository: SoundRepository) -> None:
"""Initialize the dashboard service."""
self.sound_repository = sound_repository
async def get_soundboard_statistics(self) -> dict[str, Any]:
"""Get comprehensive soundboard statistics."""
try:
stats = await self.sound_repository.get_soundboard_statistics()
return {
"sound_count": stats["count"],
"total_play_count": stats["total_plays"],
"total_duration": stats["total_duration"],
"total_size": stats["total_size"],
}
except Exception:
logger.exception("Failed to get soundboard statistics")
raise
async def get_track_statistics(self) -> dict[str, Any]:
"""Get comprehensive track statistics."""
try:
stats = await self.sound_repository.get_track_statistics()
return {
"track_count": stats["count"],
"total_play_count": stats["total_plays"],
"total_duration": stats["total_duration"],
"total_size": stats["total_size"],
}
except Exception:
logger.exception("Failed to get track statistics")
raise