Pilot for one-module-per-resource: bindingsAPI owns the /api/bindings* routes and their handlers, constructed only when the binding store is configured; a 503 stub mounts the same routes otherwise, preserving the old not-configured answers. Handlers move off *Server unchanged in behavior; the shared dispatch-ledger handler stays on Server for the captures/tasks routes. task check green.
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package webui
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
)
|
|
|
|
// handleDispatches serves the newest dispatch ledger rows for the resource the
|
|
// path names, linking bindings, captures and tasks to each other. Shared by
|
|
// the bindings module and the captures/tasks routes, so it stays on Server.
|
|
func (s *Server) handleDispatches(filterFor func(id string) (storecontract.DispatchFilter, bool)) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if s.Dispatches == nil {
|
|
http.Error(w, "dispatch ledger not configured", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
filter, ok := filterFor(r.PathValue("id"))
|
|
if !ok {
|
|
http.Error(w, "invalid id", http.StatusBadRequest)
|
|
return
|
|
}
|
|
filter.Limit = 50
|
|
dispatches, err := s.Dispatches.ListDispatches(r.Context(), filter)
|
|
if err != nil {
|
|
s.Log.ErrorContext(r.Context(), "list dispatches", "err", err)
|
|
http.Error(w, "list dispatches failed", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
writeJSON(w, dispatches)
|
|
}
|
|
}
|