package wages import ( "encoding/json" "errors" "net/http" "github.com/go-chi/chi/v5" "github.com/missionworkforce/missionmatch/internal/platform/security" ) // Handler serves the cached wage baseline read API. type Handler struct{ svc *Service } func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} } // Routes mounts the wages endpoint under the /api group. // Routes mounts the cached wage baseline. Gated for the reason set out on the opportunity routes. func (h *Handler) Routes(r chi.Router) { r.With(security.RequireCapability(security.CapCandidateRead)).Get("/wages", h.baseline) } func (h *Handler) baseline(w http.ResponseWriter, r *http.Request) { items, err := h.svc.Baseline(r.Context()) w.Header().Set("Content-Type", "application/json") if err != nil { if errors.Is(err, ErrNoDatabase) { w.WriteHeader(http.StatusServiceUnavailable) _, _ = w.Write([]byte(`{"error":"database not configured"}`)) return } w.WriteHeader(http.StatusInternalServerError) _, _ = w.Write([]byte(`{"error":"internal error"}`)) return } _ = json.NewEncoder(w).Encode(items) }