Files
TradarrV2/backend/internal/api/router.go
Blomios 5cb45138df feat(indices): add authenticated OpenFIGI search
Add the bounded OpenFIGI v3 adapter, authenticated search route, and server-side configuration.

Refs #3

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

96 lines
2.9 KiB
Go

package api
import (
"github.com/gin-gonic/gin"
"github.com/tradarr/backend/internal/api/handlers"
"github.com/tradarr/backend/internal/auth"
)
func SetupRouter(h *handlers.Handler, jwtSecret string) *gin.Engine {
r := gin.New()
r.Use(gin.Recovery())
r.Use(gin.LoggerWithConfig(gin.LoggerConfig{
SkipPaths: []string{"/api/summaries/status"},
}))
r.Use(func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
c.Header("Access-Control-Allow-Headers", "Authorization,Content-Type")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
})
api := r.Group("/api")
// Auth public
api.POST("/auth/login", h.Login)
// Routes authentifiées
authed := api.Group("/")
authed.Use(auth.Middleware(jwtSecret))
authed.GET("/indices/search", h.SearchIndices)
authed.GET("/me", h.GetMe)
authed.GET("/me/preferences", h.GetMyPreferences)
authed.PUT("/me/preferences", h.UpdateMyPreferences)
authed.GET("/me/assets", h.GetMyAssets)
authed.POST("/me/assets", h.AddMyAsset)
authed.DELETE("/me/assets/:id", h.RemoveMyAsset)
authed.GET("/summaries", h.ListSummaries)
authed.GET("/summaries/generations", h.ListGenerations)
authed.GET("/summaries/status", h.GetGeneratingStatus)
authed.POST("/summaries/generate", h.GenerateSummary)
authed.GET("/reports", h.ListReports)
authed.POST("/reports", h.CreateReport)
authed.DELETE("/reports/:id", h.DeleteReport)
authed.GET("/reports/:id/messages", h.ListReportMessages)
authed.POST("/reports/:id/messages", h.CreateReportMessage)
// Admin
admin := authed.Group("/admin")
admin.Use(h.AdminOnly())
admin.GET("/credentials", h.GetCredentials)
admin.PUT("/credentials", h.UpsertCredentials)
admin.GET("/ai-providers", h.ListAIProviders)
admin.POST("/ai-providers", h.CreateAIProvider)
admin.PUT("/ai-providers/:id", h.UpdateAIProvider)
admin.POST("/ai-providers/:id/activate", h.SetActiveAIProvider)
admin.DELETE("/ai-providers/:id", h.DeleteAIProvider)
admin.GET("/ai-providers/:id/models", h.ListAIModels)
admin.POST("/ai-providers/probe-models", h.ProbeAIModels)
admin.GET("/sources", h.ListSources)
admin.PUT("/sources/:id", h.UpdateSource)
admin.GET("/settings", h.ListSettings)
admin.PUT("/settings", h.UpdateSettings)
admin.GET("/settings/default-prompt", h.GetDefaultSystemPrompt)
admin.GET("/schedule", h.GetSchedule)
admin.PUT("/schedule", h.UpdateSchedule)
admin.GET("/users", h.ListUsers)
admin.POST("/users", h.CreateAdminUser)
admin.PUT("/users/:id", h.UpdateAdminUser)
admin.DELETE("/users/:id", h.DeleteAdminUser)
// AI roles (per-task model assignment)
admin.GET("/ai-roles", h.GetAIRoles)
admin.PUT("/ai-roles/:role", h.UpdateAIRole)
// Ollama model management
admin.GET("/ollama/models", h.ListOllamaModels)
admin.POST("/ollama/pull", h.PullOllamaModel)
admin.DELETE("/ollama/models/:name", h.DeleteOllamaModel)
return r
}