refactor: Update playlist service and endpoints for global current playlist management
This commit is contained in:
@@ -62,11 +62,11 @@ async def get_main_playlist(
|
||||
|
||||
@router.get("/current")
|
||||
async def get_current_playlist(
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)], # noqa: ARG001
|
||||
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
|
||||
) -> PlaylistResponse:
|
||||
"""Get the user's current playlist (falls back to main playlist)."""
|
||||
playlist = await playlist_service.get_current_playlist(current_user.id)
|
||||
"""Get the global current playlist (falls back to main playlist)."""
|
||||
playlist = await playlist_service.get_current_playlist()
|
||||
return PlaylistResponse.from_playlist(playlist)
|
||||
|
||||
|
||||
@@ -105,13 +105,19 @@ async def update_playlist(
|
||||
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
|
||||
) -> PlaylistResponse:
|
||||
"""Update a playlist."""
|
||||
if current_user.id is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="User ID not available",
|
||||
)
|
||||
|
||||
playlist = await playlist_service.update_playlist(
|
||||
playlist_id=playlist_id,
|
||||
user_id=current_user.id,
|
||||
name=request.name,
|
||||
description=request.description,
|
||||
genre=request.genre,
|
||||
is_current=request.is_current,
|
||||
is_current=None, # is_current is not handled by this endpoint
|
||||
)
|
||||
return PlaylistResponse.from_playlist(playlist)
|
||||
|
||||
@@ -212,21 +218,21 @@ async def reorder_playlist_sounds(
|
||||
@router.put("/{playlist_id}/set-current")
|
||||
async def set_current_playlist(
|
||||
playlist_id: int,
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)], # noqa: ARG001
|
||||
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
|
||||
) -> PlaylistResponse:
|
||||
"""Set a playlist as the current playlist."""
|
||||
playlist = await playlist_service.set_current_playlist(playlist_id, current_user.id)
|
||||
"""Set a playlist as the global current playlist."""
|
||||
playlist = await playlist_service.set_current_playlist_global(playlist_id)
|
||||
return PlaylistResponse.from_playlist(playlist)
|
||||
|
||||
|
||||
@router.delete("/current")
|
||||
async def unset_current_playlist(
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)],
|
||||
current_user: Annotated[User, Depends(get_current_active_user_flexible)], # noqa: ARG001
|
||||
playlist_service: Annotated[PlaylistService, Depends(get_playlist_service)],
|
||||
) -> MessageResponse:
|
||||
"""Unset the current playlist."""
|
||||
await playlist_service.unset_current_playlist(current_user.id)
|
||||
"""Unset the global current playlist."""
|
||||
await playlist_service.unset_current_playlist_global()
|
||||
return MessageResponse(message="Current playlist unset successfully")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user