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]>
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
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/job-tracker/internal/graph/model"
|
||||
"adam-french.co.uk/job-tracker/internal/models"
|
||||
"adam-french.co.uk/job-tracker/internal/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
|
||||
}
|
||||
Reference in New Issue
Block a user