refactor(server/api): migrate library/suggestions/radio/home preludes (A2 4/N)
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/auth"
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
||||||
)
|
)
|
||||||
@@ -14,9 +13,8 @@ import (
|
|||||||
// DB failure — the SPA should render either empty states or full content,
|
// DB failure — the SPA should render either empty states or full content,
|
||||||
// not a half-broken page.
|
// not a half-broken page.
|
||||||
func (h *handlers) handleGetHome(w http.ResponseWriter, r *http.Request) {
|
func (h *handlers) handleGetHome(w http.ResponseWriter, r *http.Request) {
|
||||||
user, ok := auth.UserFromContext(r.Context())
|
user, ok := requireUser(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
writeErr(w, apierror.ErrUnauthorized)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err := recommendation.HomeData(r.Context(), h.pool, user.ID)
|
data, err := recommendation.HomeData(r.Context(), h.pool, user.ID)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
|
||||||
@@ -119,14 +118,12 @@ func (h *handlers) handleGetArtist(w http.ResponseWriter, r *http.Request) {
|
|||||||
// as a flat list. Used by ArtistCard's play affordance, which shuffles
|
// as a flat list. Used by ArtistCard's play affordance, which shuffles
|
||||||
// client-side. 404 when the artist doesn't exist.
|
// client-side. 404 when the artist doesn't exist.
|
||||||
func (h *handlers) handleGetArtistTracks(w http.ResponseWriter, r *http.Request) {
|
func (h *handlers) handleGetArtistTracks(w http.ResponseWriter, r *http.Request) {
|
||||||
id, ok := parseUUID(chi.URLParam(r, "id"))
|
id, ok := requireURLUUID(w, r, "id")
|
||||||
if !ok {
|
if !ok {
|
||||||
writeErr(w, apierror.BadRequest("bad_request", "invalid artist id"))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, ok := auth.UserFromContext(r.Context())
|
user, ok := requireUser(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
writeErr(w, apierror.ErrUnauthorized)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
q := dbq.New(h.pool)
|
q := dbq.New(h.pool)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/auth"
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
||||||
)
|
)
|
||||||
@@ -30,9 +29,8 @@ type RadioResponse struct {
|
|||||||
// scoring formula folds in contextual_match_score using the user's current
|
// scoring formula folds in contextual_match_score using the user's current
|
||||||
// session vector (read from the most recent open play_event).
|
// session vector (read from the most recent open play_event).
|
||||||
func (h *handlers) handleRadio(w http.ResponseWriter, r *http.Request) {
|
func (h *handlers) handleRadio(w http.ResponseWriter, r *http.Request) {
|
||||||
user, ok := auth.UserFromContext(r.Context())
|
user, ok := requireUser(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
writeErr(w, apierror.ErrUnauthorized)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
raw := strings.TrimSpace(r.URL.Query().Get("seed_track"))
|
raw := strings.TrimSpace(r.URL.Query().Get("seed_track"))
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgtype"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/auth"
|
|
||||||
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
"git.fabledsword.com/bvandeusen/minstrel/internal/recommendation"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,9 +34,8 @@ type seedContributionView struct {
|
|||||||
//
|
//
|
||||||
// Returns 200 with a JSON array (possibly empty). Read-only; no admin gate.
|
// Returns 200 with a JSON array (possibly empty). Read-only; no admin gate.
|
||||||
func (h *handlers) handleListSuggestions(w http.ResponseWriter, r *http.Request) {
|
func (h *handlers) handleListSuggestions(w http.ResponseWriter, r *http.Request) {
|
||||||
user, ok := auth.UserFromContext(r.Context())
|
user, ok := requireUser(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
writeErr(w, apierror.ErrUnauthorized)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
limit := 12
|
limit := 12
|
||||||
|
|||||||
Reference in New Issue
Block a user