feat: Enhance favorites functionality; add favorites filtering to playlists and sounds, and improve favorite indicators in responses

This commit is contained in:
JSC
2025-08-16 21:41:50 +02:00
parent 78508c84eb
commit f906b6d643
10 changed files with 97 additions and 52 deletions

View File

@@ -18,16 +18,16 @@ class SoundResponse(BaseModel):
size: int = Field(description="File size in bytes")
hash: str = Field(description="File hash")
normalized_filename: str | None = Field(
description="Normalized filename", default=None
description="Normalized filename", default=None,
)
normalized_duration: int | None = Field(
description="Normalized duration in milliseconds", default=None
description="Normalized duration in milliseconds", default=None,
)
normalized_size: int | None = Field(
description="Normalized file size in bytes", default=None
description="Normalized file size in bytes", default=None,
)
normalized_hash: str | None = Field(
description="Normalized file hash", default=None
description="Normalized file hash", default=None,
)
thumbnail: str | None = Field(description="Thumbnail filename", default=None)
play_count: int = Field(description="Number of times played")
@@ -35,10 +35,10 @@ class SoundResponse(BaseModel):
is_music: bool = Field(description="Whether the sound is music")
is_deletable: bool = Field(description="Whether the sound can be deleted")
is_favorited: bool = Field(
description="Whether the sound is favorited by the current user", default=False
description="Whether the sound is favorited by the current user", default=False,
)
favorite_count: int = Field(
description="Number of users who favorited this sound", default=0
description="Number of users who favorited this sound", default=0,
)
created_at: datetime = Field(description="Creation timestamp")
updated_at: datetime = Field(description="Last update timestamp")
@@ -50,7 +50,7 @@ class SoundResponse(BaseModel):
@classmethod
def from_sound(
cls, sound: Sound, is_favorited: bool = False, favorite_count: int = 0
cls, sound: Sound, is_favorited: bool = False, favorite_count: int = 0,
) -> "SoundResponse":
"""Create a SoundResponse from a Sound model.
@@ -61,6 +61,7 @@ class SoundResponse(BaseModel):
Returns:
SoundResponse instance
"""
if sound.id is None:
raise ValueError("Sound ID cannot be None")