feat: Implement favorites management API; add endpoints for adding, removing, and retrieving favorites for sounds and playlists
feat: Create Favorite model and repository for managing user favorites in the database feat: Add FavoriteService to handle business logic for favorites management feat: Enhance Playlist and Sound response schemas to include favorite indicators and counts refactor: Update API routes to include favorites functionality in playlists and sounds
This commit is contained in:
@@ -33,12 +33,23 @@ class PlaylistResponse(BaseModel):
|
||||
is_main: bool
|
||||
is_current: bool
|
||||
is_deletable: bool
|
||||
is_favorited: bool = False
|
||||
favorite_count: int = 0
|
||||
created_at: str
|
||||
updated_at: str | None
|
||||
|
||||
@classmethod
|
||||
def from_playlist(cls, playlist: Playlist) -> "PlaylistResponse":
|
||||
"""Create response from playlist model."""
|
||||
def from_playlist(cls, playlist: Playlist, is_favorited: bool = False, favorite_count: int = 0) -> "PlaylistResponse":
|
||||
"""Create response from playlist model.
|
||||
|
||||
Args:
|
||||
playlist: The Playlist model
|
||||
is_favorited: Whether the playlist is favorited by the current user
|
||||
favorite_count: Number of users who favorited this playlist
|
||||
|
||||
Returns:
|
||||
PlaylistResponse instance
|
||||
"""
|
||||
if playlist.id is None:
|
||||
msg = "Playlist ID cannot be None"
|
||||
raise ValueError(msg)
|
||||
@@ -50,6 +61,8 @@ class PlaylistResponse(BaseModel):
|
||||
is_main=playlist.is_main,
|
||||
is_current=playlist.is_current,
|
||||
is_deletable=playlist.is_deletable,
|
||||
is_favorited=is_favorited,
|
||||
favorite_count=favorite_count,
|
||||
created_at=playlist.created_at.isoformat(),
|
||||
updated_at=playlist.updated_at.isoformat() if playlist.updated_at else None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user