Added api/classifications endpoint, requiring a new query
This commit is contained in:
1 parent
378ac59f41
commit
0e27d2b2f3
9 files changed
+186
-6
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"git.avsdev.uk/Go/job-search/internal/httpx"
|
||||
"git.avsdev.uk/Go/job-search/internal/store"
|
||||
)
|
||||
|
||||
// classificationRoutes wires HTTP handlers to the classification codes in
|
||||
// the opportunity store. They're read-only.
|
||||
type classificationRoutes struct {
|
||||
store *store.Store
|
||||
}
|
||||
|
||||
// newClassificationRoutes returns the classification handlers for
|
||||
// opportunityStore.
|
||||
func newClassificationRoutes(
|
||||
opportunityStore *store.Store,
|
||||
) *classificationRoutes {
|
||||
return &classificationRoutes{
|
||||
store: opportunityStore,
|
||||
}
|
||||
}
|
||||
|
||||
// Routes registers the classification routes on router (mounted under
|
||||
// /api).
|
||||
func (h *classificationRoutes) Routes(router chi.Router) {
|
||||
router.Get("/classifications", h.list)
|
||||
}
|
||||
|
||||
// list serves GET /classifications: every classification code that at least
|
||||
// one opportunity has, ordered by code.
|
||||
//
|
||||
// @Summary List classifications
|
||||
// @Description Every classification code (CPV and others) that at least one
|
||||
// @Description stored opportunity has, once each, ordered by code: the
|
||||
// @Description codes worth filtering opportunities by.
|
||||
// @Tags classifications
|
||||
// @Produce json
|
||||
// @Success 200 {array} types.ClassificationCode
|
||||
// @Failure 500 {object} httpx.Problem
|
||||
// @Router /classifications [get]
|
||||
func (h *classificationRoutes) list(w http.ResponseWriter, r *http.Request) {
|
||||
classifications, err := h.store.ListClassifications(r.Context())
|
||||
if err != nil {
|
||||
httpx.WriteProblem(w, r, http.StatusInternalServerError, "")
|
||||
return
|
||||
}
|
||||
|
||||
httpx.WriteJSON(w, http.StatusOK, classifications)
|
||||
}
|
||||
Reference in new issue
Block a user