feat(api): extend ArtistRef/AlbumRef + add HomePayload for M6a

- ArtistRef gains SortName and CoverURL fields
- AlbumRef gains SortTitle field
- albumRefFrom now populates SortTitle from dbq.Album.SortTitle
- artistRefFrom now populates SortName from dbq.Artist.SortName
- New artistRefFromCovered helper builds CoverURL from nullable cover_album_id
- New HomePayload view type for GET /api/home response body
This commit is contained in:
2026-05-01 17:56:19 -04:00
parent 302a15a209
commit 1abaf15051
2 changed files with 40 additions and 4 deletions
+22 -2
View File
@@ -36,18 +36,26 @@ type Page[T any] struct {
}
// ArtistRef is the lightweight artist shape used in lists and search results.
// SortName is exposed so the SPA's alphabetical-grid divider can group rows
// by the catalogue sort order ("The Beatles" → "B"). CoverURL is derived from
// a representative album (most-recent with cover_art_path); empty when the
// artist's discography has no cover art.
type ArtistRef struct {
ID string `json:"id"`
Name string `json:"name"`
SortName string `json:"sort_name"`
AlbumCount int `json:"album_count"`
CoverURL string `json:"cover_url"`
}
// AlbumRef is the lightweight album shape used in lists, artist details,
// and search results. CoverURL points to /api/albums/{id}/cover which
// Plan 3 implements.
// and search results. SortTitle is exposed so the SPA's alphabetical-grid
// divider can group rows by sort order ("The Wall" → "W"). CoverURL points
// to /api/albums/{id}/cover.
type AlbumRef struct {
ID string `json:"id"`
Title string `json:"title"`
SortTitle string `json:"sort_title"`
ArtistID string `json:"artist_id"`
ArtistName string `json:"artist_name"`
Year int `json:"year,omitempty"`
@@ -92,3 +100,15 @@ type SearchResponse struct {
Albums Page[AlbumRef] `json:"albums"`
Tracks Page[TrackRef] `json:"tracks"`
}
// HomePayload is the response body of GET /api/home. Field counts:
// 50 (recently_added) / 25 (rediscover_albums) / 25 (rediscover_artists)
// / 75 (most_played) / 25 (last_played). All slices are non-nil at JSON
// encode time so empty sections render as [] rather than null.
type HomePayload struct {
RecentlyAddedAlbums []AlbumRef `json:"recently_added_albums"`
RediscoverAlbums []AlbumRef `json:"rediscover_albums"`
RediscoverArtists []ArtistRef `json:"rediscover_artists"`
MostPlayedTracks []TrackRef `json:"most_played_tracks"`
LastPlayedArtists []ArtistRef `json:"last_played_artists"`
}