refactor(server/api): migrate requests/quarantine/me_token/listenbrainz/admin_invites preludes (A2 3/N)
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"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/lidarrquarantine"
|
||||
)
|
||||
@@ -44,14 +41,12 @@ type flagBody struct {
|
||||
|
||||
// handleFlag implements POST /api/quarantine. Upserts via Service.Flag.
|
||||
func (h *handlers) handleFlag(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := auth.UserFromContext(r.Context())
|
||||
user, ok := requireUser(w, r)
|
||||
if !ok {
|
||||
writeErr(w, apierror.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
var body flagBody
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeErr(w, apierror.BadRequest("bad_request", "invalid JSON body"))
|
||||
if !decodeBody(w, r, &body) {
|
||||
return
|
||||
}
|
||||
trackID, ok := parseUUID(body.TrackID)
|
||||
@@ -77,14 +72,12 @@ func (h *handlers) handleFlag(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// handleUnflag implements DELETE /api/quarantine/{track_id}.
|
||||
func (h *handlers) handleUnflag(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := auth.UserFromContext(r.Context())
|
||||
user, ok := requireUser(w, r)
|
||||
if !ok {
|
||||
writeErr(w, apierror.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
id, ok := parseUUID(chi.URLParam(r, "track_id"))
|
||||
id, ok := requireURLUUID(w, r, "track_id")
|
||||
if !ok {
|
||||
writeErr(w, apierror.BadRequest("bad_request", "invalid track id"))
|
||||
return
|
||||
}
|
||||
if err := h.lidarrQuarantine.Unflag(r.Context(), user.ID, id); err != nil {
|
||||
@@ -118,9 +111,8 @@ type quarantineMineView struct {
|
||||
// handleListMyQuarantine implements GET /api/quarantine/mine. Returns the
|
||||
// caller's quarantines with track/album/artist detail.
|
||||
func (h *handlers) handleListMyQuarantine(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := auth.UserFromContext(r.Context())
|
||||
user, ok := requireUser(w, r)
|
||||
if !ok {
|
||||
writeErr(w, apierror.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
rows, err := h.lidarrQuarantine.ListMine(r.Context(), user.ID)
|
||||
|
||||
Reference in New Issue
Block a user