Files
minstrel/internal/api/me_normalization.go
T
bvandeusenandClaude Opus 5.5 08a2c06b85 docs: api comments say what the endpoints do, not how they came to be (#6277)
Rewrites the internal/api comment blocks to rule 32: task, milestone and
rule ids gone, the stories behind them restated as the constraint they
left, stale references corrected (the stream secret is wired from config,
the timezone handler already refreshes the scheduler, the Android app is
the native client, the design docs cited are not in the repo). Also
rewraps comment lines over 80 columns left by the earlier batches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:23:58 -04:00

52 lines
1.7 KiB
Go

package api
import (
"encoding/json"
"errors"
"net/http"
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/library"
)
// GET /api/me/normalization returns the caller's loudness-normalization
// preference, or the defaults when they have never set one.
func (h *handlers) handleGetMyNormalization(w http.ResponseWriter, r *http.Request) {
caller, ok := requireUser(w, r)
if !ok {
return
}
p, err := library.LoadNormalizationPrefs(r.Context(), dbq.New(h.pool), caller.ID)
if err != nil {
writeErrWithLog(w, h.logger, "normalization: load", apierror.InternalMsg("lookup failed", err))
return
}
writeJSON(w, http.StatusOK, p)
}
// PUT /api/me/normalization replaces the caller's preference with the whole
// body. Every field is required, so a client replaying a queued change
// offline sends the full state it showed the user, and the last write wins.
func (h *handlers) handlePutMyNormalization(w http.ResponseWriter, r *http.Request) {
caller, ok := requireUser(w, r)
if !ok {
return
}
var body library.NormalizationPrefs
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
writeErr(w, apierror.BadRequest("bad_body", "invalid JSON body"))
return
}
p, err := library.SaveNormalizationPrefs(r.Context(), dbq.New(h.pool), caller.ID, body)
if errors.Is(err, library.ErrNormalizationPrefsInvalid) {
writeErr(w, apierror.BadRequest("invalid_normalization", err.Error()))
return
}
if err != nil {
writeErrWithLog(w, h.logger, "normalization: save", apierror.InternalMsg("save failed", err))
return
}
writeJSON(w, http.StatusOK, p)
}