refactor: Introduce utility functions for exception handling and database operations; update auth and playlist services to use new exception methods
All checks were successful
Backend CI / test (push) Successful in 3m58s

This commit is contained in:
JSC
2025-07-31 13:28:06 +02:00
parent f24698e3ff
commit b8346ab667
9 changed files with 679 additions and 122 deletions

View File

@@ -10,6 +10,11 @@ from app.models.playlist import Playlist
from app.models.sound import Sound
from app.repositories.playlist import PlaylistRepository
from app.repositories.sound import SoundRepository
from app.utils.exceptions import (
raise_bad_request,
raise_internal_server_error,
raise_not_found,
)
logger = get_logger(__name__)
@@ -27,10 +32,7 @@ class PlaylistService:
"""Get a playlist by ID."""
playlist = await self.playlist_repo.get_by_id(playlist_id)
if not playlist:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Playlist not found",
)
raise_not_found("Playlist")
return playlist
@@ -47,9 +49,8 @@ class PlaylistService:
main_playlist = await self.playlist_repo.get_main_playlist()
if not main_playlist:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Main playlist not found. Make sure to run database seeding."
raise_internal_server_error(
"Main playlist not found. Make sure to run database seeding."
)
return main_playlist