43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
// Package api provides HTTP routing and handlers for the preferences-api service.
|
|
package api
|
|
|
|
import (
|
|
"git.threesix.ai/jordan/slate-v3-1770514618/pkg/app"
|
|
"git.threesix.ai/jordan/slate-v3-1770514618/pkg/auth"
|
|
"git.threesix.ai/jordan/slate-v3-1770514618/services/preferences-api/internal/api/handlers"
|
|
"git.threesix.ai/jordan/slate-v3-1770514618/services/preferences-api/internal/config"
|
|
"git.threesix.ai/jordan/slate-v3-1770514618/services/preferences-api/internal/service"
|
|
)
|
|
|
|
// RegisterRoutes registers all HTTP routes for the service.
|
|
// Routes are mounted under /api/preferences-api to match the ingress path routing.
|
|
func RegisterRoutes(application *app.App, preferencesService *service.PreferencesService) {
|
|
logger := application.Logger()
|
|
cfg := config.Load()
|
|
|
|
healthHandler := handlers.NewHealth(logger)
|
|
preferencesHandler := handlers.NewPreferences(preferencesService)
|
|
|
|
spec := NewServiceSpec()
|
|
application.EnableDocs(spec)
|
|
|
|
application.Route("/api/preferences-api", func(r app.Router) {
|
|
r.Get("/health", healthHandler.Check)
|
|
|
|
// Protected routes (auth required when enabled)
|
|
r.Group(func(r app.Router) {
|
|
if cfg.AuthEnabled {
|
|
r.Use(auth.Middleware(auth.MiddlewareConfig{
|
|
Validator: auth.NewJWTValidator(auth.JWTConfig{
|
|
Secret: []byte(cfg.JWTSecret),
|
|
Issuer: "slate-v3-1770514618",
|
|
}),
|
|
}))
|
|
}
|
|
|
|
r.Get("/preferences/{user_id}", app.Wrap(preferencesHandler.Get))
|
|
r.Put("/preferences/{user_id}", app.Wrap(preferencesHandler.Update))
|
|
})
|
|
})
|
|
}
|