@@ -7,12 +7,16 @@ import (
77 "musicboxapi/models"
88)
99
10- func (pdb * PostgresDb ) FetchPlaylistSongs (ctx context.Context , playlistId int ) (songs []models.Song , error error ) {
10+ func (pdb * PostgresDb ) FetchPlaylistSongs (ctx context.Context , playlistId int , lastKnowPosition int ) (songs []models.Song , error error ) {
1111
12- query := `SELECT s.Id, s.Name, s.Path, s.ThumbnailPath, s.Duration, s.SourceId, s.UpdatedAt, CreatedAt FROM Song s
13- INNER JOIN PlaylistSong ps ON ps.PlaylistId = $1
14- WHERE ps.SongId = s.Id
15- order by ps.Position` // order by playlist position
12+ // query := `SELECT s.Id, s.Name, s.Path, s.ThumbnailPath, s.Duration, s.SourceId, s.UpdatedAt, CreatedAt FROM Song s
13+ // INNER JOIN PlaylistSong ps ON ps.PlaylistId = $1
14+ // WHERE ps.SongId = s.Id
15+ // order by ps.Position` // order by playlist position
16+
17+ query := `SELECT s.Id, s.Name, s.Path, s.ThumbnailPath, s.Duration, s.SourceId, s.UpdatedAt, s.CreatedAt FROM playlistsong ps
18+ INNER JOIN song s ON s.id = ps.songid
19+ WHERE ps.playlistid = $1 AND ps.position > $2`
1620
1721 statement , err := pdb .connection .Prepare (query )
1822 defer statement .Close ()
@@ -22,7 +26,7 @@ func (pdb *PostgresDb) FetchPlaylistSongs(ctx context.Context, playlistId int) (
2226 return nil , err
2327 }
2428
25- rows , err := statement .QueryContext (ctx , playlistId )
29+ rows , err := statement .QueryContext (ctx , playlistId , lastKnowPosition )
2630 defer rows .Close ()
2731
2832 if err != nil {
0 commit comments