Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/aioe/handler.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/aioe/handler.go |
| Original SHA-256 | eec424378270b8b1f7835a98df1d5585201b52141f114ac7e3db5763ae1f8c82 |
| Git blob SHA | f4517677571b5f607a96adbab2fe4eb4ebb3e5bc |
| Reading-copy SHA-256 | eec424378270b8b1f7835a98df1d5585201b52141f114ac7e3db5763ae1f8c82 |
Every recorded occurrence
These 2 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/aioe/handler.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/aioe/handler.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓110 lines · 3.0 KB
package aioemodule
import (
"encoding/json"
"errors"
"io"
"net/http"
"strconv"
"github.com/go-chi/chi/v5"
"github.com/missionworkforce/missionmatch/internal/platform/security"
)
// Handler wires the AIOE HTTP surface. Outcome capture is a recruiter grade write (the one click
// screening feedback loop); everything under /aioe is admin only, internal proof the engine is
// alive, never customer marketing.
type Handler struct {
svc *Service
}
func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} }
func (h *Handler) Routes(r chi.Router) {
r.With(security.RequireCapability(security.CapCandidateWrite)).Post("/outcomes", h.postOutcome)
r.Route("/aioe", func(r chi.Router) {
r.Use(security.RequireRole(security.RoleAdmin))
r.Get("/status", h.getStatus)
r.Get("/history", h.getHistory)
r.Post("/run", h.postRun)
r.Post("/promote", h.postPromote)
})
}
func (h *Handler) postOutcome(w http.ResponseWriter, r *http.Request) {
var req PostOutcomeRequest
if err := json.NewDecoder(io.LimitReader(r.Body, 64*1024)).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "invalid json body")
return
}
out, err := h.svc.RecordOutcome(r.Context(), req)
if err != nil {
writeServiceErr(w, err)
return
}
writeJSON(w, http.StatusCreated, out)
}
func (h *Handler) getStatus(w http.ResponseWriter, r *http.Request) {
out, err := h.svc.Status(r.Context())
if err != nil {
writeServiceErr(w, err)
return
}
writeJSON(w, http.StatusOK, out)
}
func (h *Handler) getHistory(w http.ResponseWriter, r *http.Request) {
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
out, err := h.svc.History(r.Context(), limit)
if err != nil {
writeServiceErr(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]any{"adjustments": out})
}
func (h *Handler) postRun(w http.ResponseWriter, r *http.Request) {
report, err := h.svc.RunNow(r.Context())
if err != nil {
writeServiceErr(w, err)
return
}
writeJSON(w, http.StatusOK, report)
}
func (h *Handler) postPromote(w http.ResponseWriter, r *http.Request) {
report, err := h.svc.Promote(r.Context())
if err != nil {
writeServiceErr(w, err)
return
}
writeJSON(w, http.StatusOK, report)
}
func writeServiceErr(w http.ResponseWriter, err error) {
switch {
case errors.Is(err, ErrBadRequest):
writeError(w, http.StatusBadRequest, err.Error())
case errors.Is(err, ErrNotConfigured):
writeError(w, http.StatusServiceUnavailable, "the optimization engine is not configured on this deployment")
case errors.Is(err, ErrNoDatabase):
writeError(w, http.StatusServiceUnavailable, "no database configured")
default:
writeError(w, http.StatusInternalServerError, "internal error")
}
}
func writeError(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 writeJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(v)
}