feat(api): add GET /api/library/albums handler
Implements the paged alpha-sorted album list endpoint used by the M6a wrapping-grid SPA page. Mirrors handleListArtists alpha branch using ListAlbumsAlphaWithArtist + CountAlbums; 2/2 integration tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
)
|
||||
|
||||
// handleListLibraryAlbums implements GET /api/library/albums. Mirrors
|
||||
// /api/artists?sort=alpha but for albums. The new wrapping-grid page on
|
||||
// the SPA infinite-scrolls against this endpoint via TanStack
|
||||
// createInfiniteQuery.
|
||||
func (h *handlers) handleListLibraryAlbums(w http.ResponseWriter, r *http.Request) {
|
||||
limit, offset, err := parsePaging(r.URL.Query())
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadRequest, "bad_request", err.Error())
|
||||
return
|
||||
}
|
||||
q := dbq.New(h.pool)
|
||||
rows, err := q.ListAlbumsAlphaWithArtist(r.Context(), dbq.ListAlbumsAlphaWithArtistParams{
|
||||
Limit: int32(limit), Offset: int32(offset),
|
||||
})
|
||||
if err != nil {
|
||||
h.logger.Error("api: list library albums", "err", err)
|
||||
writeErr(w, http.StatusInternalServerError, "server_error", "lookup failed")
|
||||
return
|
||||
}
|
||||
total, err := q.CountAlbums(r.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("api: count albums", "err", err)
|
||||
writeErr(w, http.StatusInternalServerError, "server_error", "count failed")
|
||||
return
|
||||
}
|
||||
items := make([]AlbumRef, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
items = append(items, albumRefFrom(row.Album, row.ArtistName, 0, 0))
|
||||
}
|
||||
writeJSON(w, http.StatusOK, Page[AlbumRef]{
|
||||
Items: items, Total: int(total), Limit: limit, Offset: offset,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user