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:
+18
-2
@@ -75,16 +75,31 @@ func streamURL(trackID pgtype.UUID) string {
|
||||
return "/api/tracks/" + uuidToString(trackID) + "/stream"
|
||||
}
|
||||
|
||||
// artistRefFrom projects a dbq.Artist into an ArtistRef. albumCount must be
|
||||
// pre-computed by the caller (one query per artist in lists).
|
||||
// artistRefFrom projects a dbq.Artist into an ArtistRef without cover.
|
||||
// albumCount must be pre-computed by the caller. Used by code paths that
|
||||
// don't have a representative-album lookup at hand (artist detail, search,
|
||||
// liked-artists list).
|
||||
func artistRefFrom(a dbq.Artist, albumCount int) ArtistRef {
|
||||
return ArtistRef{
|
||||
ID: uuidToString(a.ID),
|
||||
Name: a.Name,
|
||||
SortName: a.SortName,
|
||||
AlbumCount: albumCount,
|
||||
}
|
||||
}
|
||||
|
||||
// artistRefFromCovered projects a dbq.Artist into an ArtistRef with the
|
||||
// derived CoverURL populated from a representative album id (nullable).
|
||||
// Used by /api/home and /api/artists?sort=alpha which carry the lookup
|
||||
// in the same query.
|
||||
func artistRefFromCovered(a dbq.Artist, albumCount int, coverAlbumID pgtype.UUID) ArtistRef {
|
||||
ref := artistRefFrom(a, albumCount)
|
||||
if coverAlbumID.Valid {
|
||||
ref.CoverURL = coverURL(coverAlbumID)
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
||||
// albumRefFrom projects a dbq.Album into an AlbumRef. artistName must be
|
||||
// pre-resolved because Album only carries artist_id. trackCount and
|
||||
// durationSec may be 0 when the caller does not compute them.
|
||||
@@ -92,6 +107,7 @@ func albumRefFrom(a dbq.Album, artistName string, trackCount, durationSec int) A
|
||||
return AlbumRef{
|
||||
ID: uuidToString(a.ID),
|
||||
Title: a.Title,
|
||||
SortTitle: a.SortTitle,
|
||||
ArtistID: uuidToString(a.ArtistID),
|
||||
ArtistName: artistName,
|
||||
Year: yearFromDate(a.ReleaseDate),
|
||||
|
||||
Reference in New Issue
Block a user