feat: Implement playlist reordering with position swapping and reload player on current playlist changes
This commit is contained in:
@@ -165,6 +165,20 @@ class PlaylistRepository(BaseRepository[Playlist]):
|
||||
|
||||
"""
|
||||
try:
|
||||
# Phase 1: Set all positions to temporary negative values to avoid conflicts
|
||||
temp_offset = -10000 # Use large negative number to avoid conflicts
|
||||
for i, (sound_id, _) in enumerate(sound_positions):
|
||||
statement = select(PlaylistSound).where(
|
||||
PlaylistSound.playlist_id == playlist_id,
|
||||
PlaylistSound.sound_id == sound_id,
|
||||
)
|
||||
result = await self.session.exec(statement)
|
||||
playlist_sound = result.first()
|
||||
|
||||
if playlist_sound:
|
||||
playlist_sound.position = temp_offset + i
|
||||
|
||||
# Phase 2: Set the final positions
|
||||
for sound_id, new_position in sound_positions:
|
||||
statement = select(PlaylistSound).where(
|
||||
PlaylistSound.playlist_id == playlist_id,
|
||||
|
||||
Reference in New Issue
Block a user