refactor: Update response types to use common schemas across API endpoints
Some checks failed
Backend CI / test (push) Failing after 3m51s

This commit is contained in:
JSC
2025-07-31 10:40:03 +02:00
parent dc372b961e
commit c13285ca4e
7 changed files with 101 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
from app.core.database import get_db
from app.core.dependencies import get_current_active_user_flexible
from app.models.user import User
from app.schemas.common import MessageResponse
from app.schemas.playlist import (
PlaylistAddSoundRequest,
PlaylistCreateRequest,
@@ -120,10 +121,10 @@ async def delete_playlist(
playlist_id: int,
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
) -> dict[str, str]:
) -> MessageResponse:
"""Delete a playlist."""
await playlist_service.delete_playlist(playlist_id, current_user.id)
return {"message": "Playlist deleted successfully"}
return MessageResponse(message="Playlist deleted successfully")
@router.get("/search/{query}")
@@ -165,7 +166,7 @@ async def add_sound_to_playlist(
request: PlaylistAddSoundRequest,
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
) -> dict[str, str]:
) -> MessageResponse:
"""Add a sound to a playlist."""
await playlist_service.add_sound_to_playlist(
playlist_id=playlist_id,
@@ -173,7 +174,7 @@ async def add_sound_to_playlist(
user_id=current_user.id,
position=request.position,
)
return {"message": "Sound added to playlist successfully"}
return MessageResponse(message="Sound added to playlist successfully")
@router.delete("/{playlist_id}/sounds/{sound_id}")
@@ -182,14 +183,14 @@ async def remove_sound_from_playlist(
sound_id: int,
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
) -> dict[str, str]:
) -> MessageResponse:
"""Remove a sound from a playlist."""
await playlist_service.remove_sound_from_playlist(
playlist_id=playlist_id,
sound_id=sound_id,
user_id=current_user.id,
)
return {"message": "Sound removed from playlist successfully"}
return MessageResponse(message="Sound removed from playlist successfully")
@router.put("/{playlist_id}/sounds/reorder")
@@ -198,14 +199,14 @@ async def reorder_playlist_sounds(
request: PlaylistReorderRequest,
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
) -> dict[str, str]:
) -> MessageResponse:
"""Reorder sounds in a playlist."""
await playlist_service.reorder_playlist_sounds(
playlist_id=playlist_id,
user_id=current_user.id,
sound_positions=request.sound_positions,
)
return {"message": "Playlist sounds reordered successfully"}
return MessageResponse(message="Playlist sounds reordered successfully")
@router.put("/{playlist_id}/set-current")
@@ -223,10 +224,10 @@ async def set_current_playlist(
async def unset_current_playlist(
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
) -> dict[str, str]:
) -> MessageResponse:
"""Unset the current playlist."""
await playlist_service.unset_current_playlist(current_user.id)
return {"message": "Current playlist unset successfully"}
return MessageResponse(message="Current playlist unset successfully")
@router.get("/{playlist_id}/stats")