Delete the old job code now that the tracker runs on its own
The job tracker has run from its own image at /jobs/ since 931b02c, so its
old copy here goes: the GraphQL schema, resolvers and models for
applications, references, sources, leads and the search profile; the
capture and email handlers and services; the Python posting reader, lead
scorer and email classifier; the Vue pages, stores and the capture-token
card on the Environment tab; and the userscript (nginx already redirects
its old URL to /jobs/).
The six old tables stay in the stp database: AutoMigrate never drops
anything, and dropping them is a manual step. The env variables stay in
the registry, where they already belong to the jobs service.
Docs (CLAUDE.md, DEPLOYMENT.md and the three READMEs) now describe the
site without the tracker, and DEPLOYMENT.md lists the jobs service and
./jobs-data.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -187,17 +187,9 @@ func TestSignedInMutationsArePinned(t *testing.T) {
|
||||
// `spotifyNeedsReauth` is false for non-admins.
|
||||
func TestGuardedQueriesArePinned(t *testing.T) {
|
||||
want := map[string]string{
|
||||
"users": "admin",
|
||||
"user": "admin",
|
||||
"jobApplications": "admin",
|
||||
"jobApplication": "admin",
|
||||
"jobAppReferences": "admin",
|
||||
"jobSources": "admin",
|
||||
"jobLeads": "admin",
|
||||
"jobLead": "admin",
|
||||
"jobSearchProfile": "admin",
|
||||
"jobLeadSyncStatus": "admin",
|
||||
"places": "signedIn",
|
||||
"users": "admin",
|
||||
"user": "admin",
|
||||
"places": "signedIn",
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, field := range schemaUnderTest().Query.Fields {
|
||||
@@ -283,8 +275,8 @@ func TestGuardedFieldsRefuseOverTheWire(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"anonymous admin query", context.Background(), `{ users { id } }`, "admin access required"},
|
||||
{"non-admin admin query", withClaims(2, false), `{ jobApplications { id } }`, "admin access required"},
|
||||
{"anonymous admin mutation", context.Background(), `mutation { deleteJobApplication(id: 1) }`, "admin access required"},
|
||||
{"non-admin admin query", withClaims(2, false), `{ users { id } }`, "admin access required"},
|
||||
{"anonymous admin mutation", context.Background(), `mutation { deleteBookmark(id: 1) { id } }`, "admin access required"},
|
||||
{"non-admin admin mutation", withClaims(2, false), `mutation { deleteUser(id: 1) { id } }`, "admin access required"},
|
||||
{"anonymous signed-in query", context.Background(), `{ places { id } }`, "authentication required"},
|
||||
{"anonymous signed-in mutation", context.Background(), `mutation { deletePlace(id: 1) { id } }`, "authentication required"},
|
||||
@@ -301,40 +293,6 @@ func TestGuardedFieldsRefuseOverTheWire(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The JobStatus enum over the wire, from the side the tracker page uses it:
|
||||
// status sent as a JSON string variable. A value in the vocabulary reaches the
|
||||
// resolver (shown by the resolver's own validation error, which comes before
|
||||
// any database access); one outside it is refused before the resolver runs.
|
||||
func TestJobStatusInputOverTheWire(t *testing.T) {
|
||||
const mutation = `mutation ($input: CreateJobApplicationInput!) { createJobApplication(input: $input) { id status } }`
|
||||
admin := withClaims(1, true)
|
||||
input := func(status any) map[string]any {
|
||||
// A blank title makes the resolver return early, so no test here
|
||||
// needs a database.
|
||||
return map[string]any{"input": map[string]any{"jobTitle": " ", "company": "Acme", "status": status}}
|
||||
}
|
||||
|
||||
for _, status := range []string{"saved", "applied", "screening", "assessment", "interviewing", "offer", "rejected", "withdrawn"} {
|
||||
got := execute(t, admin, mutation, input(status))
|
||||
if !slices.Equal(got, []string{"jobTitle and company are required"}) {
|
||||
t.Errorf("status %q: errors = %q, want it accepted and the resolver reached", status, got)
|
||||
}
|
||||
}
|
||||
|
||||
for _, status := range []any{"hired", "Applied", "", " applied", 3} {
|
||||
got := execute(t, admin, mutation, input(status))
|
||||
if len(got) != 1 || got[0] == "jobTitle and company are required" {
|
||||
t.Errorf("status %#v: errors = %q, want it refused before the resolver", status, got)
|
||||
}
|
||||
}
|
||||
|
||||
// The guard still comes first: an anonymous caller learns nothing about
|
||||
// the vocabulary from a valid input.
|
||||
if got := execute(t, context.Background(), mutation, input("applied")); !slices.Equal(got, []string{"admin access required"}) {
|
||||
t.Errorf("anonymous: errors = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// IDs: the wire form must be what it was when every type had a hand-written
|
||||
// resolver returning int. Both marshallers write a quoted decimal string and
|
||||
// both read a string or a number.
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
// needed for it. A field resolver is only written where the Go type has
|
||||
// no binding (Message.authorId and Rowing's time/distance are unsigned in
|
||||
// Go and Int in the schema).
|
||||
// - The JobStatus enum is bound to a custom marshaller in
|
||||
// services/job_status.go rather than a generated type; see that file.
|
||||
// - Resolvers reach the database and the third-party caches through
|
||||
// Resolver.Store, the same handlers.Store the REST endpoints use.
|
||||
// - context.go and middleware.go carry the caller's identity from Gin into
|
||||
@@ -36,8 +34,8 @@
|
||||
//
|
||||
// The rule of thumb in this schema is that queries are public and mutations
|
||||
// are @admin, with these exceptions: login, logout and refreshToken are
|
||||
// public; the places mutations and query are @signedIn; and the users, job
|
||||
// application and job reference queries are @admin (they are private data).
|
||||
// public; the places mutations and query are @signedIn; and the users
|
||||
// queries are @admin (they are private data).
|
||||
// directives_test.go holds that list and fails when the schema departs from
|
||||
// it — in particular when a mutation is added with no directive.
|
||||
//
|
||||
|
||||
+17
-5073
File diff suppressed because it is too large
Load Diff
@@ -1,78 +0,0 @@
|
||||
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"
|
||||
|
||||
"adam-french.co.uk/backend/graph/model"
|
||||
"adam-french.co.uk/backend/models"
|
||||
)
|
||||
|
||||
// CreateJobAppReference is the resolver for the createJobAppReference field.
|
||||
func (r *mutationResolver) CreateJobAppReference(ctx context.Context, input model.CreateJobAppReferenceInput) (*models.JobAppReference, error) {
|
||||
ref := models.JobAppReference{
|
||||
Category: input.Category,
|
||||
Label: input.Label,
|
||||
Value: input.Value,
|
||||
}
|
||||
if input.SortOrder != nil {
|
||||
ref.SortOrder = *input.SortOrder
|
||||
}
|
||||
if err := r.Store.DB.Create(&ref).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ref, nil
|
||||
}
|
||||
|
||||
// UpdateJobAppReference is the resolver for the updateJobAppReference field.
|
||||
func (r *mutationResolver) UpdateJobAppReference(ctx context.Context, id int, input model.UpdateJobAppReferenceInput) (*models.JobAppReference, error) {
|
||||
var ref models.JobAppReference
|
||||
if err := r.Store.DB.First(&ref, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Category != nil {
|
||||
ref.Category = *input.Category
|
||||
}
|
||||
if input.Label != nil {
|
||||
ref.Label = *input.Label
|
||||
}
|
||||
if input.Value != nil {
|
||||
ref.Value = *input.Value
|
||||
}
|
||||
if input.SortOrder != nil {
|
||||
ref.SortOrder = *input.SortOrder
|
||||
}
|
||||
if err := r.Store.DB.Save(&ref).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ref, nil
|
||||
}
|
||||
|
||||
// DeleteJobAppReference is the resolver for the deleteJobAppReference field.
|
||||
func (r *mutationResolver) DeleteJobAppReference(ctx context.Context, id int) (bool, error) {
|
||||
// Loaded first so a missing id is an error rather than a `true` that
|
||||
// deleted nothing; see DeleteJobApplication.
|
||||
var ref models.JobAppReference
|
||||
if err := r.Store.DB.First(&ref, id).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := r.Store.DB.Delete(&ref).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// JobAppReferences is the resolver for the jobAppReferences field.
|
||||
func (r *queryResolver) JobAppReferences(ctx context.Context) ([]*models.JobAppReference, error) {
|
||||
var refs []*models.JobAppReference
|
||||
// created_at is the final tie-break so entries sharing a sort_order (the
|
||||
// default 0) keep a stable, insertion-ordered sequence.
|
||||
if err := r.Store.DB.Order("category ASC, sort_order ASC, created_at ASC").Find(&refs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return refs, nil
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
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"
|
||||
"time"
|
||||
|
||||
"adam-french.co.uk/backend/graph/model"
|
||||
"adam-french.co.uk/backend/models"
|
||||
"adam-french.co.uk/backend/services"
|
||||
)
|
||||
|
||||
// CreateJobSource is the resolver for the createJobSource field.
|
||||
func (r *mutationResolver) CreateJobSource(ctx context.Context, input model.CreateJobSourceInput) (*models.JobSource, error) {
|
||||
src := models.JobSource{Kind: input.Kind, Label: input.Label, Enabled: true}
|
||||
if input.Token != nil {
|
||||
src.Token = *input.Token
|
||||
}
|
||||
if input.Query != nil {
|
||||
src.Query = *input.Query
|
||||
}
|
||||
if input.Location != nil {
|
||||
src.Location = *input.Location
|
||||
}
|
||||
if input.Enabled != nil {
|
||||
src.Enabled = *input.Enabled
|
||||
}
|
||||
if err := services.ValidateJobSource(&src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := r.Store.DB.Create(&src).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
// UpdateJobSource is the resolver for the updateJobSource field.
|
||||
func (r *mutationResolver) UpdateJobSource(ctx context.Context, id int, input model.UpdateJobSourceInput) (*models.JobSource, error) {
|
||||
// Partial update, as in UpdateJobApplication: a nil field is untouched.
|
||||
// The merged row is validated as a whole, because whether a token or a
|
||||
// query is required depends on the kind, which may itself be changing.
|
||||
var src models.JobSource
|
||||
if err := r.Store.DB.First(&src, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Kind != nil {
|
||||
src.Kind = *input.Kind
|
||||
}
|
||||
if input.Label != nil {
|
||||
src.Label = *input.Label
|
||||
}
|
||||
if input.Token != nil {
|
||||
src.Token = *input.Token
|
||||
}
|
||||
if input.Query != nil {
|
||||
src.Query = *input.Query
|
||||
}
|
||||
if input.Location != nil {
|
||||
src.Location = *input.Location
|
||||
}
|
||||
if input.Enabled != nil {
|
||||
src.Enabled = *input.Enabled
|
||||
}
|
||||
if err := services.ValidateJobSource(&src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Named columns rather than Save: the fetcher writes last_fetched_at,
|
||||
// last_count and last_error on this row during a run, and saving the
|
||||
// whole struct loaded above would put stale values back over them.
|
||||
if err := r.Store.DB.Model(&src).
|
||||
Select("Kind", "Label", "Token", "Query", "Location", "Enabled").
|
||||
Updates(&src).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
// DeleteJobSource is the resolver for the deleteJobSource field.
|
||||
func (r *mutationResolver) DeleteJobSource(ctx context.Context, id int) (bool, error) {
|
||||
// Loaded first so a missing id is an error; see DeleteJobApplication.
|
||||
// The source's leads are deliberately left alone: they are still real
|
||||
// postings, and deleting them would let a re-added source file every one
|
||||
// of them again, dismissed ones included.
|
||||
var src models.JobSource
|
||||
if err := r.Store.DB.First(&src, id).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := r.Store.DB.Delete(&src).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DismissJobLead is the resolver for the dismissJobLead field.
|
||||
func (r *mutationResolver) DismissJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return r.setLeadState(id, services.LeadNew, services.LeadDismissed)
|
||||
}
|
||||
|
||||
// RestoreJobLead is the resolver for the restoreJobLead field.
|
||||
func (r *mutationResolver) RestoreJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return r.setLeadState(id, services.LeadDismissed, services.LeadNew)
|
||||
}
|
||||
|
||||
// PromoteJobLead is the resolver for the promoteJobLead field.
|
||||
func (r *mutationResolver) PromoteJobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
return services.PromoteJobLead(r.Store.DB, uint(id), time.Now())
|
||||
}
|
||||
|
||||
// UpdateJobSearchProfile is the resolver for the updateJobSearchProfile field.
|
||||
func (r *mutationResolver) UpdateJobSearchProfile(ctx context.Context, input model.UpdateJobSearchProfileInput) (*models.JobSearchProfile, error) {
|
||||
profile, err := services.LoadJobSearchProfile(r.Store.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Profile != nil {
|
||||
profile.Profile = *input.Profile
|
||||
}
|
||||
if input.IncludeKeywords != nil {
|
||||
profile.IncludeKeywords = strings.TrimSpace(*input.IncludeKeywords)
|
||||
}
|
||||
if input.ExcludeKeywords != nil {
|
||||
profile.ExcludeKeywords = strings.TrimSpace(*input.ExcludeKeywords)
|
||||
}
|
||||
if input.Locations != nil {
|
||||
profile.Locations = strings.TrimSpace(*input.Locations)
|
||||
}
|
||||
if input.MinScore != nil {
|
||||
profile.MinScore = *input.MinScore
|
||||
}
|
||||
if err := services.SaveJobSearchProfile(r.Store.DB, profile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
// RunJobLeadSync is the resolver for the runJobLeadSync field.
|
||||
func (r *mutationResolver) RunJobLeadSync(ctx context.Context) (bool, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return false, fmt.Errorf("job leads are not configured")
|
||||
}
|
||||
return r.Store.JobLeads.RunInBackground(services.LeadJobSync), nil
|
||||
}
|
||||
|
||||
// ScoreJobLeads is the resolver for the scoreJobLeads field.
|
||||
func (r *mutationResolver) ScoreJobLeads(ctx context.Context) (bool, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return false, fmt.Errorf("job leads are not configured")
|
||||
}
|
||||
return r.Store.JobLeads.RunInBackground(services.LeadJobScore), nil
|
||||
}
|
||||
|
||||
// RescoreJobLeads is the resolver for the rescoreJobLeads field.
|
||||
func (r *mutationResolver) RescoreJobLeads(ctx context.Context) (bool, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return false, fmt.Errorf("job leads are not configured")
|
||||
}
|
||||
return r.Store.JobLeads.RunInBackground(services.LeadJobRescore), nil
|
||||
}
|
||||
|
||||
// JobSources is the resolver for the jobSources field.
|
||||
func (r *queryResolver) JobSources(ctx context.Context) ([]*models.JobSource, error) {
|
||||
var sources []*models.JobSource
|
||||
if err := r.Store.DB.Order("label ASC, id ASC").Find(&sources).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
// JobLeads is the resolver for the jobLeads field.
|
||||
func (r *queryResolver) JobLeads(ctx context.Context, state *string, includeUnmatched *bool) ([]*models.JobLead, error) {
|
||||
// Omit, not Select: every column but the description, which is tens of
|
||||
// kilobytes a row and is fetched one lead at a time through jobLead. A
|
||||
// client that asks for description here gets "".
|
||||
query := r.Store.DB.Omit("description")
|
||||
if state != nil {
|
||||
query = query.Where("state = ?", *state)
|
||||
}
|
||||
if includeUnmatched == nil || !*includeUnmatched {
|
||||
// A promoted or dismissed lead is shown whatever the filter now says
|
||||
// about it; `matched` only decides what the inbox offers.
|
||||
query = query.Where("(matched = ? OR state <> ?)", true, services.LeadNew)
|
||||
}
|
||||
var leads []*models.JobLead
|
||||
// Best first, unscored after scored, newest first within a score. The
|
||||
// limit is a backstop for includeUnmatched on a database holding several
|
||||
// whole boards.
|
||||
if err := query.Order("score DESC NULLS LAST, created_at DESC, id DESC").Limit(2000).Find(&leads).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return leads, nil
|
||||
}
|
||||
|
||||
// JobLead is the resolver for the jobLead field.
|
||||
func (r *queryResolver) JobLead(ctx context.Context, id int) (*models.JobLead, error) {
|
||||
var lead models.JobLead
|
||||
if err := r.Store.DB.First(&lead, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lead, nil
|
||||
}
|
||||
|
||||
// JobSearchProfile is the resolver for the jobSearchProfile field.
|
||||
func (r *queryResolver) JobSearchProfile(ctx context.Context) (*models.JobSearchProfile, error) {
|
||||
return services.LoadJobSearchProfile(r.Store.DB)
|
||||
}
|
||||
|
||||
// JobLeadSyncStatus is the resolver for the jobLeadSyncStatus field.
|
||||
func (r *queryResolver) JobLeadSyncStatus(ctx context.Context) (*model.JobLeadSyncStatus, error) {
|
||||
if r.Store.JobLeads == nil {
|
||||
return &model.JobLeadSyncStatus{LastError: "job leads are not configured"}, nil
|
||||
}
|
||||
status := r.Store.JobLeads.Status()
|
||||
return &model.JobLeadSyncStatus{Running: status.Running, LastRunAt: status.LastRunAt, LastError: status.LastError}, nil
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"adam-french.co.uk/backend/models"
|
||||
)
|
||||
|
||||
// setLeadState moves a lead from one state to another and returns it. It
|
||||
// lives here, not in job_lead.resolvers.go, because gqlgen moves anything in
|
||||
// a resolvers file that is not a resolver to the bottom on regeneration.
|
||||
//
|
||||
// The move is refused unless the lead is in `from`, which is what stops a
|
||||
// promoted lead being dismissed or restored: its application exists, and
|
||||
// flipping the lead would only make the inbox disagree with the tracker.
|
||||
func (r *mutationResolver) setLeadState(id int, from, to string) (*models.JobLead, error) {
|
||||
var lead models.JobLead
|
||||
if err := r.Store.DB.First(&lead, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if lead.State == to {
|
||||
return &lead, nil
|
||||
}
|
||||
if lead.State != from {
|
||||
return nil, fmt.Errorf("a %s lead cannot be made %s", lead.State, to)
|
||||
}
|
||||
if err := r.Store.DB.Model(&lead).Update("state", to).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lead, nil
|
||||
}
|
||||
@@ -30,33 +30,6 @@ type CreateFavoriteInput struct {
|
||||
Link *string `json:"link,omitempty"`
|
||||
}
|
||||
|
||||
type CreateJobAppReferenceInput struct {
|
||||
Category string `json:"category"`
|
||||
Label string `json:"label"`
|
||||
Value string `json:"value"`
|
||||
SortOrder *int `json:"sortOrder,omitempty"`
|
||||
}
|
||||
|
||||
type CreateJobApplicationInput struct {
|
||||
JobTitle string `json:"jobTitle"`
|
||||
Company string `json:"company"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
URL *string `json:"url,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Notes *string `json:"notes,omitempty"`
|
||||
AppliedAt *time.Time `json:"appliedAt,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type CreateJobSourceInput struct {
|
||||
Kind string `json:"kind"`
|
||||
Label string `json:"label"`
|
||||
Token *string `json:"token,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type CreatePlaceInput struct {
|
||||
Title string `json:"title"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
@@ -87,12 +60,6 @@ type GiteaFeedItem struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type JobLeadSyncStatus struct {
|
||||
Running bool `json:"running"`
|
||||
LastRunAt *time.Time `json:"lastRunAt,omitempty"`
|
||||
LastError string `json:"lastError"`
|
||||
}
|
||||
|
||||
type LoginInput struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -146,41 +113,6 @@ type SteamStatus struct {
|
||||
RecentGames []*SteamGame `json:"recentGames"`
|
||||
}
|
||||
|
||||
type UpdateJobAppReferenceInput struct {
|
||||
Category *string `json:"category,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Value *string `json:"value,omitempty"`
|
||||
SortOrder *int `json:"sortOrder,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateJobApplicationInput struct {
|
||||
JobTitle *string `json:"jobTitle,omitempty"`
|
||||
Company *string `json:"company,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
URL *string `json:"url,omitempty"`
|
||||
Status *string `json:"status,omitempty"`
|
||||
Notes *string `json:"notes,omitempty"`
|
||||
AppliedAt *time.Time `json:"appliedAt,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateJobSearchProfileInput struct {
|
||||
Profile *string `json:"profile,omitempty"`
|
||||
IncludeKeywords *string `json:"includeKeywords,omitempty"`
|
||||
ExcludeKeywords *string `json:"excludeKeywords,omitempty"`
|
||||
Locations *string `json:"locations,omitempty"`
|
||||
MinScore *int `json:"minScore,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateJobSourceInput struct {
|
||||
Kind *string `json:"kind,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Token *string `json:"token,omitempty"`
|
||||
Query *string `json:"query,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
Enabled *bool `json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type UpdatePlaceInput struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
Location *string `json:"location,omitempty"`
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
# Reusable snippets for filling in application forms. Private, like the
|
||||
# applications themselves, so the query is @admin as well as the mutations.
|
||||
|
||||
type JobAppReference {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
updatedAt: Time!
|
||||
category: String!
|
||||
label: String!
|
||||
value: String!
|
||||
sortOrder: Int!
|
||||
}
|
||||
|
||||
input CreateJobAppReferenceInput {
|
||||
category: String!
|
||||
label: String!
|
||||
value: String!
|
||||
sortOrder: Int
|
||||
}
|
||||
|
||||
input UpdateJobAppReferenceInput {
|
||||
category: String
|
||||
label: String
|
||||
value: String
|
||||
sortOrder: Int
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobAppReferences: [JobAppReference!]! @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobAppReference(input: CreateJobAppReferenceInput!): JobAppReference! @admin
|
||||
updateJobAppReference(id: ID!, input: UpdateJobAppReferenceInput!): JobAppReference! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true.
|
||||
deleteJobAppReference(id: ID!): Boolean! @admin
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
# Job application tracker. Rows come from these mutations, automatically from
|
||||
# the email sync pipeline (backend/services/email_sync.go), from the browser
|
||||
# capture userscript (backend/handlers/handle_job_capture.go), or from
|
||||
# promoting a lead (job_lead.graphql). These are private data, so the queries
|
||||
# here are @admin as well as the mutations.
|
||||
#
|
||||
# description is the captured posting text. It can run to tens of kilobytes,
|
||||
# so the tracker's list query leaves it out and asks for it per row.
|
||||
|
||||
# The lifecycle of an application, in the order the email pipeline and the
|
||||
# capture endpoint are allowed to advance it. The values are lowercase on
|
||||
# purpose: they are exactly the strings stored in the status column and ranked
|
||||
# in services.statusOrder (backend/services/email_sync.go), and a test there
|
||||
# fails if this list and that map ever differ. Adding a status means adding
|
||||
# it in both places, and to the tracker page and the capture userscript.
|
||||
#
|
||||
# It is bound to a custom marshaller (services/job_status.go, via gqlgen.yml)
|
||||
# rather than a generated Go type: input is strict, so a mutation carrying a
|
||||
# status outside this list is refused, while output passes a legacy stored
|
||||
# value through so one old row cannot fail the whole jobApplications query.
|
||||
#
|
||||
# On the wire it is still a JSON string ("applied"), as it was when the field
|
||||
# was a String, both in variables and in responses.
|
||||
enum JobStatus {
|
||||
saved
|
||||
applied
|
||||
screening
|
||||
assessment
|
||||
interviewing
|
||||
offer
|
||||
rejected
|
||||
withdrawn
|
||||
}
|
||||
|
||||
type JobApplication {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
updatedAt: Time!
|
||||
jobTitle: String!
|
||||
company: String!
|
||||
location: String
|
||||
url: String
|
||||
status: JobStatus!
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
}
|
||||
|
||||
input CreateJobApplicationInput {
|
||||
jobTitle: String!
|
||||
company: String!
|
||||
location: String
|
||||
url: String
|
||||
status: JobStatus!
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
}
|
||||
|
||||
input UpdateJobApplicationInput {
|
||||
jobTitle: String
|
||||
company: String
|
||||
location: String
|
||||
url: String
|
||||
status: JobStatus
|
||||
notes: String
|
||||
appliedAt: Time
|
||||
description: String
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobApplications: [JobApplication!]! @admin
|
||||
jobApplication(id: ID!): JobApplication @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobApplication(input: CreateJobApplicationInput!): JobApplication! @admin
|
||||
updateJobApplication(id: ID!, input: UpdateJobApplicationInput!): JobApplication! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true.
|
||||
deleteJobApplication(id: ID!): Boolean! @admin
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
# Job leads: postings found automatically, as opposed to applications being
|
||||
# tracked (job_application.graphql). The fetcher in
|
||||
# backend/services/job_leads.go polls each JobSource, files what it finds as
|
||||
# JobLead rows and has Claude score them against the JobSearchProfile. A lead
|
||||
# reaches the tracker only when it is promoted from the leads page.
|
||||
#
|
||||
# All of it is private, so every field here is @admin, queries included.
|
||||
|
||||
# One place to poll. `kind` is one of greenhouse, lever, ashby (a company's
|
||||
# board: `token` is its slug and `label` the company name) or adzuna, reed (a
|
||||
# keyword search: `query` and `location`, with `label` only a display name).
|
||||
# It is a String rather than an enum because the resolver validates it and
|
||||
# the list is the fetcher's to extend (services/job_sources.go).
|
||||
#
|
||||
# The last* fields are written by the fetcher, never by a mutation.
|
||||
type JobSource {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
updatedAt: Time!
|
||||
kind: String!
|
||||
label: String!
|
||||
token: String!
|
||||
query: String!
|
||||
location: String!
|
||||
enabled: Boolean!
|
||||
lastFetchedAt: Time
|
||||
lastCount: Int!
|
||||
lastError: String!
|
||||
}
|
||||
|
||||
input CreateJobSourceInput {
|
||||
kind: String!
|
||||
label: String!
|
||||
token: String
|
||||
query: String
|
||||
location: String
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
input UpdateJobSourceInput {
|
||||
kind: String
|
||||
label: String
|
||||
token: String
|
||||
query: String
|
||||
location: String
|
||||
enabled: Boolean
|
||||
}
|
||||
|
||||
# description is the posting's full text, tens of kilobytes on some boards,
|
||||
# so the list query on the leads page leaves it out and asks per row — the
|
||||
# same arrangement as JobApplication.description.
|
||||
#
|
||||
# state is new, dismissed or promoted. score (0-100) and scoreReasons are
|
||||
# null until Claude has scored the lead, which only happens to matched ones.
|
||||
type JobLead {
|
||||
id: ID!
|
||||
createdAt: Time!
|
||||
sourceKind: String!
|
||||
jobTitle: String!
|
||||
company: String!
|
||||
location: String!
|
||||
url: String!
|
||||
description: String!
|
||||
postedAt: Time
|
||||
lastSeenAt: Time!
|
||||
matched: Boolean!
|
||||
state: String!
|
||||
score: Int
|
||||
scoreReasons: String
|
||||
scoredAt: Time
|
||||
jobAppId: ID
|
||||
}
|
||||
|
||||
# The single row a lead is judged against. profile is free text sent to
|
||||
# Claude with each posting; the three keyword lists hold one entry per line
|
||||
# and drive the pre-filter; minScore is the inbox's display threshold.
|
||||
type JobSearchProfile {
|
||||
updatedAt: Time!
|
||||
profile: String!
|
||||
includeKeywords: String!
|
||||
excludeKeywords: String!
|
||||
locations: String!
|
||||
minScore: Int!
|
||||
}
|
||||
|
||||
input UpdateJobSearchProfileInput {
|
||||
profile: String
|
||||
includeKeywords: String
|
||||
excludeKeywords: String
|
||||
locations: String
|
||||
minScore: Int
|
||||
}
|
||||
|
||||
# lastRunAt and lastError describe the most recent run in this backend
|
||||
# process; both reset when it restarts.
|
||||
type JobLeadSyncStatus {
|
||||
running: Boolean!
|
||||
lastRunAt: Time
|
||||
lastError: String!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
jobSources: [JobSource!]! @admin
|
||||
# state filters to one of new, dismissed, promoted; omitted returns all.
|
||||
# Leads that failed the pre-filter are left out unless includeUnmatched.
|
||||
jobLeads(state: String, includeUnmatched: Boolean): [JobLead!]! @admin
|
||||
jobLead(id: ID!): JobLead @admin
|
||||
jobSearchProfile: JobSearchProfile! @admin
|
||||
jobLeadSyncStatus: JobLeadSyncStatus! @admin
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
createJobSource(input: CreateJobSourceInput!): JobSource! @admin
|
||||
updateJobSource(id: ID!, input: UpdateJobSourceInput!): JobSource! @admin
|
||||
# Errors on an id that does not exist, like the other deletes; the Boolean
|
||||
# is only ever true. The source's leads are kept.
|
||||
deleteJobSource(id: ID!): Boolean! @admin
|
||||
|
||||
dismissJobLead(id: ID!): JobLead! @admin
|
||||
# Puts a dismissed lead back in the inbox. A promoted lead cannot be
|
||||
# restored: its application exists, and is managed on the tracker.
|
||||
restoreJobLead(id: ID!): JobLead! @admin
|
||||
# Adds the lead to the tracker as a saved application — or, if the posting
|
||||
# is already tracked, links to that row instead of making a second — and
|
||||
# returns the lead, now promoted, with jobAppId set.
|
||||
promoteJobLead(id: ID!): JobLead! @admin
|
||||
|
||||
updateJobSearchProfile(input: UpdateJobSearchProfileInput!): JobSearchProfile! @admin
|
||||
|
||||
# Starts a fetch-and-score run in the background and returns at once: true
|
||||
# if it started, false if one was already running. Poll jobLeadSyncStatus
|
||||
# to see it finish.
|
||||
runJobLeadSync: Boolean! @admin
|
||||
|
||||
# Scores every matched lead that has no score yet, without polling any
|
||||
# source. Background and polled like runJobLeadSync, and refused (false)
|
||||
# while either is running.
|
||||
scoreJobLeads: Boolean! @admin
|
||||
|
||||
# Scores every matched inbox lead again, scored or not, for after the
|
||||
# profile or the model has changed. A lead keeps its old score until its
|
||||
# new one arrives. Background and polled like the two above, and refused
|
||||
# (false) while any of the three is running.
|
||||
rescoreJobLeads: Boolean! @admin
|
||||
}
|
||||
Reference in New Issue
Block a user