Add authenticated POST /api/v1/jobs to enqueue registered job kinds
Addresses feature-review finding F1 on Feature 04 PR #30: a job can now be enqueued over the API and its progressive result read back. - jobs: Runner.Enqueue(kind, payload) rejects an unregistered kind with ErrUnknownKind and a payload that does not decode into the kind's payload type with ErrInvalidPayload, storing no job. Kind.Enqueue shares the same insert path. - server: POST /api/v1/jobs, inside the session- and CSRF-guarded /api/v1 group, takes {kind, payload?} and returns 202 {id}; unknown kind, bad payload or malformed body return 400 with the standard error shape. - Tests drive POST -> GET partial result (handler held on a channel) -> GET succeeded through the production router, plus 400/401/403 cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ type RouteMounter interface {
|
||||
// only from a peer in trusted (see resolveOrigin). version is reported by
|
||||
// GET /health; auth mounts the /auth routes; sessions guards /api/v1 and
|
||||
// /media; settings serves /api/v1/settings/household; runner serves
|
||||
// /api/v1/jobs/{id}; assets is the web build
|
||||
// POST /api/v1/jobs and GET /api/v1/jobs/{id}; assets is the web build
|
||||
// served for every other GET. /health, /auth and the web build are public.
|
||||
// Requests to /api/v1 other than GET also need the session's CSRF token in CSRFHeader.
|
||||
func NewRouter(logger *slog.Logger, version string, trusted forwarded.Trusted, auth RouteMounter, sessions SessionLookup, settings *household.SettingsService, runner *jobs.Runner, assets fs.FS) (http.Handler, error) {
|
||||
@@ -68,6 +68,7 @@ func NewRouter(logger *slog.Logger, version string, trusted forwarded.Trusted, a
|
||||
apiV1.Get("/me", me(logger))
|
||||
apiV1.Get("/settings/household", getHouseholdSettings(logger, settings))
|
||||
apiV1.Patch("/settings/household", patchHouseholdSettings(logger, settings))
|
||||
apiV1.Post("/jobs", postJob(logger, runner))
|
||||
apiV1.Get("/jobs/{id}", getJob(logger, runner))
|
||||
r.Route("/api", func(r chi.Router) {
|
||||
r.MethodNotAllowed(methodNotAllowed)
|
||||
|
||||
Reference in New Issue
Block a user