Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/bidoutcomes/handler.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/bidoutcomes/handler.go |
| Original SHA-256 | 58ce2aa4411092094d41c582ddbb0f2a6d89535294de5eabb8f8da76dee4ee32 |
| Git blob SHA | 4eae3807fdd495eae4f24c5b9de2f6b836616d72 |
| Reading-copy SHA-256 | 58ce2aa4411092094d41c582ddbb0f2a6d89535294de5eabb8f8da76dee4ee32 |
Every recorded occurrence
These 12 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/bidoutcomes/handler.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/modules/bidoutcomes/handler.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓91 lines · 3.5 KB
package bidoutcomes
import (
"encoding/json"
"errors"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/missionworkforce/missionmatch/internal/platform/security"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// Handler serves the M7 bid outcomes recording API: record (POST) and update (PATCH). It is mounted ONLY
// when the MM_BID_OUTCOMES_ENABLED flag is on, so the feature ships dormant; when off the routes are never
// registered and a request to them is a plain 404 from the router.
type Handler struct{ svc *Service }
// NewHandler builds the handler.
func NewHandler(svc *Service) *Handler { return &Handler{svc: svc} }
// Routes mounts the bid outcomes endpoints under the tenant scoped /api group. Recording and updating a bid
// outcome is a proposal team write action, so both are gated on slate.write (the same authority tier that
// edits a slate and generates staffing recommendations): owner, admin, and recruiter. The caller and the
// validated org come from the session resolver and RBAC middleware the group already applies, never a
// client supplied header or body field.
func (h *Handler) Routes(r chi.Router) {
r.With(security.RequireCapability(security.CapSlateEdit)).Post("/bid-outcomes", h.record)
r.With(security.RequireCapability(security.CapSlateEdit)).Patch("/bid-outcomes/{id}", h.update)
}
func (h *Handler) record(w http.ResponseWriter, r *http.Request) {
var in RecordInput
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request body"})
return
}
out, err := h.svc.RecordBidOutcome(r.Context(), in)
if err != nil {
writeErr(w, err)
return
}
writeJSON(w, http.StatusCreated, out)
}
func (h *Handler) update(w http.ResponseWriter, r *http.Request) {
id, err := uuid.Parse(chi.URLParam(r, "id"))
if err != nil {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid id"})
return
}
var in UpdateInput
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request body"})
return
}
out, err := h.svc.UpdateBidOutcome(r.Context(), id, in)
if err != nil {
writeErr(w, err)
return
}
writeJSON(w, http.StatusOK, out)
}
// writeErr maps a service error to a status. A bad result enum or a malformed id is a 422, a missing row is
// a 404, an unscoped request is a 403, and an unconfigured database is a 503; everything else is a 500 with
// no internal detail leaked.
func writeErr(w http.ResponseWriter, err error) {
switch {
case errors.Is(err, ErrInvalidResult):
writeJSON(w, http.StatusUnprocessableEntity, map[string]string{"error": "result must be one of win, loss, no_bid, pending"})
case errors.Is(err, ErrInvalidID):
writeJSON(w, http.StatusUnprocessableEntity, map[string]string{"error": "an id field must be a uuid"})
case errors.Is(err, ErrNotFound):
writeJSON(w, http.StatusNotFound, map[string]string{"error": "bid outcome not found"})
case errors.Is(err, tenant.ErrNoTenant):
writeJSON(w, http.StatusForbidden, map[string]string{"error": "no validated tenant"})
case errors.Is(err, ErrNoDatabase):
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
default:
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "internal error"})
}
}
func writeJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(v)
}