Files
job-tracker/internal/services/job_status.go
T
adamfandClaude Opus 5.5 67cb8137f9
Test and publish / test (push) Successful in 6m39s
Test and publish / publish (push) Failing after 0s
Split the job tracker out of web_server into its own app
The applications tracker, leads inbox, email pipeline and capture userscript
move here from web_server's backend, Python service and Vue app, as one Go
binary that serves its own Vue SPA under /jobs/.

- The Go services, resolvers and tests move over almost unchanged.
- The three Claude calls are ported from Python to Go (internal/claude),
  with the same prompts, per-model request shaping and error messages.
- There is no login: internal/auth asks the site backend's
  /auth/validate-admin with the visitor's cookies, and relays refreshed
  cookies back.
- A Settings page replaces the admin-panel capture token card and adds the
  Microsoft sign-in link and a manual email sync.
- The userscript is 2.0.0, at /jobs/, and migrates a saved API base.
- Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI
  workflow that tests and publishes the image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 16:24:16 +01:00

76 lines
3.1 KiB
Go

package services
import (
"fmt"
"strings"
"github.com/99designs/gqlgen/graphql"
)
// The job-status vocabulary, as GraphQL sees it.
//
// The schema declares `enum JobStatus` (graph/schema/job_application.graphql)
// and gqlgen.yml binds it to the two functions below instead of letting
// gqlgen generate a Go enum type. That keeps models.JobApplication.Status a
// plain string column — no migration, and the email pipeline and the capture
// endpoint go on writing strings — while the GraphQL boundary still refuses a
// status nobody ranked.
//
// statusOrder (email_sync.go) is the vocabulary; the enum in the schema has to
// list the same values, and TestJobStatusEnumMatchesStatusOrder fails when
// they differ. The functions live in this package, rather than in graph,
// because this is where statusOrder is and graph already imports services.
// KnownStatus reports whether s is exactly one of the tracked statuses. No
// trimming or case folding: see NormalizeStatus for the forgiving version the
// email pipeline and the capture endpoint use on values that did not come
// through GraphQL.
func KnownStatus(s string) bool {
_, ok := statusOrder[s]
return ok
}
// MarshalJobStatus writes a stored status to a GraphQL response.
//
// It is deliberately lenient, where the input side is strict. The column is
// older than the enum, so a row can hold a status outside the vocabulary: the
// tracker's early Title Case values ("Rejected"), or something written by
// hand. A generated enum type would fail to serialise such a row, and because
// JobApplication.status is non-null that one error would null out the whole
// jobApplications list — one stale row hiding every application. So:
//
// - a value that is in the vocabulary once trimmed and lowered is emitted
// in that canonical form, which also means an edit form sends back
// something the input side accepts;
// - anything else is emitted exactly as stored. That is not a legal
// JobStatus, strictly, but the response is JSON and the tracker page
// shows an unlisted status as-is so that it can be corrected, which is
// more use than an error or a made-up substitute.
//
// The value is written with gqlgen's own String marshaller, so it is the same
// quoted JSON string the field produced when it was declared String.
func MarshalJobStatus(s string) graphql.Marshaler {
if canonical := strings.ToLower(strings.TrimSpace(s)); KnownStatus(canonical) {
s = canonical
}
return graphql.MarshalString(s)
}
// UnmarshalJobStatus reads a status from a mutation's input, and is where
// drift is refused: only the exact lowercase values are accepted, so nothing
// outside the vocabulary can be written through GraphQL.
//
// The value arrives as a string whether the client sent a JSON string
// variable ("applied", which is what the tracker page does) or wrote the enum
// literal in the query document (applied).
func UnmarshalJobStatus(v any) (string, error) {
s, ok := v.(string)
if !ok {
return "", fmt.Errorf("status must be a string")
}
if !KnownStatus(s) {
return "", fmt.Errorf("%q is not a valid JobStatus", s)
}
return s, nil
}