feat(server): GET /api/library/sync endpoint
Returns batched upserts + deletes since the supplied cursor. Empty cursor
returns full snapshot; subsequent calls pull deltas. Per-user entities
(likes, playlists) are scoped to the authed user. Composite-key entities
(likes, playlist_tracks) use stable string ids encoded by sync.EncodeLikeID
/ sync.EncodePlaylistTrackID.
Behavior:
204 No Content - no changes since cursor
200 OK - JSON syncResponse {cursor, upserts, deletes}
410 Gone - cursor older than oldest log row; client must reset
401 / 500 - standard envelope errors
Adds sqlc queries GetAlbumsByIDs, GetTracksByIDs, GetPlaylistsByIDs to
mirror the existing GetArtistsByIDs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,46 @@ func (q *Queries) GetPlaylist(ctx context.Context, id pgtype.UUID) (GetPlaylistR
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPlaylistsByIDs = `-- name: GetPlaylistsByIDs :many
|
||||
SELECT id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id FROM playlists WHERE id = ANY($1::uuid[])
|
||||
`
|
||||
|
||||
// Batched lookup used by /api/library/sync to hydrate upsert payloads
|
||||
// (#357). Mirror of GetArtistsByIDs.
|
||||
func (q *Queries) GetPlaylistsByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Playlist, error) {
|
||||
rows, err := q.db.Query(ctx, getPlaylistsByIDs, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Playlist
|
||||
for rows.Next() {
|
||||
var i Playlist
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.IsPublic,
|
||||
&i.CoverPath,
|
||||
&i.TrackCount,
|
||||
&i.DurationSec,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listAllPlaylistTracksForCollage = `-- name: ListAllPlaylistTracksForCollage :many
|
||||
SELECT pt.position,
|
||||
albums.cover_art_path AS album_cover_path
|
||||
|
||||
Reference in New Issue
Block a user