Files
stpweb/backend/graph/job_application.resolvers.go
adamfandClaude Opus 5.5 71344a1f8d Declare GraphQL auth in the schema and drop the Go Claude client
Authorisation: @admin and @signedIn schema directives replace the 25
hand-copied resolver checks. A test fails if a mutation has neither and
is not on the public allow-list, so a new mutation cannot ship unguarded.

IDs: uint model IDs bind through graphql.UintID, removing the ten
int(obj.ID) resolvers.

Job status is a GraphQL enum, tied to services.statusOrder by a test.
Input is strict, so the mutations no longer coerce an unknown status to
"applied"; output is lenient so one legacy row cannot fail the list.

deleteJobApplication and deleteJobAppReference now error on a missing id
like the other deletes.

The rowing reader, the job extractor and now the email classifier reach
the Python service through one services.CallPython helper. The email
pipeline's prompt and fence stripping moved to Python, and
anthropic-sdk-go is gone from go.mod.

Fix the auth test fixture, whose 11-byte secret had been panicking the
services test package since InitAuth began requiring 32 bytes. Add a
test that keeps the python service's compose environment list in step
with the env registry.

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

141 lines
5.1 KiB
Go

package graph
// This file will be automatically regenerated based on the schema, any resolver
// implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.95
import (
"context"
"fmt"
"strings"
"adam-french.co.uk/backend/graph/model"
"adam-french.co.uk/backend/models"
)
// CreateJobApplication is the resolver for the createJobApplication field.
func (r *mutationResolver) CreateJobApplication(ctx context.Context, input model.CreateJobApplicationInput) (*models.JobApplication, error) {
// String! is non-null but not non-empty, and the columns are only
// `not null`, so "" stores happily and then never matches the email
// pipeline's LOWER(company) lookup — an orphan row no sync can advance.
jobTitle := strings.TrimSpace(input.JobTitle)
company := strings.TrimSpace(input.Company)
if jobTitle == "" || company == "" {
return nil, fmt.Errorf("jobTitle and company are required")
}
// input.Status is already one of the JobStatus values: the enum's
// unmarshaller (services.UnmarshalJobStatus) refused anything else before
// this resolver was reached, so it is stored as it came.
app := models.JobApplication{
JobTitle: jobTitle,
Company: company,
Location: input.Location,
URL: input.URL,
Status: input.Status,
Notes: input.Notes,
AppliedAt: input.AppliedAt,
Description: input.Description,
}
if err := r.Store.DB.Create(&app).Error; err != nil {
return nil, err
}
return &app, nil
}
// UpdateJobApplication is the resolver for the updateJobApplication field.
func (r *mutationResolver) UpdateJobApplication(ctx context.Context, id int, input model.UpdateJobApplicationInput) (*models.JobApplication, error) {
// Partial update: every input field is a pointer so that "not supplied"
// is distinguishable from "set to empty". A nil field is left untouched.
// An explicit "" on a nullable column does clear it — that is how the UI
// empties a wrong URL or stale notes — but the same value on a required
// column is rejected rather than blanking a live row.
var app models.JobApplication
if err := r.Store.DB.First(&app, id).Error; err != nil {
return nil, err
}
if input.JobTitle != nil {
if strings.TrimSpace(*input.JobTitle) == "" {
return nil, fmt.Errorf("jobTitle cannot be empty")
}
app.JobTitle = strings.TrimSpace(*input.JobTitle)
}
if input.Company != nil {
if strings.TrimSpace(*input.Company) == "" {
return nil, fmt.Errorf("company cannot be empty")
}
app.Company = strings.TrimSpace(*input.Company)
}
if input.Location != nil {
app.Location = input.Location
}
if input.URL != nil {
app.URL = input.URL
}
if input.Status != nil {
app.Status = *input.Status
}
if input.Notes != nil {
app.Notes = input.Notes
}
if input.AppliedAt != nil {
app.AppliedAt = input.AppliedAt
}
if input.Description != nil {
app.Description = input.Description
}
if err := r.Store.DB.Save(&app).Error; err != nil {
return nil, err
}
return &app, nil
}
// DeleteJobApplication is the resolver for the deleteJobApplication field.
func (r *mutationResolver) DeleteJobApplication(ctx context.Context, id int) (bool, error) {
// Loaded first so a missing id is an error, as it is for the deletes that
// return the row (deletePost, deletePlace, deleteBookmark). Deleting by
// id alone reports success whether or not anything matched, which told
// the tracker a row was gone when it had never existed. The return type
// stays Boolean! for the front end's sake, so the only value is true.
//
// Soft delete: the row is kept, which is what lets the email pipeline see
// that an application was deleted and not re-create it.
var app models.JobApplication
if err := r.Store.DB.First(&app, id).Error; err != nil {
return false, err
}
if err := r.Store.DB.Delete(&app).Error; err != nil {
return false, err
}
return true, nil
}
// JobApplications is the resolver for the jobApplications field.
func (r *queryResolver) JobApplications(ctx context.Context) ([]*models.JobApplication, error) {
// Admin-only even though it is a query (@admin in the schema): job
// applications are private.
//
// A row whose stored status is outside the JobStatus enum does not fail
// this list: services.MarshalJobStatus passes it through.
//
// Find can populate a slice of pointers directly, avoiding the
// copy-to-pointers loop the other list resolvers need.
var apps []*models.JobApplication
// id is the tie-break: one sync loop inserts several rows inside the same
// timestamp, and Postgres gives no stable order for equal sort keys, so
// without it the list can reshuffle between two identical page loads.
if err := r.Store.DB.Order("created_at desc, id desc").Find(&apps).Error; err != nil {
return nil, err
}
return apps, nil
}
// JobApplication is the resolver for the jobApplication field.
func (r *queryResolver) JobApplication(ctx context.Context, id int) (*models.JobApplication, error) {
var app models.JobApplication
if err := r.Store.DB.First(&app, id).Error; err != nil {
return nil, err
}
return &app, nil
}