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) } }