feat: Enhance favorites functionality; add favorites filtering to playlists and sounds, and improve favorite indicators in responses
This commit is contained in:
@@ -105,7 +105,7 @@ class FavoriteRepository(BaseRepository[Favorite]):
|
||||
statement = (
|
||||
select(Favorite)
|
||||
.where(
|
||||
and_(Favorite.user_id == user_id, Favorite.playlist_id.isnot(None))
|
||||
and_(Favorite.user_id == user_id, Favorite.playlist_id.isnot(None)),
|
||||
)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
@@ -118,7 +118,7 @@ class FavoriteRepository(BaseRepository[Favorite]):
|
||||
raise
|
||||
|
||||
async def get_by_user_and_sound(
|
||||
self, user_id: int, sound_id: int
|
||||
self, user_id: int, sound_id: int,
|
||||
) -> Favorite | None:
|
||||
"""Get a favorite by user and sound.
|
||||
|
||||
@@ -132,18 +132,18 @@ class FavoriteRepository(BaseRepository[Favorite]):
|
||||
"""
|
||||
try:
|
||||
statement = select(Favorite).where(
|
||||
and_(Favorite.user_id == user_id, Favorite.sound_id == sound_id)
|
||||
and_(Favorite.user_id == user_id, Favorite.sound_id == sound_id),
|
||||
)
|
||||
result = await self.session.exec(statement)
|
||||
return result.first()
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to get favorite for user %s and sound %s", user_id, sound_id
|
||||
"Failed to get favorite for user %s and sound %s", user_id, sound_id,
|
||||
)
|
||||
raise
|
||||
|
||||
async def get_by_user_and_playlist(
|
||||
self, user_id: int, playlist_id: int
|
||||
self, user_id: int, playlist_id: int,
|
||||
) -> Favorite | None:
|
||||
"""Get a favorite by user and playlist.
|
||||
|
||||
@@ -157,7 +157,7 @@ class FavoriteRepository(BaseRepository[Favorite]):
|
||||
"""
|
||||
try:
|
||||
statement = select(Favorite).where(
|
||||
and_(Favorite.user_id == user_id, Favorite.playlist_id == playlist_id)
|
||||
and_(Favorite.user_id == user_id, Favorite.playlist_id == playlist_id),
|
||||
)
|
||||
result = await self.session.exec(statement)
|
||||
return result.first()
|
||||
|
||||
Reference in New Issue
Block a user