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:
46
backend/internal/api/handlers/preferences.go
Normal file
46
backend/internal/api/handlers/preferences.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user