feat: Implement playlist reordering with position swapping and reload player on current playlist changes
Some checks failed
Backend CI / lint (push) Failing after 5m7s
Backend CI / test (push) Successful in 5m14s

This commit is contained in:
JSC
2025-08-01 17:49:29 +02:00
parent 0575d12b0e
commit d926779fe4
4 changed files with 161 additions and 8 deletions

View File

@@ -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,