The mailbox sync (Microsoft Graph and IMAP), its Claude classifier, the /email routes and the Settings page's email section are taken out while the pipeline is unused. The last commit with it is tagged email-pipeline-last; reverting this commit brings it back. The status rules the capture path shares (statusOrder, StatusAdvances, NormalizeStatus) move to job_status.go with their tests. ProcessedEmail stays in the migration, marked dormant, so its history survives for a restored pipeline. golang.org/x/oauth2 is no longer needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
140 lines
5.0 KiB
Go
140 lines
5.0 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/job-tracker/internal/graph/model"
|
|
"adam-french.co.uk/job-tracker/internal/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 capture
|
|
// upsert's LOWER(company) lookup — an orphan row no capture can find.
|
|
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 with deleted_at set, not purged.
|
|
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
|
|
}
|