Files
TradarrV2/backend/internal/api/handlers/preferences.go
Blomios 989996fbd6 feat(ai): add personal summary models and retire Q&A
Add an admin-managed provider model catalog with per-user summary selection, migration backfill, and generation snapshots. Retire report creation and messaging while preserving owner-scoped history.

Refs #15 #16

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-21 20:45:21 +01:00

51 lines
1.1 KiB
Go

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, models.ErrSummaryModelUnavailable) {
c.JSON(400, gin.H{"error": "summary_model_unavailable"})
return
}
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)
}