diff --git a/CLAUDE.md b/CLAUDE.md index 1063830..2522d40 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -76,7 +76,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun - `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout) - `graph/generated.go` — auto-generated by gqlgen, do not edit - `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit -- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page, Background, Layout, Component) +- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page, Background, Layout, Component, CoverLetter, CoverSnippet) - `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns) - `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), uploads (`uploads.go`: validation, naming, Garage bucket with disk fallback), DB seeding. There is no Claude client in Go any more @@ -85,7 +85,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun - `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`) - `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status - `src/uploads.js` — storing and showing uploaded files: `uploadFile(file)` → public `/uploads/...` URL, `ACCEPT` for file pickers, `kindOf`/`tagFor`/`isUploadUrl`/`mediaSize`. Every upload goes through it -- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages, layouts, components. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices +- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages, layouts, components, coverLetters, coverSnippets. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices - `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). Canvas pages are admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type, drawn by `views/home3/BoxCanvas.vue` per page key: the landing page (`/`, key `index`) is one, and admin-created `Page`s (e.g. shrines, and `/stp`, the `Page` with slug `stp`) are served at `/` by the router's catch-all, `views/canvas/CanvasPage.vue`. A `Layout` is a saved, named copy of a page's boxes and background that can be loaded onto any canvas (the canvas's Layouts button, or the admin Pages tab). A `Component` is a saved, named HTML box: "+ New box" places copies of it, and the canvas's Components button also places it *linked* (`Box.componentId`), so the box shows the component's HTML and editing it edits every linked box; the built-in starters in `templates.js` become components through that panel's "Import built-ins". Boxes and pages can be admin-only, filtered server-side. Each canvas page key also has an optional `Background`, set from the canvas's Background button and painted by `DefaultLayout`. See "The /stp canvas" in `vue/README.md` - `src/components/` — reusable UI components - `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`. @@ -117,4 +117,4 @@ Each area has its own README with the detail that doesn't belong here: - **Comments explain *why*, not *what*.** The codebase is deliberately heavily commented at the points where behaviour is non-obvious (concurrency, caching, auth, scraping, nginx templating). Preserve these when editing; if you change the behaviour they describe, update them. - **Resolver commentary lives inside function bodies**, because gqlgen relocates or strips anything above the signature when regenerating. - **Schema files use `#` comments**, not triple-quoted description blocks — descriptions would change GraphQL introspection output. -- **Legacy views are kept, not deleted.** `vue/src/views/unused/`, `Intro.vue`, `Gym.vue`, the unlisted CV templates and similar carry a `STATUS:` header comment saying whether they are live. They are tree-shaken out of the build. Check the header before assuming a file is dead — e.g. `views/unused/CoverLetters.vue` is actually live on `/cv`. +- **Legacy views are kept, not deleted.** `vue/src/views/unused/`, `Intro.vue`, `Gym.vue`, the unlisted CV templates and similar carry a `STATUS:` header comment saying whether they are live. They are tree-shaken out of the build. Check the header before assuming a file is dead; being in `views/unused/` is not proof. diff --git a/backend/gqlgen.yml b/backend/gqlgen.yml index 298057c..c81f162 100644 --- a/backend/gqlgen.yml +++ b/backend/gqlgen.yml @@ -116,3 +116,15 @@ models: resolver: false uses: resolver: true + CoverLetter: + model: + - adam-french.co.uk/backend/models.CoverLetter + fields: + deletedAt: + resolver: false + CoverSnippet: + model: + - adam-french.co.uk/backend/models.CoverSnippet + fields: + deletedAt: + resolver: false diff --git a/backend/graph/cover_letter.resolvers.go b/backend/graph/cover_letter.resolvers.go new file mode 100644 index 0000000..8aa0cec --- /dev/null +++ b/backend/graph/cover_letter.resolvers.go @@ -0,0 +1,153 @@ +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" + "errors" + + "adam-french.co.uk/backend/graph/model" + "adam-french.co.uk/backend/models" +) + +// CreateCoverLetter is the resolver for the createCoverLetter field. +func (r *mutationResolver) CreateCoverLetter(ctx context.Context, input model.CreateCoverLetterInput) (*models.CoverLetter, error) { + name, err := cleanCoverLetterName(input.Name) + if err != nil { + return nil, err + } + if err := checkCoverLetterBody(input.Body); err != nil { + return nil, err + } + taken, err := coverLetterNameTaken(r.Store.DB, name, 0) + if err != nil { + return nil, err + } + if taken { + return nil, errors.New("there is already a cover letter with that name") + } + letter := models.CoverLetter{Name: name, Body: input.Body} + if err := r.Store.DB.Create(&letter).Error; err != nil { + return nil, err + } + return &letter, nil +} + +// UpdateCoverLetter is the resolver for the updateCoverLetter field. +func (r *mutationResolver) UpdateCoverLetter(ctx context.Context, id int, input model.UpdateCoverLetterInput) (*models.CoverLetter, error) { + var letter models.CoverLetter + if err := r.Store.DB.First(&letter, id).Error; err != nil { + return nil, err + } + if input.Name != nil { + name, err := cleanCoverLetterName(*input.Name) + if err != nil { + return nil, err + } + taken, err := coverLetterNameTaken(r.Store.DB, name, letter.ID) + if err != nil { + return nil, err + } + if taken { + return nil, errors.New("there is already a cover letter with that name") + } + letter.Name = name + } + if input.Body != nil { + if err := checkCoverLetterBody(*input.Body); err != nil { + return nil, err + } + letter.Body = *input.Body + } + if err := r.Store.DB.Save(&letter).Error; err != nil { + return nil, err + } + return &letter, nil +} + +// DeleteCoverLetter is the resolver for the deleteCoverLetter field. +func (r *mutationResolver) DeleteCoverLetter(ctx context.Context, id int) (*models.CoverLetter, error) { + var letter models.CoverLetter + if err := r.Store.DB.First(&letter, id).Error; err != nil { + return nil, err + } + if err := r.Store.DB.Delete(&letter).Error; err != nil { + return nil, err + } + return &letter, nil +} + +// CreateCoverSnippet is the resolver for the createCoverSnippet field. +func (r *mutationResolver) CreateCoverSnippet(ctx context.Context, input model.CreateCoverSnippetInput) (*models.CoverSnippet, error) { + text, err := cleanSnippetText(input.Text) + if err != nil { + return nil, err + } + snippet := models.CoverSnippet{Text: text} + if input.Section != nil { + if snippet.Section, err = cleanSnippetSection(*input.Section); err != nil { + return nil, err + } + } + if err := r.Store.DB.Create(&snippet).Error; err != nil { + return nil, err + } + return &snippet, nil +} + +// UpdateCoverSnippet is the resolver for the updateCoverSnippet field. +func (r *mutationResolver) UpdateCoverSnippet(ctx context.Context, id int, input model.UpdateCoverSnippetInput) (*models.CoverSnippet, error) { + // Letters it was dropped into keep their own copy of the old text. + var snippet models.CoverSnippet + if err := r.Store.DB.First(&snippet, id).Error; err != nil { + return nil, err + } + var err error + if input.Text != nil { + if snippet.Text, err = cleanSnippetText(*input.Text); err != nil { + return nil, err + } + } + if input.Section != nil { + if snippet.Section, err = cleanSnippetSection(*input.Section); err != nil { + return nil, err + } + } + if err := r.Store.DB.Save(&snippet).Error; err != nil { + return nil, err + } + return &snippet, nil +} + +// DeleteCoverSnippet is the resolver for the deleteCoverSnippet field. +func (r *mutationResolver) DeleteCoverSnippet(ctx context.Context, id int) (*models.CoverSnippet, error) { + var snippet models.CoverSnippet + if err := r.Store.DB.First(&snippet, id).Error; err != nil { + return nil, err + } + if err := r.Store.DB.Delete(&snippet).Error; err != nil { + return nil, err + } + return &snippet, nil +} + +// CoverLetters is the resolver for the coverLetters field. +func (r *queryResolver) CoverLetters(ctx context.Context) ([]*models.CoverLetter, error) { + var letters []models.CoverLetter + if err := r.Store.DB.Order("updated_at DESC").Find(&letters).Error; err != nil { + return nil, err + } + return ptrs(letters), nil +} + +// CoverSnippets is the resolver for the coverSnippets field. +func (r *queryResolver) CoverSnippets(ctx context.Context) ([]*models.CoverSnippet, error) { + var snippets []models.CoverSnippet + if err := r.Store.DB.Order("section ASC, created_at DESC").Find(&snippets).Error; err != nil { + return nil, err + } + return ptrs(snippets), nil +} diff --git a/backend/graph/cover_letter_helpers.go b/backend/graph/cover_letter_helpers.go new file mode 100644 index 0000000..eb793f0 --- /dev/null +++ b/backend/graph/cover_letter_helpers.go @@ -0,0 +1,84 @@ +package graph + +// Hand-written helpers for cover_letter.resolvers.go, kept out of the +// resolver file for the same reason as box_helpers.go. + +import ( + "encoding/json" + "errors" + "fmt" + "strings" + "unicode/utf8" + + "adam-french.co.uk/backend/models" + "gorm.io/gorm" +) + +const ( + maxCoverLetterNameLen = 100 + // A letter is a page of text; 100 KB is far beyond any real one and + // still small enough that a runaway client can't fill the table. + maxCoverLetterBodyLen = 100 * 1024 + maxSnippetTextLen = 5000 + maxSnippetSectionLen = 100 +) + +// cleanCoverLetterName trims name and reports why it can't be a letter's +// name. +func cleanCoverLetterName(name string) (string, error) { + name = strings.TrimSpace(name) + if name == "" { + return name, errors.New("a cover letter needs a name") + } + if len(name) > maxCoverLetterNameLen { + return name, fmt.Errorf("a cover letter name is at most %d characters", maxCoverLetterNameLen) + } + return name, nil +} + +// coverLetterNameTaken reports whether a live letter other than exceptID has +// this name. Checked up front, like layoutNameTaken, so the admin gets a +// sentence rather than a constraint violation. +func coverLetterNameTaken(db *gorm.DB, name string, exceptID uint) (bool, error) { + var count int64 + err := db.Model(&models.CoverLetter{}).Where("name = ? AND id <> ?", name, exceptID).Count(&count).Error + return count > 0, err +} + +// checkCoverLetterBody reports why body can't be stored. The server never +// reads inside it, so it only has to be a JSON object of a sane size — an +// array or a bare string would be a frontend bug worth refusing early. +func checkCoverLetterBody(body string) error { + if len(body) > maxCoverLetterBodyLen { + return fmt.Errorf("a cover letter is at most %d KB", maxCoverLetterBodyLen/1024) + } + var obj map[string]json.RawMessage + // null unmarshals into a nil map without error, so it is caught here too. + if err := json.Unmarshal([]byte(body), &obj); err != nil || obj == nil { + return errors.New("a cover letter body must be a JSON object") + } + return nil +} + +// cleanSnippetText trims text and reports why it can't be a bank paragraph. +// Counted in characters, not bytes, since the limit is about how much prose +// fits rather than storage. +func cleanSnippetText(text string) (string, error) { + text = strings.TrimSpace(text) + if text == "" { + return text, errors.New("a paragraph can't be empty") + } + if utf8.RuneCountInString(text) > maxSnippetTextLen { + return text, fmt.Errorf("a paragraph is at most %d characters", maxSnippetTextLen) + } + return text, nil +} + +// cleanSnippetSection trims a snippet's section title. +func cleanSnippetSection(section string) (string, error) { + section = strings.TrimSpace(section) + if utf8.RuneCountInString(section) > maxSnippetSectionLen { + return section, fmt.Errorf("a section title is at most %d characters", maxSnippetSectionLen) + } + return section, nil +} diff --git a/backend/graph/cover_letter_helpers_test.go b/backend/graph/cover_letter_helpers_test.go new file mode 100644 index 0000000..2cb6f87 --- /dev/null +++ b/backend/graph/cover_letter_helpers_test.go @@ -0,0 +1,76 @@ +package graph + +import ( + "strings" + "testing" +) + +func TestCleanCoverLetterName(t *testing.T) { + for _, c := range []struct { + name, in, want string + wantErr bool + }{ + {"plain", "Acme", "Acme", false}, + {"trimmed", " Acme \n", "Acme", false}, + {"empty", "", "", true}, + {"only spaces", " ", "", true}, + {"at the limit", strings.Repeat("a", maxCoverLetterNameLen), strings.Repeat("a", maxCoverLetterNameLen), false}, + {"too long", strings.Repeat("a", maxCoverLetterNameLen+1), "", true}, + } { + t.Run(c.name, func(t *testing.T) { + got, err := cleanCoverLetterName(c.in) + if (err != nil) != c.wantErr { + t.Fatalf("err = %v, wantErr %v", err, c.wantErr) + } + if !c.wantErr && got != c.want { + t.Fatalf("got %q, want %q", got, c.want) + } + }) + } +} + +func TestCheckCoverLetterBody(t *testing.T) { + for _, c := range []struct { + name, in string + wantErr bool + }{ + {"object", `{"v":1,"sections":[]}`, false}, + {"empty object", `{}`, false}, + {"array", `[]`, true}, + {"string", `"hi"`, true}, + {"null", `null`, true}, + {"not json", `{`, true}, + {"empty", ``, true}, + {"too big", `{"x":"` + strings.Repeat("a", maxCoverLetterBodyLen) + `"}`, true}, + } { + t.Run(c.name, func(t *testing.T) { + if err := checkCoverLetterBody(c.in); (err != nil) != c.wantErr { + t.Fatalf("err = %v, wantErr %v", err, c.wantErr) + } + }) + } +} + +func TestCleanSnippetText(t *testing.T) { + for _, c := range []struct { + name, in, want string + wantErr bool + }{ + {"plain", "I like Go.", "I like Go.", false}, + {"trimmed", "\n I like Go. ", "I like Go.", false}, + {"empty", " ", "", true}, + // Characters, not bytes: 5000 two-byte runes still fit. + {"multibyte at the limit", strings.Repeat("é", maxSnippetTextLen), strings.Repeat("é", maxSnippetTextLen), false}, + {"too long", strings.Repeat("a", maxSnippetTextLen+1), "", true}, + } { + t.Run(c.name, func(t *testing.T) { + got, err := cleanSnippetText(c.in) + if (err != nil) != c.wantErr { + t.Fatalf("err = %v, wantErr %v", err, c.wantErr) + } + if !c.wantErr && got != c.want { + t.Fatalf("got %q, want %q", got, c.want) + } + }) + } +} diff --git a/backend/graph/directives_test.go b/backend/graph/directives_test.go index e3a87e1..844448e 100644 --- a/backend/graph/directives_test.go +++ b/backend/graph/directives_test.go @@ -192,6 +192,8 @@ func TestGuardedQueriesArePinned(t *testing.T) { "places": "signedIn", "layouts": "admin", "components": "admin", + "coverLetters": "admin", + "coverSnippets": "admin", "permissionTypes": "signedIn", } got := map[string]string{} diff --git a/backend/graph/generated.go b/backend/graph/generated.go index 20012fb..3ea14dd 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -113,6 +113,21 @@ type ComplexityRoot struct { W func(childComplexity int) int } + CoverLetter struct { + Body func(childComplexity int) int + CreatedAt func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + + CoverSnippet struct { + CreatedAt func(childComplexity int) int + ID func(childComplexity int) int + Section func(childComplexity int) int + Text func(childComplexity int) int + } + Favorite struct { CreatedAt func(childComplexity int) int ID func(childComplexity int) int @@ -157,6 +172,8 @@ type ComplexityRoot struct { CreateBookmark func(childComplexity int, input model.CreateBookmarkInput) int CreateBox func(childComplexity int, input model.CreateBoxInput) int CreateComponent func(childComplexity int, input model.CreateComponentInput) int + CreateCoverLetter func(childComplexity int, input model.CreateCoverLetterInput) int + CreateCoverSnippet func(childComplexity int, input model.CreateCoverSnippetInput) int CreateFavorite func(childComplexity int, input model.CreateFavoriteInput) int CreateLayout func(childComplexity int, input model.CreateLayoutInput) int CreatePage func(childComplexity int, input model.CreatePageInput) int @@ -166,6 +183,8 @@ type ComplexityRoot struct { DeleteBookmark func(childComplexity int, id int) int DeleteBox func(childComplexity int, id int) int DeleteComponent func(childComplexity int, id int) int + DeleteCoverLetter func(childComplexity int, id int) int + DeleteCoverSnippet func(childComplexity int, id int) int DeleteLayout func(childComplexity int, id int) int DeletePage func(childComplexity int, id int) int DeletePlace func(childComplexity int, id int) int @@ -181,6 +200,8 @@ type ComplexityRoot struct { SetUserPermissions func(childComplexity int, id int, permissions []string) int UpdateBox func(childComplexity int, id int, input model.UpdateBoxInput) int UpdateComponent func(childComplexity int, id int, input model.UpdateComponentInput) int + UpdateCoverLetter func(childComplexity int, id int, input model.UpdateCoverLetterInput) int + UpdateCoverSnippet func(childComplexity int, id int, input model.UpdateCoverSnippetInput) int UpdateLayout func(childComplexity int, id int, input model.UpdateLayoutInput) int UpdatePage func(childComplexity int, id int, input model.UpdatePageInput) int UpdatePlace func(childComplexity int, id int, input model.UpdatePlaceInput) int @@ -231,6 +252,8 @@ type ComplexityRoot struct { Bookmarks func(childComplexity int) int Boxes func(childComplexity int, page string) int Components func(childComplexity int) int + CoverLetters func(childComplexity int) int + CoverSnippets func(childComplexity int) int Favorites func(childComplexity int) int GiteaFeed func(childComplexity int) int Layouts func(childComplexity int) int @@ -344,6 +367,12 @@ type MutationResolver interface { DeleteComponent(ctx context.Context, id int) (*models.Component, error) SaveBoxAsComponent(ctx context.Context, id int, name string) (*models.Box, error) DetachBox(ctx context.Context, id int) (*models.Box, error) + CreateCoverLetter(ctx context.Context, input model.CreateCoverLetterInput) (*models.CoverLetter, error) + UpdateCoverLetter(ctx context.Context, id int, input model.UpdateCoverLetterInput) (*models.CoverLetter, error) + DeleteCoverLetter(ctx context.Context, id int) (*models.CoverLetter, error) + CreateCoverSnippet(ctx context.Context, input model.CreateCoverSnippetInput) (*models.CoverSnippet, error) + UpdateCoverSnippet(ctx context.Context, id int, input model.UpdateCoverSnippetInput) (*models.CoverSnippet, error) + DeleteCoverSnippet(ctx context.Context, id int) (*models.CoverSnippet, error) CreateFavorite(ctx context.Context, input model.CreateFavoriteInput) (*models.Favorite, error) CreateLayout(ctx context.Context, input model.CreateLayoutInput) (*models.Layout, error) UpdateLayout(ctx context.Context, id int, input model.UpdateLayoutInput) (*models.Layout, error) @@ -370,6 +399,8 @@ type QueryResolver interface { Bookmarks(ctx context.Context) ([]*models.Bookmark, error) Boxes(ctx context.Context, page string) ([]*models.Box, error) Components(ctx context.Context) ([]*models.Component, error) + CoverLetters(ctx context.Context) ([]*models.CoverLetter, error) + CoverSnippets(ctx context.Context) ([]*models.CoverSnippet, error) Favorites(ctx context.Context) ([]*models.Favorite, error) GiteaFeed(ctx context.Context) (*model.GiteaFeedItem, error) Layouts(ctx context.Context) ([]*models.Layout, error) @@ -711,6 +742,62 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Component.W(childComplexity), true + case "CoverLetter.body": + if e.ComplexityRoot.CoverLetter.Body == nil { + break + } + + return e.ComplexityRoot.CoverLetter.Body(childComplexity), true + case "CoverLetter.createdAt": + if e.ComplexityRoot.CoverLetter.CreatedAt == nil { + break + } + + return e.ComplexityRoot.CoverLetter.CreatedAt(childComplexity), true + case "CoverLetter.id": + if e.ComplexityRoot.CoverLetter.ID == nil { + break + } + + return e.ComplexityRoot.CoverLetter.ID(childComplexity), true + case "CoverLetter.name": + if e.ComplexityRoot.CoverLetter.Name == nil { + break + } + + return e.ComplexityRoot.CoverLetter.Name(childComplexity), true + case "CoverLetter.updatedAt": + if e.ComplexityRoot.CoverLetter.UpdatedAt == nil { + break + } + + return e.ComplexityRoot.CoverLetter.UpdatedAt(childComplexity), true + + case "CoverSnippet.createdAt": + if e.ComplexityRoot.CoverSnippet.CreatedAt == nil { + break + } + + return e.ComplexityRoot.CoverSnippet.CreatedAt(childComplexity), true + case "CoverSnippet.id": + if e.ComplexityRoot.CoverSnippet.ID == nil { + break + } + + return e.ComplexityRoot.CoverSnippet.ID(childComplexity), true + case "CoverSnippet.section": + if e.ComplexityRoot.CoverSnippet.Section == nil { + break + } + + return e.ComplexityRoot.CoverSnippet.Section(childComplexity), true + case "CoverSnippet.text": + if e.ComplexityRoot.CoverSnippet.Text == nil { + break + } + + return e.ComplexityRoot.CoverSnippet.Text(childComplexity), true + case "Favorite.createdAt": if e.ComplexityRoot.Favorite.CreatedAt == nil { break @@ -931,6 +1018,28 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.CreateComponent(childComplexity, args["input"].(model.CreateComponentInput)), true + case "Mutation.createCoverLetter": + if e.ComplexityRoot.Mutation.CreateCoverLetter == nil { + break + } + + args, err := ec.field_Mutation_createCoverLetter_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreateCoverLetter(childComplexity, args["input"].(model.CreateCoverLetterInput)), true + case "Mutation.createCoverSnippet": + if e.ComplexityRoot.Mutation.CreateCoverSnippet == nil { + break + } + + args, err := ec.field_Mutation_createCoverSnippet_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreateCoverSnippet(childComplexity, args["input"].(model.CreateCoverSnippetInput)), true case "Mutation.createFavorite": if e.ComplexityRoot.Mutation.CreateFavorite == nil { break @@ -1030,6 +1139,28 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteComponent(childComplexity, args["id"].(int)), true + case "Mutation.deleteCoverLetter": + if e.ComplexityRoot.Mutation.DeleteCoverLetter == nil { + break + } + + args, err := ec.field_Mutation_deleteCoverLetter_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeleteCoverLetter(childComplexity, args["id"].(int)), true + case "Mutation.deleteCoverSnippet": + if e.ComplexityRoot.Mutation.DeleteCoverSnippet == nil { + break + } + + args, err := ec.field_Mutation_deleteCoverSnippet_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeleteCoverSnippet(childComplexity, args["id"].(int)), true case "Mutation.deleteLayout": if e.ComplexityRoot.Mutation.DeleteLayout == nil { break @@ -1185,6 +1316,28 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.UpdateComponent(childComplexity, args["id"].(int), args["input"].(model.UpdateComponentInput)), true + case "Mutation.updateCoverLetter": + if e.ComplexityRoot.Mutation.UpdateCoverLetter == nil { + break + } + + args, err := ec.field_Mutation_updateCoverLetter_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdateCoverLetter(childComplexity, args["id"].(int), args["input"].(model.UpdateCoverLetterInput)), true + case "Mutation.updateCoverSnippet": + if e.ComplexityRoot.Mutation.UpdateCoverSnippet == nil { + break + } + + args, err := ec.field_Mutation_updateCoverSnippet_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdateCoverSnippet(childComplexity, args["id"].(int), args["input"].(model.UpdateCoverSnippetInput)), true case "Mutation.updateLayout": if e.ComplexityRoot.Mutation.UpdateLayout == nil { break @@ -1430,6 +1583,18 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Query.Components(childComplexity), true + case "Query.coverLetters": + if e.ComplexityRoot.Query.CoverLetters == nil { + break + } + + return e.ComplexityRoot.Query.CoverLetters(childComplexity), true + case "Query.coverSnippets": + if e.ComplexityRoot.Query.CoverSnippets == nil { + break + } + + return e.ComplexityRoot.Query.CoverSnippets(childComplexity), true case "Query.favorites": if e.ComplexityRoot.Query.Favorites == nil { break @@ -1764,6 +1929,8 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCreateBookmarkInput, ec.unmarshalInputCreateBoxInput, ec.unmarshalInputCreateComponentInput, + ec.unmarshalInputCreateCoverLetterInput, + ec.unmarshalInputCreateCoverSnippetInput, ec.unmarshalInputCreateFavoriteInput, ec.unmarshalInputCreateLayoutInput, ec.unmarshalInputCreatePageInput, @@ -1773,6 +1940,8 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputLoginInput, ec.unmarshalInputUpdateBoxInput, ec.unmarshalInputUpdateComponentInput, + ec.unmarshalInputUpdateCoverLetterInput, + ec.unmarshalInputUpdateCoverSnippetInput, ec.unmarshalInputUpdateLayoutInput, ec.unmarshalInputUpdatePageInput, ec.unmarshalInputUpdatePlaceInput, @@ -1851,7 +2020,7 @@ func newExecutionContext( } } -//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/background.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/component.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/layout.graphql" "schema/message.graphql" "schema/page.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" +//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/background.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/component.graphql" "schema/cover_letter.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/layout.graphql" "schema/message.graphql" "schema/page.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" var sourcesFS embed.FS func sourceData(filename string) string { @@ -1869,6 +2038,7 @@ var sources = []*ast.Source{ {Name: "schema/bookmark.graphql", Input: sourceData("schema/bookmark.graphql"), BuiltIn: false}, {Name: "schema/box.graphql", Input: sourceData("schema/box.graphql"), BuiltIn: false}, {Name: "schema/component.graphql", Input: sourceData("schema/component.graphql"), BuiltIn: false}, + {Name: "schema/cover_letter.graphql", Input: sourceData("schema/cover_letter.graphql"), BuiltIn: false}, {Name: "schema/favorite.graphql", Input: sourceData("schema/favorite.graphql"), BuiltIn: false}, {Name: "schema/gitea.graphql", Input: sourceData("schema/gitea.graphql"), BuiltIn: false}, {Name: "schema/layout.graphql", Input: sourceData("schema/layout.graphql"), BuiltIn: false}, @@ -2022,6 +2192,36 @@ func (ec *executionContext) childFields_Component(ctx context.Context, field gra return nil, fmt.Errorf("no field named %q was found under type Component", field.Name) } +func (ec *executionContext) childFields_CoverLetter(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CoverLetter_id(ctx, field) + case "createdAt": + return ec.fieldContext_CoverLetter_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_CoverLetter_updatedAt(ctx, field) + case "name": + return ec.fieldContext_CoverLetter_name(ctx, field) + case "body": + return ec.fieldContext_CoverLetter_body(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CoverLetter", field.Name) +} + +func (ec *executionContext) childFields_CoverSnippet(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CoverSnippet_id(ctx, field) + case "createdAt": + return ec.fieldContext_CoverSnippet_createdAt(ctx, field) + case "text": + return ec.fieldContext_CoverSnippet_text(ctx, field) + case "section": + return ec.fieldContext_CoverSnippet_section(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CoverSnippet", field.Name) +} + func (ec *executionContext) childFields_Favorite(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": @@ -2510,6 +2710,34 @@ func (ec *executionContext) field_Mutation_createComponent_args(ctx context.Cont return args, nil } +func (ec *executionContext) field_Mutation_createCoverLetter_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.CreateCoverLetterInput, error) { + return ec.unmarshalNCreateCoverLetterInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateCoverLetterInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_createCoverSnippet_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.CreateCoverSnippetInput, error) { + return ec.unmarshalNCreateCoverSnippetInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateCoverSnippetInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createFavorite_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2636,6 +2864,34 @@ func (ec *executionContext) field_Mutation_deleteComponent_args(ctx context.Cont return args, nil } +func (ec *executionContext) field_Mutation_deleteCoverLetter_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_deleteCoverSnippet_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_deleteLayout_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2866,6 +3122,50 @@ func (ec *executionContext) field_Mutation_updateComponent_args(ctx context.Cont return args, nil } +func (ec *executionContext) field_Mutation_updateCoverLetter_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + arg1, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.UpdateCoverLetterInput, error) { + return ec.unmarshalNUpdateCoverLetterInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateCoverLetterInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Mutation_updateCoverSnippet_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + arg1, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.UpdateCoverSnippetInput, error) { + return ec.unmarshalNUpdateCoverSnippetInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateCoverSnippetInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updateLayout_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -4234,6 +4534,213 @@ func (ec *executionContext) fieldContext_Component_uses(_ context.Context, field return graphql.NewScalarFieldContext("Component", field, true, true, errors.New("field of type Int does not have child fields")) } +func (ec *executionContext) _CoverLetter_id(ctx context.Context, field graphql.CollectedField, obj *models.CoverLetter) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverLetter_id(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.ID, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v uint) graphql.Marshaler { + return ec.marshalNID2uint(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverLetter_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverLetter", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _CoverLetter_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.CoverLetter) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverLetter_createdAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.CreatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverLetter_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverLetter", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _CoverLetter_updatedAt(ctx context.Context, field graphql.CollectedField, obj *models.CoverLetter) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverLetter_updatedAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.UpdatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverLetter_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverLetter", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _CoverLetter_name(ctx context.Context, field graphql.CollectedField, obj *models.CoverLetter) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverLetter_name(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Name, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverLetter_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverLetter", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _CoverLetter_body(ctx context.Context, field graphql.CollectedField, obj *models.CoverLetter) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverLetter_body(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Body, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverLetter_body(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverLetter", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _CoverSnippet_id(ctx context.Context, field graphql.CollectedField, obj *models.CoverSnippet) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverSnippet_id(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.ID, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v uint) graphql.Marshaler { + return ec.marshalNID2uint(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverSnippet_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverSnippet", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _CoverSnippet_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.CoverSnippet) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverSnippet_createdAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.CreatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverSnippet_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverSnippet", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _CoverSnippet_text(ctx context.Context, field graphql.CollectedField, obj *models.CoverSnippet) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverSnippet_text(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Text, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverSnippet_text(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverSnippet", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _CoverSnippet_section(ctx context.Context, field graphql.CollectedField, obj *models.CoverSnippet) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_CoverSnippet_section(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Section, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_CoverSnippet_section(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("CoverSnippet", field, false, false, errors.New("field of type String does not have child fields")) +} + func (ec *executionContext) _Favorite_id(ctx context.Context, field graphql.CollectedField, obj *models.Favorite) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -5649,6 +6156,348 @@ func (ec *executionContext) fieldContext_Mutation_detachBox(ctx context.Context, return fc, nil } +func (ec *executionContext) _Mutation_createCoverLetter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_createCoverLetter(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreateCoverLetter(ctx, fc.Args["input"].(model.CreateCoverLetterInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverLetter + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverLetter) graphql.Marshaler { + return ec.marshalNCoverLetter2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetter(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createCoverLetter(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverLetter(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCoverLetter_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateCoverLetter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_updateCoverLetter(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdateCoverLetter(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdateCoverLetterInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverLetter + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverLetter) graphql.Marshaler { + return ec.marshalNCoverLetter2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetter(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updateCoverLetter(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverLetter(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updateCoverLetter_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteCoverLetter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_deleteCoverLetter(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeleteCoverLetter(ctx, fc.Args["id"].(int)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverLetter + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverLetter) graphql.Marshaler { + return ec.marshalNCoverLetter2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetter(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deleteCoverLetter(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverLetter(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteCoverLetter_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_createCoverSnippet(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_createCoverSnippet(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreateCoverSnippet(ctx, fc.Args["input"].(model.CreateCoverSnippetInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverSnippet + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverSnippet) graphql.Marshaler { + return ec.marshalNCoverSnippet2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippet(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createCoverSnippet(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverSnippet(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createCoverSnippet_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateCoverSnippet(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_updateCoverSnippet(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdateCoverSnippet(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdateCoverSnippetInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverSnippet + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverSnippet) graphql.Marshaler { + return ec.marshalNCoverSnippet2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippet(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updateCoverSnippet(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverSnippet(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updateCoverSnippet_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteCoverSnippet(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_deleteCoverSnippet(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeleteCoverSnippet(ctx, fc.Args["id"].(int)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.CoverSnippet + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.CoverSnippet) graphql.Marshaler { + return ec.marshalNCoverSnippet2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippet(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deleteCoverSnippet(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverSnippet(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteCoverSnippet_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_createFavorite(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -7511,6 +8360,96 @@ func (ec *executionContext) fieldContext_Query_components(_ context.Context, fie return fc, nil } +func (ec *executionContext) _Query_coverLetters(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Query_coverLetters(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().CoverLetters(ctx) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal []*models.CoverLetter + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v []*models.CoverLetter) graphql.Marshaler { + return ec.marshalNCoverLetter2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetterᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_coverLetters(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverLetter(ctx, field) + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_coverSnippets(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Query_coverSnippets(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().CoverSnippets(ctx) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal []*models.CoverSnippet + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v []*models.CoverSnippet) graphql.Marshaler { + return ec.marshalNCoverSnippet2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippetᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_coverSnippets(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_CoverSnippet(ctx, field) + }, + } + return fc, nil +} + func (ec *executionContext) _Query_favorites(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -10388,6 +11327,80 @@ func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Conte return it, nil } +func (ec *executionContext) unmarshalInputCreateCoverLetterInput(ctx context.Context, obj any) (model.CreateCoverLetterInput, error) { + var it model.CreateCoverLetterInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "body"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "body": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Body = data + } + } + return it, nil +} + +func (ec *executionContext) unmarshalInputCreateCoverSnippetInput(ctx context.Context, obj any) (model.CreateCoverSnippetInput, error) { + var it model.CreateCoverSnippetInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"text", "section"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "text": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("text")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Text = data + case "section": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("section")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Section = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputCreateFavoriteInput(ctx context.Context, obj any) (model.CreateFavoriteInput, error) { var it model.CreateFavoriteInput if obj == nil { @@ -10889,6 +11902,80 @@ func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Conte return it, nil } +func (ec *executionContext) unmarshalInputUpdateCoverLetterInput(ctx context.Context, obj any) (model.UpdateCoverLetterInput, error) { + var it model.UpdateCoverLetterInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "body"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "body": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Body = data + } + } + return it, nil +} + +func (ec *executionContext) unmarshalInputUpdateCoverSnippetInput(ctx context.Context, obj any) (model.UpdateCoverSnippetInput, error) { + var it model.UpdateCoverSnippetInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"text", "section"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "text": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("text")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Text = data + case "section": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("section")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Section = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputUpdateLayoutInput(ctx context.Context, obj any) (model.UpdateLayoutInput, error) { var it model.UpdateLayoutInput if obj == nil { @@ -11563,6 +12650,117 @@ func (ec *executionContext) _Component(ctx context.Context, sel ast.SelectionSet return out } +var coverLetterImplementors = []string{"CoverLetter"} + +func (ec *executionContext) _CoverLetter(ctx context.Context, sel ast.SelectionSet, obj *models.CoverLetter) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, coverLetterImplementors) + + out := graphql.NewFieldSet(fields) + deferredFieldSet := graphql.NewFieldSet(nil) + deferLabelToView := make(map[string]*graphql.FieldSetView) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CoverLetter") + case "id": + out.Values[i] = ec._CoverLetter_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createdAt": + out.Values[i] = ec._CoverLetter_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updatedAt": + out.Values[i] = ec._CoverLetter_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "name": + out.Values[i] = ec._CoverLetter_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "body": + out.Values[i] = ec._CoverLetter_body(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.Deferred, int32(min(len(deferLabelToView), math.MaxInt32))) + + ec.ProcessDeferredGroup(graphql.DeferredGroup{ + Defers: deferLabelToView, + Path: graphql.GetPath(ctx), + FieldSet: deferredFieldSet, + Context: ctx, + }) + + return out +} + +var coverSnippetImplementors = []string{"CoverSnippet"} + +func (ec *executionContext) _CoverSnippet(ctx context.Context, sel ast.SelectionSet, obj *models.CoverSnippet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, coverSnippetImplementors) + + out := graphql.NewFieldSet(fields) + deferredFieldSet := graphql.NewFieldSet(nil) + deferLabelToView := make(map[string]*graphql.FieldSetView) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CoverSnippet") + case "id": + out.Values[i] = ec._CoverSnippet_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createdAt": + out.Values[i] = ec._CoverSnippet_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "text": + out.Values[i] = ec._CoverSnippet_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "section": + out.Values[i] = ec._CoverSnippet_section(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.Deferred, int32(min(len(deferLabelToView), math.MaxInt32))) + + ec.ProcessDeferredGroup(graphql.DeferredGroup{ + Defers: deferLabelToView, + Path: graphql.GetPath(ctx), + FieldSet: deferredFieldSet, + Context: ctx, + }) + + return out +} + var favoriteImplementors = []string{"Favorite"} func (ec *executionContext) _Favorite(ctx context.Context, sel ast.SelectionSet, obj *models.Favorite) graphql.Marshaler { @@ -12051,6 +13249,48 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createCoverLetter": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCoverLetter(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updateCoverLetter": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateCoverLetter(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteCoverLetter": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteCoverLetter(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createCoverSnippet": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createCoverSnippet(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updateCoverSnippet": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateCoverSnippet(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteCoverSnippet": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteCoverSnippet(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "createFavorite": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_createFavorite(ctx, field) @@ -12611,6 +13851,50 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "coverLetters": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_coverLetters(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "coverSnippets": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_coverSnippets(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "favorites": field := field @@ -14109,6 +15393,58 @@ func (ec *executionContext) marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbacke return ec._Component(ctx, sel, v) } +func (ec *executionContext) marshalNCoverLetter2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetterᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.CoverLetter) graphql.Marshaler { + ret := graphql.MarshalSliceConcurrently(ctx, len(v), 0, false, func(ctx context.Context, i int) graphql.Marshaler { + fc := graphql.GetFieldContext(ctx) + fc.Result = &v[i] + return ec.marshalNCoverLetter2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetter(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCoverLetter2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverLetter(ctx context.Context, sel ast.SelectionSet, v *models.CoverLetter) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + graphql.AddErrorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CoverLetter(ctx, sel, v) +} + +func (ec *executionContext) marshalNCoverSnippet2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippetᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.CoverSnippet) graphql.Marshaler { + ret := graphql.MarshalSliceConcurrently(ctx, len(v), 0, false, func(ctx context.Context, i int) graphql.Marshaler { + fc := graphql.GetFieldContext(ctx) + fc.Result = &v[i] + return ec.marshalNCoverSnippet2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippet(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCoverSnippet2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐCoverSnippet(ctx context.Context, sel ast.SelectionSet, v *models.CoverSnippet) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + graphql.AddErrorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CoverSnippet(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCreateActivityInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateActivityInput(ctx context.Context, v any) (model.CreateActivityInput, error) { res, err := ec.unmarshalInputCreateActivityInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -14129,6 +15465,16 @@ func (ec *executionContext) unmarshalNCreateComponentInput2adamᚑfrenchᚗcoᚗ return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateCoverLetterInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateCoverLetterInput(ctx context.Context, v any) (model.CreateCoverLetterInput, error) { + res, err := ec.unmarshalInputCreateCoverLetterInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNCreateCoverSnippetInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateCoverSnippetInput(ctx context.Context, v any) (model.CreateCoverSnippetInput, error) { + res, err := ec.unmarshalInputCreateCoverSnippetInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateFavoriteInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateFavoriteInput(ctx context.Context, v any) (model.CreateFavoriteInput, error) { res, err := ec.unmarshalInputCreateFavoriteInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -14615,6 +15961,16 @@ func (ec *executionContext) unmarshalNUpdateComponentInput2adamᚑfrenchᚗcoᚗ return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNUpdateCoverLetterInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateCoverLetterInput(ctx context.Context, v any) (model.UpdateCoverLetterInput, error) { + res, err := ec.unmarshalInputUpdateCoverLetterInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNUpdateCoverSnippetInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateCoverSnippetInput(ctx context.Context, v any) (model.UpdateCoverSnippetInput, error) { + res, err := ec.unmarshalInputUpdateCoverSnippetInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNUpdateLayoutInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateLayoutInput(ctx context.Context, v any) (model.UpdateLayoutInput, error) { res, err := ec.unmarshalInputUpdateLayoutInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index 846d6c3..115cf93 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -59,6 +59,16 @@ type CreateComponentInput struct { AdminOnly *bool `json:"adminOnly,omitempty"` } +type CreateCoverLetterInput struct { + Name string `json:"name"` + Body string `json:"body"` +} + +type CreateCoverSnippetInput struct { + Text string `json:"text"` + Section *string `json:"section,omitempty"` +} + type CreateFavoriteInput struct { Type string `json:"type"` Name string `json:"name"` @@ -185,6 +195,16 @@ type UpdateComponentInput struct { AdminOnly *bool `json:"adminOnly,omitempty"` } +type UpdateCoverLetterInput struct { + Name *string `json:"name,omitempty"` + Body *string `json:"body,omitempty"` +} + +type UpdateCoverSnippetInput struct { + Text *string `json:"text,omitempty"` + Section *string `json:"section,omitempty"` +} + type UpdateLayoutInput struct { Name *string `json:"name,omitempty"` } diff --git a/backend/graph/schema/cover_letter.graphql b/backend/graph/schema/cover_letter.graphql new file mode 100644 index 0000000..15d149c --- /dev/null +++ b/backend/graph/schema/cover_letter.graphql @@ -0,0 +1,60 @@ +# Cover letters: saved letters from the /cv Cover Letter tab, and the bank of +# reusable paragraphs dragged into them. A letter's body is JSON the frontend +# owns (views/CV/coverLetter.js); the server only checks it is a JSON object +# of a sane size. See models.CoverLetter and graph/cover_letter_helpers.go. +# +# Admin only throughout, reads included: /cv is public, but the letters are +# drafts addressed to particular employers. + +type CoverLetter { + id: ID! + createdAt: Time! + updatedAt: Time! + name: String! + # The whole letter, as a JSON object. + body: String! +} + +type CoverSnippet { + id: ID! + createdAt: Time! + text: String! + # The section title it was written for; "" for none. Only groups the bank. + section: String! +} + +input CreateCoverLetterInput { + name: String! + body: String! +} + +input UpdateCoverLetterInput { + name: String + body: String +} + +input CreateCoverSnippetInput { + text: String! + section: String +} + +input UpdateCoverSnippetInput { + text: String + section: String +} + +extend type Query { + # Most recently updated first. + coverLetters: [CoverLetter!]! @admin + # By section, then newest first. + coverSnippets: [CoverSnippet!]! @admin +} + +extend type Mutation { + createCoverLetter(input: CreateCoverLetterInput!): CoverLetter! @admin + updateCoverLetter(id: ID!, input: UpdateCoverLetterInput!): CoverLetter! @admin + deleteCoverLetter(id: ID!): CoverLetter! @admin + createCoverSnippet(input: CreateCoverSnippetInput!): CoverSnippet! @admin + updateCoverSnippet(id: ID!, input: UpdateCoverSnippetInput!): CoverSnippet! @admin + deleteCoverSnippet(id: ID!): CoverSnippet! @admin +} diff --git a/backend/models/models.go b/backend/models/models.go index 368d973..9ac82c0 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -288,3 +288,29 @@ type Component struct { Shadow string `gorm:"not null;default:''" json:"shadow"` AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` } + +// CoverLetter is a saved letter from the /cv Cover Letter tab. Body is the +// whole letter as JSON (contact block, sections, paragraphs; the shape is +// views/CV/coverLetter.js's) because only the frontend ever reads inside it — +// the same reasoning as Layout.Boxes. The unique index is partial for the +// same reason as Page's. +type CoverLetter struct { + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` + Name string `gorm:"not null;index:idx_cover_letters_name,unique,where:deleted_at IS NULL" json:"name"` + Body string `gorm:"type:text;not null" json:"body"` +} + +// CoverSnippet is a reusable paragraph in the cover-letter bank, dragged into +// a letter as a copy. Section is the title of the section it was written for, +// only used to group the bank; a snippet can be dropped into any section. +type CoverSnippet struct { + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` + Text string `gorm:"type:text;not null" json:"text"` + Section string `gorm:"not null;default:''" json:"section"` +} diff --git a/backend/services/database.go b/backend/services/database.go index 3bc9cd2..906ce6b 100644 --- a/backend/services/database.go +++ b/backend/services/database.go @@ -56,6 +56,8 @@ func migrateDatabase(db *gorm.DB) error { &models.Background{}, &models.Layout{}, &models.Component{}, + &models.CoverLetter{}, + &models.CoverSnippet{}, ) if err != nil { return err diff --git a/vue/README.md b/vue/README.md index 8a3935b..9e3bea8 100644 --- a/vue/README.md +++ b/vue/README.md @@ -381,7 +381,7 @@ in its header comment; the summary: | `views/home/BadApple.vue` | unfinished ASCII video player; not imported | | `views/CV/CVProgramming.vue` | live — the only CV template listed in `CV.vue` | | `views/CV/CV{General,Backend,Frontend,Security,Electrical,Hospitality,Analyst,Temp}.vue` | commented out of `CV.vue`'s list; unreachable | -| `views/unused/CoverLetters.vue` | **live** despite the directory — it is the "Cover Letter" tab on `/cv` | +| `views/CV/CoverLetters.vue` (+ `CoverSnippetBank.vue`, `coverLetter.js`) | live — the "Cover Letter" tab on `/cv`. Sections of draggable paragraphs; an admin also gets saved letters (`CoverLetter`) and a paragraph bank (`CoverSnippet`), both `@admin` | | `views/unused/Notes.vue` | no route points at it; not imported | | `components/util/{MusicPlayer,ObjectTable}.vue` | not imported | | `components/elle/Elle.vue`, `components/borders/UtenaFrame.vue` | decorative; not imported | diff --git a/vue/src/stores/coverLetters.js b/vue/src/stores/coverLetters.js new file mode 100644 index 0000000..5f9e6bd --- /dev/null +++ b/vue/src/stores/coverLetters.js @@ -0,0 +1,28 @@ +/** + * Saved cover letters (the `CoverLetter` GraphQL type) for the /cv Cover + * Letter tab — full CRUD, built on createCrudStore(). + * + * `body` is the whole letter as a JSON string; views/CV/coverLetter.js owns + * its shape (parseBody / serialize), the server only checks it is an object. + * + * Admin only, so nothing fetches it until views/CV/CoverLetters.vue sees an + * admin signed in. + */ + +import { createCrudStore } from "@/stores/createCrudStore"; + +const COVER_LETTER_FIELDS = ` + id + name + body + updatedAt +`; + +export const useCoverLettersStore = createCrudStore("coverLetters", { + type: "CoverLetter", + list: "coverLetters", + fields: COVER_LETTER_FIELDS, + // The list query is most recently updated first, so a new letter goes on top. + insert: "prepend", + deleteReturns: "object", +}); diff --git a/vue/src/stores/coverSnippets.js b/vue/src/stores/coverSnippets.js new file mode 100644 index 0000000..531ff83 --- /dev/null +++ b/vue/src/stores/coverSnippets.js @@ -0,0 +1,29 @@ +/** + * The cover-letter paragraph bank (the `CoverSnippet` GraphQL type): reusable + * paragraphs dragged into a letter as copies — full CRUD, built on + * createCrudStore(). + * + * `section` is the title of the section a snippet was written for and only + * groups the bank (views/CV/CoverSnippetBank.vue); editing a snippet never + * changes letters it was already dropped into. + * + * Admin only, like stores/coverLetters.js. + */ + +import { createCrudStore } from "@/stores/createCrudStore"; + +const COVER_SNIPPET_FIELDS = ` + id + text + section + createdAt +`; + +export const useCoverSnippetsStore = createCrudStore("coverSnippets", { + type: "CoverSnippet", + list: "coverSnippets", + fields: COVER_SNIPPET_FIELDS, + // The bank groups by section itself, so where a new one lands doesn't matter. + insert: "prepend", + deleteReturns: "object", +}); diff --git a/vue/src/views/CV/CoverLetters.vue b/vue/src/views/CV/CoverLetters.vue index 84d0e7f..8dd37c0 100644 --- a/vue/src/views/CV/CoverLetters.vue +++ b/vue/src/views/CV/CoverLetters.vue @@ -1,92 +1,547 @@ diff --git a/vue/src/views/CV/CoverSnippetBank.vue b/vue/src/views/CV/CoverSnippetBank.vue new file mode 100644 index 0000000..de312fb --- /dev/null +++ b/vue/src/views/CV/CoverSnippetBank.vue @@ -0,0 +1,324 @@ + + + + + diff --git a/vue/src/views/CV/coverLetter.js b/vue/src/views/CV/coverLetter.js new file mode 100644 index 0000000..7992f5d --- /dev/null +++ b/vue/src/views/CV/coverLetter.js @@ -0,0 +1,133 @@ +/** + * The cover letter as data, with no Vue in it: the default letter, the JSON + * body stored in a CoverLetter row (stores/coverLetters.js), and the moves + * the drag and drop in CoverLetters.vue makes. + * + * Body shape (v: 1): + * { v, name, phone, email, role, signoff, + * sections: [{ id, title, paragraphs: [{ id, text }] }] } + * + * Every section and paragraph carries an id because the template keys its + * v-for on it. Keying on the index would leave a contenteditable showing the + * old text after a reorder, since Vue would reuse the element in place. + * + * A position is `{ section, index }`: a section's index and a paragraph's + * index inside it. `index` may equal the paragraph count, meaning "at the end". + */ + +export const BODY_VERSION = 1; + +/** A short id, unique enough within one letter. crypto.randomUUID would do, + * but it is missing outside a secure context (the dev stack over a LAN IP). */ +export function newId() { + return Math.random().toString(36).slice(2, 10) + Date.now().toString(36); +} + +export function newParagraph(text = "New paragraph...") { + return { id: newId(), text }; +} + +export function newSection(title = "New section", texts = []) { + return { id: newId(), title, paragraphs: texts.map(newParagraph) }; +} + +/** The blank template a visitor sees, and what "New" starts from. */ +export function newLetter() { + return { + v: BODY_VERSION, + name: "Adam French", + phone: "+447563266931", + email: "adam.a.french@outlook.com", + role: "Job title / role", + signoff: "Thank you for reading - Adam F", + sections: [ + newSection("Why the company", ["Why I'm interested in the company..."]), + newSection("Why I fit", ["Why I'm a strong fit for the role..."]), + newSection("Experience", ["Relevant experience and background..."]), + ], + }; +} + +const str = (v, fallback) => (typeof v === "string" ? v : fallback); + +/** + * Read a stored body back into a letter. Anything missing or malformed + * falls back to the default field by field, so a hand-edited or older row + * still opens rather than blanking the page; ids are regenerated if absent. + */ +export function parseBody(json) { + const base = newLetter(); + let raw; + try { + raw = JSON.parse(json); + } catch { + return base; + } + if (!raw || typeof raw !== "object") return base; + const sections = Array.isArray(raw.sections) + ? raw.sections + .filter((s) => s && typeof s === "object") + .map((s) => ({ + id: str(s.id, newId()), + title: str(s.title, ""), + paragraphs: Array.isArray(s.paragraphs) + ? s.paragraphs + .filter((p) => p && typeof p.text === "string") + .map((p) => ({ id: str(p.id, newId()), text: p.text })) + : [], + })) + : base.sections; + return { + v: BODY_VERSION, + name: str(raw.name, base.name), + phone: str(raw.phone, base.phone), + email: str(raw.email, base.email), + role: str(raw.role, base.role), + signoff: str(raw.signoff, base.signoff), + sections, + }; +} + +/** The JSON stored as a CoverLetter's body. Also what the "unsaved" marker + * compares, so the key order here must stay fixed. */ +export function serialize(letter) { + return JSON.stringify({ + v: BODY_VERSION, + name: letter.name, + phone: letter.phone, + email: letter.email, + role: letter.role, + signoff: letter.signoff, + sections: letter.sections.map((s) => ({ + id: s.id, + title: s.title, + paragraphs: s.paragraphs.map((p) => ({ id: p.id, text: p.text })), + })), + }); +} + +/** + * Move the paragraph at `from` to `to`, both positions as they are before the + * move. Moving down within one section shifts the target up by one once the + * paragraph has been taken out, which is corrected here so a drop lands where + * the indicator showed. + */ +export function moveParagraph(letter, from, to) { + const src = letter.sections[from.section]; + const dst = letter.sections[to.section]; + if (!src || !dst || !src.paragraphs[from.index]) return; + let index = to.index; + if (from.section === to.section) { + if (index === from.index || index === from.index + 1) return; + if (index > from.index) index -= 1; + } + const [para] = src.paragraphs.splice(from.index, 1); + dst.paragraphs.splice(index, 0, para); +} + +/** Put a new paragraph holding `text` at `to`. */ +export function insertParagraph(letter, to, text) { + const dst = letter.sections[to.section]; + if (!dst) return; + dst.paragraphs.splice(to.index, 0, newParagraph(text)); +}