diff --git a/CLAUDE.md b/CLAUDE.md index 8b98b7c..a892669 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -73,7 +73,7 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi. - `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) +- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box) - `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`), the `.env` registry (`env_manager.go`), DB seeding. There is no Claude client in Go any more @@ -81,8 +81,8 @@ Dockerized multi-service personal website self-hosted on a Raspberry Pi. - `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/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places. `createCrudStore.js` is the factory behind places; `createMirrorStore.js` is the one behind the home-page slices -- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines) +- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes. `createCrudStore.js` is the factory behind places and boxes; `createMirrorStore.js` is the one behind the home-page slices +- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. 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`. diff --git a/backend/gqlgen.yml b/backend/gqlgen.yml index 62c8bee..fc358d1 100644 --- a/backend/gqlgen.yml +++ b/backend/gqlgen.yml @@ -76,3 +76,9 @@ models: fields: deletedAt: resolver: false + Box: + model: + - adam-french.co.uk/backend/models.Box + fields: + deletedAt: + resolver: false diff --git a/backend/graph/box.resolvers.go b/backend/graph/box.resolvers.go new file mode 100644 index 0000000..1bafbef --- /dev/null +++ b/backend/graph/box.resolvers.go @@ -0,0 +1,110 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver +// implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.95 + +import ( + "context" + + "adam-french.co.uk/backend/graph/model" + "adam-french.co.uk/backend/models" +) + +// CreateBox is the resolver for the createBox field. +func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxInput) (*models.Box, error) { + // Framed defaults to true here rather than in the gorm tag — see the + // comment on models.Box.Framed. Sizes not supplied fall back to the + // same 300x200 the column defaults use. + box := models.Box{ + Kind: input.Kind, + Widget: input.Widget, + HTML: input.HTML, + Title: input.Title, + W: 300, + H: 200, + Framed: true, + } + setInt(&box.X, input.X) + setInt(&box.Y, input.Y) + setInt(&box.W, input.W) + setInt(&box.H, input.H) + setInt(&box.Z, input.Z) + if input.Framed != nil { + box.Framed = *input.Framed + } + if input.HideOnMobile != nil { + box.HideOnMobile = *input.HideOnMobile + } + if err := validateBox(&box); err != nil { + return nil, err + } + if err := r.Store.DB.Create(&box).Error; err != nil { + return nil, err + } + return &box, nil +} + +// UpdateBox is the resolver for the updateBox field. +func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) { + // Partial update: nil fields are left alone. The canvas sends only the + // geometry after a drag and only the html after an edit, so this is + // what keeps the two from overwriting each other. Kind is not + // updatable — switching a widget box to html is a delete and create. + var box models.Box + if err := r.Store.DB.First(&box, id).Error; err != nil { + return nil, err + } + if input.Widget != nil { + box.Widget = input.Widget + } + if input.HTML != nil { + box.HTML = input.HTML + } + if input.Title != nil { + box.Title = input.Title + } + setInt(&box.X, input.X) + setInt(&box.Y, input.Y) + setInt(&box.W, input.W) + setInt(&box.H, input.H) + setInt(&box.Z, input.Z) + if input.Framed != nil { + box.Framed = *input.Framed + } + if input.HideOnMobile != nil { + box.HideOnMobile = *input.HideOnMobile + } + if err := validateBox(&box); err != nil { + return nil, err + } + if err := r.Store.DB.Save(&box).Error; err != nil { + return nil, err + } + return &box, nil +} + +// DeleteBox is the resolver for the deleteBox field. +func (r *mutationResolver) DeleteBox(ctx context.Context, id int) (*models.Box, error) { + var box models.Box + if err := r.Store.DB.First(&box, id).Error; err != nil { + return nil, err + } + if err := r.Store.DB.Delete(&box).Error; err != nil { + return nil, err + } + return &box, nil +} + +// Boxes is the resolver for the boxes field. +func (r *queryResolver) Boxes(ctx context.Context) ([]*models.Box, error) { + // Public: this is the page layout every visitor loads. Ordered by z so + // DOM order matches stacking order, which keeps tab order sensible. + var boxes []models.Box + if err := r.Store.DB.Order("z ASC, id ASC").Find(&boxes).Error; err != nil { + return nil, err + } + return ptrs(boxes), nil +} + diff --git a/backend/graph/box_helpers.go b/backend/graph/box_helpers.go new file mode 100644 index 0000000..4114f30 --- /dev/null +++ b/backend/graph/box_helpers.go @@ -0,0 +1,44 @@ +package graph + +// Hand-written helpers for box.resolvers.go. Kept out of that file because +// gqlgen moves unknown code in a resolvers file to the end, under a warning +// comment, on every regenerate. + +import ( + "errors" + + "adam-french.co.uk/backend/models" +) + +// minBoxSize stops a box being resized to nothing, after which it could not +// be grabbed again on the canvas. +const minBoxSize = 40 + +func setInt(dst *int, src *int) { + if src != nil { + *dst = *src + } +} + +// validateBox checks the fields a box needs to render and clamps geometry +// rather than rejecting it, because a drag that overshoots the canvas edge +// should land at the edge, not fail. +func validateBox(box *models.Box) error { + switch box.Kind { + case "widget": + if box.Widget == nil || *box.Widget == "" { + return errors.New("a widget box needs a widget name") + } + case "html": + if box.HTML == nil { + return errors.New("an html box needs html") + } + default: + return errors.New(`box kind must be "widget" or "html"`) + } + box.X = max(box.X, 0) + box.Y = max(box.Y, 0) + box.W = max(box.W, minBoxSize) + box.H = max(box.H, minBoxSize) + return nil +} diff --git a/backend/graph/box_helpers_test.go b/backend/graph/box_helpers_test.go new file mode 100644 index 0000000..c41c517 --- /dev/null +++ b/backend/graph/box_helpers_test.go @@ -0,0 +1,42 @@ +package graph + +import ( + "testing" + + "adam-french.co.uk/backend/models" +) + +func TestValidateBox(t *testing.T) { + str := func(s string) *string { return &s } + + for _, c := range []struct { + name string + box models.Box + wantErr bool + }{ + {"widget with a name", models.Box{Kind: "widget", Widget: str("Chat")}, false}, + {"widget without a name", models.Box{Kind: "widget"}, true}, + {"widget with an empty name", models.Box{Kind: "widget", Widget: str("")}, true}, + {"html with html", models.Box{Kind: "html", HTML: str("

hi

")}, false}, + {"html with empty html", models.Box{Kind: "html", HTML: str("")}, false}, + {"html without html", models.Box{Kind: "html"}, true}, + {"unknown kind", models.Box{Kind: "iframe", HTML: str("x")}, true}, + } { + t.Run(c.name, func(t *testing.T) { + err := validateBox(&c.box) + if (err != nil) != c.wantErr { + t.Fatalf("err = %v, wantErr %v", err, c.wantErr) + } + }) + } + + // Geometry is clamped, not rejected: a drag past the canvas edge lands + // at the edge, and a box can never shrink below a grabbable size. + box := models.Box{Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0} + if err := validateBox(&box); err != nil { + t.Fatal(err) + } + if box.X != 0 || box.Y != 0 || box.W != minBoxSize || box.H != minBoxSize { + t.Fatalf("clamped to %d,%d %dx%d; want 0,0 %dx%d", box.X, box.Y, box.W, box.H, minBoxSize, minBoxSize) + } +} diff --git a/backend/graph/generated.go b/backend/graph/generated.go index 9248373..3b52c60 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -65,6 +65,23 @@ type ComplexityRoot struct { UpdatedAt func(childComplexity int) int } + Box struct { + CreatedAt func(childComplexity int) int + Framed func(childComplexity int) int + H func(childComplexity int) int + HTML func(childComplexity int) int + HideOnMobile func(childComplexity int) int + ID func(childComplexity int) int + Kind func(childComplexity int) int + Title func(childComplexity int) int + UpdatedAt func(childComplexity int) int + W func(childComplexity int) int + Widget func(childComplexity int) int + X func(childComplexity int) int + Y func(childComplexity int) int + Z func(childComplexity int) int + } + Favorite struct { CreatedAt func(childComplexity int) int ID func(childComplexity int) int @@ -95,11 +112,13 @@ type ComplexityRoot struct { Mutation struct { CreateActivity func(childComplexity int, input model.CreateActivityInput) int CreateBookmark func(childComplexity int, input model.CreateBookmarkInput) int + CreateBox func(childComplexity int, input model.CreateBoxInput) int CreateFavorite func(childComplexity int, input model.CreateFavoriteInput) int CreatePlace func(childComplexity int, input model.CreatePlaceInput) int CreatePost func(childComplexity int, input model.CreatePostInput) int CreateUser func(childComplexity int, input model.CreateUserInput) int DeleteBookmark func(childComplexity int, id int) int + DeleteBox func(childComplexity int, id int) int DeletePlace func(childComplexity int, id int) int DeletePost func(childComplexity int, id int) int DeleteUser func(childComplexity int, id int) int @@ -107,6 +126,7 @@ type ComplexityRoot struct { Logout func(childComplexity int) int RefreshToken func(childComplexity int) int SetUserAdmin func(childComplexity int, id int, admin bool) int + UpdateBox func(childComplexity int, id int, input model.UpdateBoxInput) int UpdatePlace func(childComplexity int, id int, input model.UpdatePlaceInput) int UpdatePost func(childComplexity int, id int, input model.UpdatePostInput) int } @@ -137,6 +157,7 @@ type ComplexityRoot struct { Query struct { Activities func(childComplexity int) int Bookmarks func(childComplexity int) int + Boxes func(childComplexity int) int Favorites func(childComplexity int) int GiteaFeed func(childComplexity int) int Me func(childComplexity int) int @@ -228,6 +249,9 @@ type MutationResolver interface { RefreshToken(ctx context.Context) (*model.AuthPayload, error) CreateBookmark(ctx context.Context, input model.CreateBookmarkInput) (*models.Bookmark, error) DeleteBookmark(ctx context.Context, id int) (*models.Bookmark, error) + CreateBox(ctx context.Context, input model.CreateBoxInput) (*models.Box, error) + UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) + DeleteBox(ctx context.Context, id int) (*models.Box, error) CreateFavorite(ctx context.Context, input model.CreateFavoriteInput) (*models.Favorite, error) CreatePlace(ctx context.Context, input model.CreatePlaceInput) (*models.Place, error) UpdatePlace(ctx context.Context, id int, input model.UpdatePlaceInput) (*models.Place, error) @@ -243,6 +267,7 @@ type QueryResolver interface { Activities(ctx context.Context) ([]*models.Activity, error) Me(ctx context.Context) (*models.User, error) Bookmarks(ctx context.Context) ([]*models.Bookmark, error) + Boxes(ctx context.Context) ([]*models.Box, error) Favorites(ctx context.Context) ([]*models.Favorite, error) GiteaFeed(ctx context.Context) (*model.GiteaFeedItem, error) Messages(ctx context.Context) ([]*models.Message, error) @@ -361,6 +386,91 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Bookmark.UpdatedAt(childComplexity), true + case "Box.createdAt": + if e.ComplexityRoot.Box.CreatedAt == nil { + break + } + + return e.ComplexityRoot.Box.CreatedAt(childComplexity), true + case "Box.framed": + if e.ComplexityRoot.Box.Framed == nil { + break + } + + return e.ComplexityRoot.Box.Framed(childComplexity), true + case "Box.h": + if e.ComplexityRoot.Box.H == nil { + break + } + + return e.ComplexityRoot.Box.H(childComplexity), true + case "Box.html": + if e.ComplexityRoot.Box.HTML == nil { + break + } + + return e.ComplexityRoot.Box.HTML(childComplexity), true + case "Box.hideOnMobile": + if e.ComplexityRoot.Box.HideOnMobile == nil { + break + } + + return e.ComplexityRoot.Box.HideOnMobile(childComplexity), true + case "Box.id": + if e.ComplexityRoot.Box.ID == nil { + break + } + + return e.ComplexityRoot.Box.ID(childComplexity), true + case "Box.kind": + if e.ComplexityRoot.Box.Kind == nil { + break + } + + return e.ComplexityRoot.Box.Kind(childComplexity), true + case "Box.title": + if e.ComplexityRoot.Box.Title == nil { + break + } + + return e.ComplexityRoot.Box.Title(childComplexity), true + case "Box.updatedAt": + if e.ComplexityRoot.Box.UpdatedAt == nil { + break + } + + return e.ComplexityRoot.Box.UpdatedAt(childComplexity), true + case "Box.w": + if e.ComplexityRoot.Box.W == nil { + break + } + + return e.ComplexityRoot.Box.W(childComplexity), true + case "Box.widget": + if e.ComplexityRoot.Box.Widget == nil { + break + } + + return e.ComplexityRoot.Box.Widget(childComplexity), true + case "Box.x": + if e.ComplexityRoot.Box.X == nil { + break + } + + return e.ComplexityRoot.Box.X(childComplexity), true + case "Box.y": + if e.ComplexityRoot.Box.Y == nil { + break + } + + return e.ComplexityRoot.Box.Y(childComplexity), true + case "Box.z": + if e.ComplexityRoot.Box.Z == nil { + break + } + + return e.ComplexityRoot.Box.Z(childComplexity), true + case "Favorite.createdAt": if e.ComplexityRoot.Favorite.CreatedAt == nil { break @@ -494,6 +604,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.CreateBookmark(childComplexity, args["input"].(model.CreateBookmarkInput)), true + case "Mutation.createBox": + if e.ComplexityRoot.Mutation.CreateBox == nil { + break + } + + args, err := ec.field_Mutation_createBox_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreateBox(childComplexity, args["input"].(model.CreateBoxInput)), true case "Mutation.createFavorite": if e.ComplexityRoot.Mutation.CreateFavorite == nil { break @@ -549,6 +670,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteBookmark(childComplexity, args["id"].(int)), true + case "Mutation.deleteBox": + if e.ComplexityRoot.Mutation.DeleteBox == nil { + break + } + + args, err := ec.field_Mutation_deleteBox_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeleteBox(childComplexity, args["id"].(int)), true case "Mutation.deletePlace": if e.ComplexityRoot.Mutation.DeletePlace == nil { break @@ -616,6 +748,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.SetUserAdmin(childComplexity, args["id"].(int), args["admin"].(bool)), true + case "Mutation.updateBox": + if e.ComplexityRoot.Mutation.UpdateBox == nil { + break + } + + args, err := ec.field_Mutation_updateBox_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdateBox(childComplexity, args["id"].(int), args["input"].(model.UpdateBoxInput)), true case "Mutation.updatePlace": if e.ComplexityRoot.Mutation.UpdatePlace == nil { break @@ -755,6 +898,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Query.Bookmarks(childComplexity), true + case "Query.boxes": + if e.ComplexityRoot.Query.Boxes == nil { + break + } + + return e.ComplexityRoot.Query.Boxes(childComplexity), true case "Query.favorites": if e.ComplexityRoot.Query.Favorites == nil { break @@ -1051,11 +1200,13 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { inputUnmarshalMap := graphql.BuildUnmarshalerMap( ec.unmarshalInputCreateActivityInput, ec.unmarshalInputCreateBookmarkInput, + ec.unmarshalInputCreateBoxInput, ec.unmarshalInputCreateFavoriteInput, ec.unmarshalInputCreatePlaceInput, ec.unmarshalInputCreatePostInput, ec.unmarshalInputCreateUserInput, ec.unmarshalInputLoginInput, + ec.unmarshalInputUpdateBoxInput, ec.unmarshalInputUpdatePlaceInput, ec.unmarshalInputUpdatePostInput, ) @@ -1132,7 +1283,7 @@ func newExecutionContext( } } -//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/bookmark.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/message.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/bookmark.graphql" "schema/box.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/message.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 { @@ -1147,6 +1298,7 @@ var sources = []*ast.Source{ {Name: "schema/activity.graphql", Input: sourceData("schema/activity.graphql"), BuiltIn: false}, {Name: "schema/auth.graphql", Input: sourceData("schema/auth.graphql"), BuiltIn: false}, {Name: "schema/bookmark.graphql", Input: sourceData("schema/bookmark.graphql"), BuiltIn: false}, + {Name: "schema/box.graphql", Input: sourceData("schema/box.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/message.graphql", Input: sourceData("schema/message.graphql"), BuiltIn: false}, @@ -1208,6 +1360,40 @@ func (ec *executionContext) childFields_Bookmark(ctx context.Context, field grap return nil, fmt.Errorf("no field named %q was found under type Bookmark", field.Name) } +func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Box_id(ctx, field) + case "createdAt": + return ec.fieldContext_Box_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Box_updatedAt(ctx, field) + case "kind": + return ec.fieldContext_Box_kind(ctx, field) + case "widget": + return ec.fieldContext_Box_widget(ctx, field) + case "html": + return ec.fieldContext_Box_html(ctx, field) + case "title": + return ec.fieldContext_Box_title(ctx, field) + case "x": + return ec.fieldContext_Box_x(ctx, field) + case "y": + return ec.fieldContext_Box_y(ctx, field) + case "w": + return ec.fieldContext_Box_w(ctx, field) + case "h": + return ec.fieldContext_Box_h(ctx, field) + case "z": + return ec.fieldContext_Box_z(ctx, field) + case "framed": + return ec.fieldContext_Box_framed(ctx, field) + case "hideOnMobile": + return ec.fieldContext_Box_hideOnMobile(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Box", field.Name) +} + func (ec *executionContext) childFields_Favorite(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": @@ -1572,6 +1758,20 @@ func (ec *executionContext) field_Mutation_createBookmark_args(ctx context.Conte return args, nil } +func (ec *executionContext) field_Mutation_createBox_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.CreateBoxInput, error) { + return ec.unmarshalNCreateBoxInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateBoxInput(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{} @@ -1642,6 +1842,20 @@ func (ec *executionContext) field_Mutation_deleteBookmark_args(ctx context.Conte return args, nil } +func (ec *executionContext) field_Mutation_deleteBox_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_deletePlace_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -1720,6 +1934,28 @@ func (ec *executionContext) field_Mutation_setUserAdmin_args(ctx context.Context return args, nil } +func (ec *executionContext) field_Mutation_updateBox_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.UpdateBoxInput, error) { + return ec.unmarshalNUpdateBoxInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateBoxInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updatePlace_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2174,6 +2410,328 @@ func (ec *executionContext) fieldContext_Bookmark_link(_ context.Context, field return graphql.NewScalarFieldContext("Bookmark", field, false, false, errors.New("field of type String does not have child fields")) } +func (ec *executionContext) _Box_id(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_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_Box_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _Box_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_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_Box_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Box_updatedAt(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_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_Box_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Box_kind(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_kind(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Kind, 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_Box_kind(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Box_widget(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_widget(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Widget, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *string) graphql.Marshaler { + return ec.marshalOString2ᚖstring(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Box_widget(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Box_html(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_html(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.HTML, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *string) graphql.Marshaler { + return ec.marshalOString2ᚖstring(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Box_html(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Box_title(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_title(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Title, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *string) graphql.Marshaler { + return ec.marshalOString2ᚖstring(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Box_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Box_x(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_x(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.X, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_x(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Box_y(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_y(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Y, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_y(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Box_w(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_w(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.W, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_w(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Box_h(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_h(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.H, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_h(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Box_z(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_z(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Z, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_z(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Box_framed(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_framed(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Framed, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_framed(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields")) +} + +func (ec *executionContext) _Box_hideOnMobile(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_hideOnMobile(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.HideOnMobile, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Box_hideOnMobile(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean 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, @@ -2858,6 +3416,177 @@ func (ec *executionContext) fieldContext_Mutation_deleteBookmark(ctx context.Con return fc, nil } +func (ec *executionContext) _Mutation_createBox(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_createBox(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreateBox(ctx, fc.Args["input"].(model.CreateBoxInput)) + }, + 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.Box + 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.Box) graphql.Marshaler { + return ec.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createBox(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_Box(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_createBox_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateBox(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_updateBox(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdateBox(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdateBoxInput)) + }, + 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.Box + 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.Box) graphql.Marshaler { + return ec.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updateBox(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_Box(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_updateBox_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteBox(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_deleteBox(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeleteBox(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.Box + 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.Box) graphql.Marshaler { + return ec.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deleteBox(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_Box(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_deleteBox_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, @@ -3924,6 +4653,38 @@ func (ec *executionContext) fieldContext_Query_bookmarks(_ context.Context, fiel return fc, nil } +func (ec *executionContext) _Query_boxes(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_boxes(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().Boxes(ctx) + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v []*models.Box) graphql.Marshaler { + return ec.marshalNBox2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBoxᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_boxes(_ 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_Box(ctx, field) + }, + } + return fc, nil +} + func (ec *executionContext) _Query_favorites(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -6361,6 +7122,106 @@ func (ec *executionContext) unmarshalInputCreateBookmarkInput(ctx context.Contex return it, nil } +func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, obj any) (model.CreateBoxInput, error) { + var it model.CreateBoxInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "kind": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("kind")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Kind = data + case "widget": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("widget")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Widget = data + case "html": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("html")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.HTML = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "x": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("x")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.X = data + case "y": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("y")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Y = data + case "w": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("w")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.W = data + case "h": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("h")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.H = data + case "z": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("z")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Z = data + case "framed": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("framed")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Framed = data + case "hideOnMobile": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HideOnMobile = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputCreateFavoriteInput(ctx context.Context, obj any) (model.CreateFavoriteInput, error) { var it model.CreateFavoriteInput if obj == nil { @@ -6595,6 +7456,99 @@ func (ec *executionContext) unmarshalInputLoginInput(ctx context.Context, obj an return it, nil } +func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, obj any) (model.UpdateBoxInput, error) { + var it model.UpdateBoxInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "widget": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("widget")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Widget = data + case "html": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("html")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.HTML = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "x": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("x")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.X = data + case "y": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("y")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Y = data + case "w": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("w")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.W = data + case "h": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("h")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.H = data + case "z": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("z")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.Z = data + case "framed": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("framed")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Framed = data + case "hideOnMobile": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("hideOnMobile")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.HideOnMobile = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputUpdatePlaceInput(ctx context.Context, obj any) (model.UpdatePlaceInput, error) { var it model.UpdatePlaceInput if obj == nil { @@ -6883,6 +7837,109 @@ func (ec *executionContext) _Bookmark(ctx context.Context, sel ast.SelectionSet, return out } +var boxImplementors = []string{"Box"} + +func (ec *executionContext) _Box(ctx context.Context, sel ast.SelectionSet, obj *models.Box) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, boxImplementors) + + 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("Box") + case "id": + out.Values[i] = ec._Box_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "createdAt": + out.Values[i] = ec._Box_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updatedAt": + out.Values[i] = ec._Box_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "kind": + out.Values[i] = ec._Box_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "widget": + out.Values[i] = ec._Box_widget(ctx, field, obj) + if out.Values[i] == graphql.RequiredNull { + out.Invalids++ + } + case "html": + out.Values[i] = ec._Box_html(ctx, field, obj) + if out.Values[i] == graphql.RequiredNull { + out.Invalids++ + } + case "title": + out.Values[i] = ec._Box_title(ctx, field, obj) + if out.Values[i] == graphql.RequiredNull { + out.Invalids++ + } + case "x": + out.Values[i] = ec._Box_x(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "y": + out.Values[i] = ec._Box_y(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "w": + out.Values[i] = ec._Box_w(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "h": + out.Values[i] = ec._Box_h(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "z": + out.Values[i] = ec._Box_z(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "framed": + out.Values[i] = ec._Box_framed(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "hideOnMobile": + out.Values[i] = ec._Box_hideOnMobile(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 { @@ -7167,6 +8224,27 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createBox": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createBox(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updateBox": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateBox(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteBox": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteBox(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) @@ -7494,6 +8572,28 @@ 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 "boxes": + 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_boxes(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 @@ -8832,6 +9932,32 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } +func (ec *executionContext) marshalNBox2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBoxᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Box) 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.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx context.Context, sel ast.SelectionSet, v *models.Box) 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._Box(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) @@ -8842,6 +9968,11 @@ func (ec *executionContext) unmarshalNCreateBookmarkInput2adamᚑfrenchᚗcoᚗu return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateBoxInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateBoxInput(ctx context.Context, v any) (model.CreateBoxInput, error) { + res, err := ec.unmarshalInputCreateBoxInput(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) @@ -9201,6 +10332,11 @@ func (ec *executionContext) marshalNTime2timeᚐTime(ctx context.Context, sel as return res } +func (ec *executionContext) unmarshalNUpdateBoxInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateBoxInput(ctx context.Context, v any) (model.UpdateBoxInput, error) { + res, err := ec.unmarshalInputUpdateBoxInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNUpdatePlaceInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdatePlaceInput(ctx context.Context, v any) (model.UpdatePlaceInput, error) { res, err := ec.unmarshalInputUpdatePlaceInput(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 597d650..199418f 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -24,6 +24,20 @@ type CreateBookmarkInput struct { Link string `json:"link"` } +type CreateBoxInput struct { + Kind string `json:"kind"` + Widget *string `json:"widget,omitempty"` + HTML *string `json:"html,omitempty"` + Title *string `json:"title,omitempty"` + X *int `json:"x,omitempty"` + Y *int `json:"y,omitempty"` + W *int `json:"w,omitempty"` + H *int `json:"h,omitempty"` + Z *int `json:"z,omitempty"` + Framed *bool `json:"framed,omitempty"` + HideOnMobile *bool `json:"hideOnMobile,omitempty"` +} + type CreateFavoriteInput struct { Type string `json:"type"` Name string `json:"name"` @@ -113,6 +127,19 @@ type SteamStatus struct { RecentGames []*SteamGame `json:"recentGames"` } +type UpdateBoxInput struct { + Widget *string `json:"widget,omitempty"` + HTML *string `json:"html,omitempty"` + Title *string `json:"title,omitempty"` + X *int `json:"x,omitempty"` + Y *int `json:"y,omitempty"` + W *int `json:"w,omitempty"` + H *int `json:"h,omitempty"` + Z *int `json:"z,omitempty"` + Framed *bool `json:"framed,omitempty"` + HideOnMobile *bool `json:"hideOnMobile,omitempty"` +} + type UpdatePlaceInput struct { Title *string `json:"title,omitempty"` Location *string `json:"location,omitempty"` diff --git a/backend/graph/schema/box.graphql b/backend/graph/schema/box.graphql new file mode 100644 index 0000000..360493c --- /dev/null +++ b/backend/graph/schema/box.graphql @@ -0,0 +1,60 @@ +# Boxes on the home page canvas (/stp). Anyone may read the layout — it is +# the page — but only an admin may change it. x/y/w/h are px on a fixed +# 1400px-wide design canvas; see models.Box. +# +# kind is "widget" (a built-in Vue component named by `widget`) or "html" +# (`html` rendered in a sandboxed iframe on the front end). + +type Box { + id: ID! + createdAt: Time! + updatedAt: Time! + kind: String! + widget: String + html: String + title: String + x: Int! + y: Int! + w: Int! + h: Int! + z: Int! + framed: Boolean! + hideOnMobile: Boolean! +} + +input CreateBoxInput { + kind: String! + widget: String + html: String + title: String + x: Int + y: Int + w: Int + h: Int + z: Int + framed: Boolean + hideOnMobile: Boolean +} + +input UpdateBoxInput { + widget: String + html: String + title: String + x: Int + y: Int + w: Int + h: Int + z: Int + framed: Boolean + hideOnMobile: Boolean +} + +extend type Query { + boxes: [Box!]! +} + +extend type Mutation { + createBox(input: CreateBoxInput!): Box! @admin + updateBox(id: ID!, input: UpdateBoxInput!): Box! @admin + deleteBox(id: ID!): Box! @admin +} diff --git a/backend/models/models.go b/backend/models/models.go index 4e07a59..84bc302 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -155,3 +155,30 @@ type Place struct { Priority int `gorm:"default:0" json:"priority"` Done bool `gorm:"default:false" json:"done"` } + +// Box is one panel on the home page canvas (/stp). Its position and size are +// in px on a fixed 1400px-wide design canvas, which the page scales down on +// narrower screens — so the stored numbers mean the same thing for every +// visitor. Kind "widget" renders a built-in Vue component named by Widget; +// kind "html" renders HTML in a sandboxed iframe on the front end, which is +// what makes storing admin-authored script here acceptable. +type Box struct { + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"` + Kind string `gorm:"not null" json:"kind"` + Widget *string `json:"widget"` + HTML *string `json:"html"` + Title *string `json:"title"` + X int `gorm:"not null;default:0" json:"x"` + Y int `gorm:"not null;default:0" json:"y"` + W int `gorm:"not null;default:300" json:"w"` + H int `gorm:"not null;default:200" json:"h"` + Z int `gorm:"not null;default:0" json:"z"` + // No gorm default on Framed: GORM omits zero values for defaulted columns + // on insert, so default:true would turn an explicit false into true. + // CreateBox applies the true default itself. + Framed bool `gorm:"not null" json:"framed"` + HideOnMobile bool `gorm:"not null;default:false" json:"hideOnMobile"` +} diff --git a/backend/services/database.go b/backend/services/database.go index 1dc5f67..250558e 100644 --- a/backend/services/database.go +++ b/backend/services/database.go @@ -51,6 +51,7 @@ func migrateDatabase(db *gorm.DB) error { &models.Message{}, &models.Bookmark{}, &models.Place{}, + &models.Box{}, ) if err != nil { return err diff --git a/vue/README.md b/vue/README.md index bc31540..2aad099 100644 --- a/vue/README.md +++ b/vue/README.md @@ -66,7 +66,7 @@ Two layout shells, defined in `src/router/index.js`: | Path | Layout | Notes | | --- | --- | --- | | `/` | DefaultLayout | Landing page (statically imported — it's the first paint) | -| `/stp` | DefaultLayout | The personal home page: the widget grid | +| `/stp` | DefaultLayout | The personal home page: an admin-editable canvas of boxes (`views/home3/`, see "The /stp canvas" below) | | `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` | | `/automata`, `/hotels`, `/shrines/*` | DefaultLayout | | | `/cv` | CVLayout | Light print theme. Its Jobs button goes to `/jobs/`, the separate job tracker app (`adamf/job-tracker`); nginx redirects the old `/cv/jobs` and `/cv/leads` there | @@ -169,6 +169,7 @@ true only once a fetch has succeeded, meaning the data is real. Waiting on | `auth` | current user (`ensureLoaded()`, see Routing), plus login/logout mutations | | `posts`, `favorites`, `activity`, `songs`, `steam` | mirror one slice of `homeData` via an `immediate` watch, and keep a placeholder value until real data arrives | | `places` | CRUD via `createCrudStore`; sign-in only, so it is fetched lazily | +| `boxes` | CRUD via `createCrudStore`; the `/stp` canvas layout. Public read, admin write | | `messages` | the chat WebSocket — not GraphQL at all | | `models` | dormant; not imported anywhere | @@ -193,6 +194,40 @@ Two factories keep the repeated shapes in one place: failure on `error`; the mutations throw, so the form that called them can show the message and keep what was typed. +## The /stp canvas + +`/stp` is a set of **boxes** (`Box` in GraphQL, `stores/boxes.js`) that an admin +creates, drags, resizes and edits in the browser. Changes save to the database, +so every visitor sees the saved layout. All of it lives in `views/home3/`: + +- **Coordinates.** `x`/`y`/`w`/`h` are px on a fixed 1400px-wide design canvas. + `Home3.vue` draws the canvas at that width and shrinks it with + `transform: scale()` to fit the window, so the arrangement is identical at + every desktop width. `BoxFrame.vue` divides pointer deltas by that scale. + `z` is the CSS z-index. +- **Two kinds of box.** `kind: "widget"` shows a built-in Vue widget by name + from `widgetRegistry.js`. The registry keys are stored data, so don't rename + them. `kind: "html"` shows admin-written HTML (`HtmlBox.vue`) in an + `