Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/commandcenter/handler.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/commandcenter/handler.go |
| Original SHA-256 | e3640bc47e33a73b8d9d9999f805c9d9708041df61f9b0865cd6745c86e72de2 |
| Git blob SHA | 47368cd56f9deb81f129197baf5895596971885d |
| Reading-copy SHA-256 | e3640bc47e33a73b8d9d9999f805c9d9708041df61f9b0865cd6745c86e72de2 |
Every recorded occurrence
These 15 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | ws8-teaching-loop | c823f0fb6bb2aba0f39001eb6de96f4000d9321f | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | ws9-bench-ingestion | f585a9ef32fa554663ce1fba9a414a54b6e49cf0 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | ws7-federal-signal | 6a9f6ce9cfb13345ffb47770d4960e7c2d9c17c2 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/modules/commandcenter/handler.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓114 lines · 4.2 KB
package commandcenter
import (
"encoding/json"
"errors"
"net/http"
"time"
"github.com/go-chi/chi/v5"
"github.com/missionworkforce/missionmatch/internal/platform/security"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// Handler serves the Workforce Command Center endpoint.
type Handler struct{ svc *Service }
func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} }
// Routes mounts the Command Center endpoints under the tenant scoped group. The dashboard read is gated
// on candidate.read since the payload exposes candidate names and clearance (the same data class as GET
// /candidates). Adopting a forecast as a requirement is a write, gated on requirement.write.
func (h *Handler) Routes(r chi.Router) {
r.With(security.RequireCapability(security.CapCandidateRead)).Get("/command-center", h.get)
// The federal signal panel reads public federal data and the global mission tag and incumbent role
// catalogs. It is gated on candidate.read like the dashboard since it shares the same surface, and it
// is read only. The optional mission query parameter scopes the open by mission list to one code.
r.With(security.RequireCapability(security.CapCandidateRead)).Get("/command-center/federal-signal", h.federalSignal)
r.With(security.RequireCapability(security.CapRequirementEdit)).Post("/command-center/upcoming/{recordID}/adopt", h.adopt)
}
func (h *Handler) federalSignal(w http.ResponseWriter, r *http.Request) {
mission := r.URL.Query().Get("mission")
v, err := h.svc.FederalSignal(r.Context(), mission)
if err != nil {
switch {
case errors.Is(err, errUnknownMission):
writeJSONErr(w, http.StatusBadRequest, "unknown mission code")
case errors.Is(err, tenant.ErrNoTenant):
writeJSONErr(w, http.StatusForbidden, "no validated tenant")
case errors.Is(err, ErrNoDatabase):
writeJSONErr(w, http.StatusServiceUnavailable, "database not configured")
default:
writeJSONErr(w, http.StatusInternalServerError, "internal error")
}
return
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(v)
}
func (h *Handler) adopt(w http.ResponseWriter, r *http.Request) {
recordID := chi.URLParam(r, "recordID")
var in AdoptForecastInput
dec := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1<<20))
dec.DisallowUnknownFields()
if err := dec.Decode(&in); err != nil {
writeJSONErr(w, http.StatusBadRequest, "invalid request body")
return
}
res, err := h.svc.AdoptForecast(r.Context(), recordID, in)
if err != nil {
switch {
case errors.Is(err, ErrForecastNotFound):
writeJSONErr(w, http.StatusNotFound, "forecast not found")
case errors.Is(err, ErrNotAForecast), errors.Is(err, ErrBadRequest):
writeJSONErr(w, http.StatusBadRequest, "record is not an adoptable forecast")
case errors.Is(err, tenant.ErrNoTenant):
writeJSONErr(w, http.StatusForbidden, "no validated tenant")
case errors.Is(err, ErrNoDatabase):
writeJSONErr(w, http.StatusServiceUnavailable, "database not configured")
default:
writeJSONErr(w, http.StatusInternalServerError, "internal error")
}
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
_ = json.NewEncoder(w).Encode(res)
}
func writeJSONErr(w http.ResponseWriter, status int, msg string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(map[string]string{"error": msg})
}
func (h *Handler) get(w http.ResponseWriter, r *http.Request) {
asOf := h.svc.clock()
if q := r.URL.Query().Get("as_of"); q != "" {
if t, err := time.Parse("2006-01-02", q); err == nil {
asOf = t
}
}
v, err := h.svc.CommandCenter(r.Context(), asOf)
if err != nil {
w.Header().Set("Content-Type", "application/json")
switch {
case errors.Is(err, tenant.ErrNoTenant):
w.WriteHeader(http.StatusForbidden)
_, _ = w.Write([]byte(`{"error":"no validated tenant"}`))
case errors.Is(err, ErrNoDatabase):
w.WriteHeader(http.StatusServiceUnavailable)
_, _ = w.Write([]byte(`{"error":"database not configured"}`))
default:
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(`{"error":"internal error"}`))
}
return
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(v)
}