feat(accounts): add admin accounts and user preferences

Remove public registration, support administrator-managed accounts, and persist personal preferences.

Refs #2 #5

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 19:54:06 +01:00
parent 1b0625f91c
commit 50bde816ed
46 changed files with 1362 additions and 256 deletions

View File

@ -0,0 +1,46 @@
package handlers
import (
"database/sql"
"errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/tradarr/backend/internal/httputil"
"github.com/tradarr/backend/internal/models"
)
func preferencesError(c *gin.Context, err error) {
if errors.Is(err, sql.ErrNoRows) {
httputil.NotFound(c)
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": "preferences unavailable"})
}
func (h *Handler) GetMyPreferences(c *gin.Context) {
if h.repo == nil {
preferencesError(c, errors.New("repository unavailable"))
return
}
p, err := h.repo.GetUserPreferences(c.GetString("userID"))
if err != nil {
preferencesError(c, err)
return
}
httputil.OK(c, p)
}
func (h *Handler) UpdateMyPreferences(c *gin.Context) {
var req models.UserPreferences
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid preferences"})
return
}
p, err := h.repo.UpdateUserPreferences(c.GetString("userID"), req)
if err != nil {
preferencesError(c, err)
return
}
httputil.OK(c, p)
}