43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
// Package api provides HTTP routing and handlers for the preferences-api service.
|
|
package api
|
|
|
|
import (
|
|
"git.threesix.ai/jordan/slate-test-1770505673/pkg/app"
|
|
"git.threesix.ai/jordan/slate-test-1770505673/pkg/auth"
|
|
"git.threesix.ai/jordan/slate-test-1770505673/services/preferences-api/internal/api/handlers"
|
|
"git.threesix.ai/jordan/slate-test-1770505673/services/preferences-api/internal/config"
|
|
"git.threesix.ai/jordan/slate-test-1770505673/services/preferences-api/internal/service"
|
|
)
|
|
|
|
// RegisterRoutes registers all HTTP routes for the service.
|
|
func RegisterRoutes(application *app.App, prefService *service.PreferenceService) {
|
|
logger := application.Logger()
|
|
cfg := config.Load()
|
|
|
|
// Initialize handlers
|
|
healthHandler := handlers.NewHealth(logger)
|
|
prefHandler := handlers.NewPreference(prefService, logger)
|
|
|
|
// Build and mount OpenAPI spec
|
|
spec := NewServiceSpec()
|
|
application.EnableDocs(spec)
|
|
|
|
application.Route("/api/preferences-api", func(r app.Router) {
|
|
// Health endpoint (no auth)
|
|
r.Get("/health", healthHandler.Check)
|
|
|
|
// Preference endpoints (auth required)
|
|
r.Group(func(r app.Router) {
|
|
r.Use(auth.Middleware(auth.MiddlewareConfig{
|
|
Validator: auth.NewJWTValidator(auth.JWTConfig{
|
|
Secret: []byte(cfg.JWTSecret),
|
|
Issuer: "slate-test-1770505673",
|
|
}),
|
|
}))
|
|
|
|
r.Get("/preferences/{user_id}", app.Wrap(prefHandler.Get))
|
|
r.Put("/preferences/{user_id}", app.Wrap(prefHandler.Update))
|
|
})
|
|
})
|
|
}
|