diff --git a/backend/app/api/handlers/v1/v1_ctrl_item_templates.go b/backend/app/api/handlers/v1/v1_ctrl_item_templates.go new file mode 100644 index 00000000..deb4c261 --- /dev/null +++ b/backend/app/api/handlers/v1/v1_ctrl_item_templates.go @@ -0,0 +1,164 @@ +package v1 + +import ( + "net/http" + + "github.com/google/uuid" + "github.com/hay-kot/httpkit/errchain" + "github.com/sysadminsmedia/homebox/backend/internal/core/services" + "github.com/sysadminsmedia/homebox/backend/internal/data/repo" + "github.com/sysadminsmedia/homebox/backend/internal/web/adapters" +) + +// HandleItemTemplatesGetAll godoc +// +// @Summary Get All Item Templates +// @Tags Item Templates +// @Produce json +// @Success 200 {object} []repo.ItemTemplateSummary +// @Router /v1/templates [GET] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesGetAll() errchain.HandlerFunc { + fn := func(r *http.Request) ([]repo.ItemTemplateSummary, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.ItemTemplates.GetAll(r.Context(), auth.GID) + } + + return adapters.Command(fn, http.StatusOK) +} + +// HandleItemTemplatesGet godoc +// +// @Summary Get Item Template +// @Tags Item Templates +// @Produce json +// @Param id path string true "Template ID" +// @Success 200 {object} repo.ItemTemplateOut +// @Router /v1/templates/{id} [GET] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesGet() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID) (repo.ItemTemplateOut, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.ItemTemplates.GetOne(r.Context(), auth.GID, ID) + } + + return adapters.CommandID("id", fn, http.StatusOK) +} + +// HandleItemTemplatesCreate godoc +// +// @Summary Create Item Template +// @Tags Item Templates +// @Produce json +// @Param payload body repo.ItemTemplateCreate true "Template Data" +// @Success 201 {object} repo.ItemTemplateOut +// @Router /v1/templates [POST] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesCreate() errchain.HandlerFunc { + fn := func(r *http.Request, body repo.ItemTemplateCreate) (repo.ItemTemplateOut, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.ItemTemplates.Create(r.Context(), auth.GID, body) + } + + return adapters.Action(fn, http.StatusCreated) +} + +// HandleItemTemplatesUpdate godoc +// +// @Summary Update Item Template +// @Tags Item Templates +// @Produce json +// @Param id path string true "Template ID" +// @Param payload body repo.ItemTemplateUpdate true "Template Data" +// @Success 200 {object} repo.ItemTemplateOut +// @Router /v1/templates/{id} [PUT] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesUpdate() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID, body repo.ItemTemplateUpdate) (repo.ItemTemplateOut, error) { + auth := services.NewContext(r.Context()) + body.ID = ID + return ctrl.repo.ItemTemplates.Update(r.Context(), auth.GID, body) + } + + return adapters.ActionID("id", fn, http.StatusOK) +} + +// HandleItemTemplatesDelete godoc +// +// @Summary Delete Item Template +// @Tags Item Templates +// @Produce json +// @Param id path string true "Template ID" +// @Success 204 +// @Router /v1/templates/{id} [DELETE] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesDelete() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID) (any, error) { + auth := services.NewContext(r.Context()) + err := ctrl.repo.ItemTemplates.Delete(r.Context(), auth.GID, ID) + return nil, err + } + + return adapters.CommandID("id", fn, http.StatusNoContent) +} + +type ItemTemplateCreateItemRequest struct { + Name string `json:"name" validate:"required,min=1,max=255"` + Description string `json:"description" validate:"max=1000"` + LocationID uuid.UUID `json:"locationId" validate:"required"` + LabelIDs []uuid.UUID `json:"labelIds"` + Quantity *int `json:"quantity"` +} + +// HandleItemTemplatesCreateItem godoc +// +// @Summary Create Item from Template +// @Tags Item Templates +// @Produce json +// @Param id path string true "Template ID" +// @Param payload body ItemTemplateCreateItemRequest true "Item Data" +// @Success 201 {object} repo.ItemOut +// @Router /v1/templates/{id}/create-item [POST] +// @Security Bearer +func (ctrl *V1Controller) HandleItemTemplatesCreateItem() errchain.HandlerFunc { + fn := func(r *http.Request, templateID uuid.UUID, body ItemTemplateCreateItemRequest) (repo.ItemOut, error) { + auth := services.NewContext(r.Context()) + + template, err := ctrl.repo.ItemTemplates.GetOne(r.Context(), auth.GID, templateID) + if err != nil { + return repo.ItemOut{}, err + } + + quantity := template.DefaultQuantity + if body.Quantity != nil { + quantity = *body.Quantity + } + + // Build custom fields from template + fields := make([]repo.ItemField, len(template.Fields)) + for i, f := range template.Fields { + fields[i] = repo.ItemField{ + Type: f.Type, + Name: f.Name, + TextValue: f.TextValue, + } + } + + // Create item with all template data in a single transaction + return ctrl.repo.Items.CreateFromTemplate(r.Context(), auth.GID, repo.ItemCreateFromTemplate{ + Name: body.Name, + Description: body.Description, + Quantity: quantity, + LocationID: body.LocationID, + LabelIDs: body.LabelIDs, + Insured: template.DefaultInsured, + Manufacturer: template.DefaultManufacturer, + ModelNumber: template.DefaultModelNumber, + LifetimeWarranty: template.DefaultLifetimeWarranty, + WarrantyDetails: template.DefaultWarrantyDetails, + Fields: fields, + }) + } + + return adapters.ActionID("id", fn, http.StatusCreated) +} diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index f3a796f6..30bdeecf 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -145,6 +145,14 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR r.Get("/assets/{id}", chain.ToHandlerFunc(v1Ctrl.HandleAssetGet(), userMW...)) + // Item Templates + r.Get("/templates", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesGetAll(), userMW...)) + r.Post("/templates", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesCreate(), userMW...)) + r.Get("/templates/{id}", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesGet(), userMW...)) + r.Put("/templates/{id}", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesUpdate(), userMW...)) + r.Delete("/templates/{id}", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesDelete(), userMW...)) + r.Post("/templates/{id}/create-item", chain.ToHandlerFunc(v1Ctrl.HandleItemTemplatesCreateItem(), userMW...)) + // Maintenance r.Get("/maintenance", chain.ToHandlerFunc(v1Ctrl.HandleMaintenanceGetAll(), userMW...)) r.Put("/maintenance/{id}", chain.ToHandlerFunc(v1Ctrl.HandleMaintenanceEntryUpdate(), userMW...)) diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 1cbb82bf..1af68fee 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -1963,6 +1963,209 @@ const docTemplate = `{ } } }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemTemplateSummary" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "parameters": [ + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.ItemTemplateCreateItemRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, "/v1/users/change-password": { "put": { "security": [ @@ -2032,6 +2235,51 @@ const docTemplate = `{ } } }, + "/v1/users/login/oidc": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "type": "string", + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "State parameter", + "name": "state", + "in": "query", + "required": true + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, "/v1/users/logout": { "post": { "security": [ @@ -2092,6 +2340,12 @@ const docTemplate = `{ "responses": { "204": { "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "schema": { + "type": "string" + } } } } @@ -2462,6 +2716,13 @@ const docTemplate = `{ "$ref": "#/definitions/ent.GroupInvitationToken" } }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ItemTemplate" + } + }, "items": { "description": "Items holds the value of the items edge.", "type": "array", @@ -2799,6 +3060,122 @@ const docTemplate = `{ } } }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + } + } + }, "ent.Label": { "type": "object", "properties": { @@ -3048,6 +3425,64 @@ const docTemplate = `{ } } }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplate" + } + ] + } + } + }, "ent.User": { "type": "object", "properties": { @@ -3083,6 +3518,14 @@ const docTemplate = `{ "description": "Name holds the value of the \"name\" field.", "type": "string" }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, "role": { "description": "Role holds the value of the \"role\" field.", "allOf": [ @@ -3583,6 +4026,280 @@ const docTemplate = `{ } } }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/definitions/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, "repo.ItemType": { "type": "string", "enum": [ @@ -4078,6 +4795,45 @@ const docTemplate = `{ } } }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "repo.TotalsByOrganizer": { "type": "object", "properties": { @@ -4135,6 +4891,12 @@ const docTemplate = `{ }, "name": { "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" } } }, @@ -4214,6 +4976,15 @@ const docTemplate = `{ } } }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, "user.Role": { "type": "string", "enum": [ @@ -4251,6 +5022,9 @@ const docTemplate = `{ "message": { "type": "string" }, + "oidc": { + "$ref": "#/definitions/v1.OIDCStatus" + }, "title": { "type": "string" }, @@ -4333,6 +5107,36 @@ const docTemplate = `{ } } }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, "v1.LoginForm": { "type": "object", "properties": { @@ -4349,6 +5153,23 @@ const docTemplate = `{ } } }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, "v1.TokenResponse": { "type": "object", "properties": { diff --git a/backend/app/api/static/docs/openapi-3.json b/backend/app/api/static/docs/openapi-3.json index 2ae3681d..a80a6124 100644 --- a/backend/app/api/static/docs/openapi-3.json +++ b/backend/app/api/static/docs/openapi-3.json @@ -2122,6 +2122,223 @@ } } }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.ItemTemplateSummary" + } + } + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateCreate" + } + } + }, + "description": "Template Data", + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateUpdate" + } + } + }, + "description": "Template Data", + "required": true + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1.ItemTemplateCreateItemRequest" + } + } + }, + "description": "Item Data", + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemOut" + } + } + } + } + } + } + }, "/v1/users/change-password": { "put": { "security": [ @@ -2197,6 +2414,52 @@ } } }, + "/v1/users/login/oidc": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "State parameter", + "name": "state", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, "/v1/users/logout": { "post": { "security": [ @@ -2254,6 +2517,16 @@ "responses": { "204": { "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } } } } @@ -2640,6 +2913,13 @@ "$ref": "#/components/schemas/ent.GroupInvitationToken" } }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/components/schemas/ent.ItemTemplate" + } + }, "items": { "description": "Items holds the value of the items edge.", "type": "array", @@ -2977,6 +3257,122 @@ } } }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/components/schemas/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.Location" + } + ] + } + } + }, "ent.Label": { "type": "object", "properties": { @@ -3226,6 +3622,64 @@ } } }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/components/schemas/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.ItemTemplate" + } + ] + } + } + }, "ent.User": { "type": "object", "properties": { @@ -3261,6 +3715,14 @@ "description": "Name holds the value of the \"name\" field.", "type": "string" }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, "role": { "description": "Role holds the value of the \"role\" field.", "allOf": [ @@ -3761,6 +4223,280 @@ } } }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/components/schemas/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, "repo.ItemType": { "type": "string", "enum": [ @@ -4256,6 +4992,45 @@ } } }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "repo.TotalsByOrganizer": { "type": "object", "properties": { @@ -4313,6 +5088,12 @@ }, "name": { "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" } } }, @@ -4392,6 +5173,15 @@ } } }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, "user.Role": { "type": "string", "enum": [ @@ -4429,6 +5219,9 @@ "message": { "type": "string" }, + "oidc": { + "$ref": "#/components/schemas/v1.OIDCStatus" + }, "title": { "type": "string" }, @@ -4511,6 +5304,36 @@ } } }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, "v1.LoginForm": { "type": "object", "properties": { @@ -4527,6 +5350,23 @@ } } }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, "v1.TokenResponse": { "type": "object", "properties": { diff --git a/backend/app/api/static/docs/openapi-3.yaml b/backend/app/api/static/docs/openapi-3.yaml index bc56d4a2..0a6d2042 100644 --- a/backend/app/api/static/docs/openapi-3.yaml +++ b/backend/app/api/static/docs/openapi-3.yaml @@ -1257,6 +1257,134 @@ paths: application/json: schema: $ref: "#/components/schemas/v1.APISummary" + /v1/templates: + get: + security: + - Bearer: [] + tags: + - Item Templates + summary: Get All Item Templates + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/repo.ItemTemplateSummary" + post: + security: + - Bearer: [] + tags: + - Item Templates + summary: Create Item Template + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateCreate" + description: Template Data + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + "/v1/templates/{id}": + get: + security: + - Bearer: [] + tags: + - Item Templates + summary: Get Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + put: + security: + - Bearer: [] + tags: + - Item Templates + summary: Update Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateUpdate" + description: Template Data + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + delete: + security: + - Bearer: [] + tags: + - Item Templates + summary: Delete Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + responses: + "204": + description: No Content + "/v1/templates/{id}/create-item": + post: + security: + - Bearer: [] + tags: + - Item Templates + summary: Create Item from Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/v1.ItemTemplateCreateItemRequest" + description: Item Data + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemOut" /v1/users/change-password: put: security: @@ -1302,6 +1430,35 @@ paths: application/json: schema: $ref: "#/components/schemas/v1.TokenResponse" + /v1/users/login/oidc: + get: + tags: + - Authentication + summary: OIDC Login Initiation + responses: + "302": + description: Found + /v1/users/login/oidc/callback: + get: + tags: + - Authentication + summary: OIDC Callback Handler + parameters: + - description: Authorization code + name: code + in: query + required: true + schema: + type: string + - description: State parameter + name: state + in: query + required: true + schema: + type: string + responses: + "302": + description: Found /v1/users/logout: post: security: @@ -1342,6 +1499,12 @@ paths: responses: "204": description: No Content + "403": + description: Local login is not enabled + content: + application/json: + schema: + type: string /v1/users/self: get: security: @@ -1590,6 +1753,11 @@ components: type: array items: $ref: "#/components/schemas/ent.GroupInvitationToken" + item_templates: + description: ItemTemplates holds the value of the item_templates edge. + type: array + items: + $ref: "#/components/schemas/ent.ItemTemplate" items: description: Items holds the value of the items edge. type: array @@ -1826,6 +1994,93 @@ components: description: Item holds the value of the item edge. allOf: - $ref: "#/components/schemas/ent.Item" + ent.ItemTemplate: + type: object + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + default_description: + description: Default description for items created from this template + type: string + default_insured: + description: DefaultInsured holds the value of the "default_insured" field. + type: boolean + default_label_ids: + description: Default label IDs for items created from this template + type: array + items: + type: string + default_lifetime_warranty: + description: DefaultLifetimeWarranty holds the value of the + "default_lifetime_warranty" field. + type: boolean + default_manufacturer: + description: DefaultManufacturer holds the value of the "default_manufacturer" + field. + type: string + default_model_number: + description: Default model number for items created from this template + type: string + default_name: + description: Default name template for items (can use placeholders) + type: string + default_quantity: + description: DefaultQuantity holds the value of the "default_quantity" field. + type: integer + default_warranty_details: + description: DefaultWarrantyDetails holds the value of the + "default_warranty_details" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + description: >- + Edges holds the relations/edges for other nodes in the graph. + + The values are being populated by the ItemTemplateQuery when eager-loading is set. + allOf: + - $ref: "#/components/schemas/ent.ItemTemplateEdges" + id: + description: ID of the ent. + type: string + include_purchase_fields: + description: Whether to include purchase fields in items created from this + template + type: boolean + include_sold_fields: + description: Whether to include sold fields in items created from this template + type: boolean + include_warranty_fields: + description: Whether to include warranty fields in items created from this + template + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + ent.ItemTemplateEdges: + type: object + properties: + fields: + description: Fields holds the value of the fields edge. + type: array + items: + $ref: "#/components/schemas/ent.TemplateField" + group: + description: Group holds the value of the group edge. + allOf: + - $ref: "#/components/schemas/ent.Group" + location: + description: Location holds the value of the location edge. + allOf: + - $ref: "#/components/schemas/ent.Location" ent.Label: type: object properties: @@ -1998,6 +2253,45 @@ components: description: User holds the value of the user edge. allOf: - $ref: "#/components/schemas/ent.User" + ent.TemplateField: + type: object + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + description: >- + Edges holds the relations/edges for other nodes in the graph. + + The values are being populated by the TemplateFieldQuery when eager-loading is set. + allOf: + - $ref: "#/components/schemas/ent.TemplateFieldEdges" + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + type: + description: Type holds the value of the "type" field. + allOf: + - $ref: "#/components/schemas/templatefield.Type" + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + ent.TemplateFieldEdges: + type: object + properties: + item_template: + description: ItemTemplate holds the value of the item_template edge. + allOf: + - $ref: "#/components/schemas/ent.ItemTemplate" ent.User: type: object properties: @@ -2026,6 +2320,12 @@ components: name: description: Name holds the value of the "name" field. type: string + oidc_issuer: + description: OidcIssuer holds the value of the "oidc_issuer" field. + type: string + oidc_subject: + description: OidcSubject holds the value of the "oidc_subject" field. + type: string role: description: Role holds the value of the "role" field. allOf: @@ -2361,6 +2661,201 @@ components: nullable: true updatedAt: type: string + repo.ItemTemplateCreate: + type: object + required: + - name + properties: + defaultDescription: + type: string + maxLength: 1000 + nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + type: array + items: + type: string + nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + nullable: true + defaultManufacturer: + type: string + maxLength: 255 + nullable: true + defaultModelNumber: + type: string + maxLength: 255 + nullable: true + defaultName: + type: string + maxLength: 255 + nullable: true + defaultQuantity: + description: Default values for items + type: integer + nullable: true + defaultWarrantyDetails: + type: string + maxLength: 1000 + nullable: true + description: + type: string + maxLength: 1000 + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + maxLength: 255 + minLength: 1 + notes: + type: string + maxLength: 1000 + repo.ItemTemplateOut: + type: object + properties: + createdAt: + type: string + defaultDescription: + type: string + defaultInsured: + type: boolean + defaultLabels: + type: array + items: + $ref: "#/components/schemas/repo.TemplateLabelSummary" + defaultLifetimeWarranty: + type: boolean + defaultLocation: + description: Default location and labels + allOf: + - $ref: "#/components/schemas/repo.TemplateLocationSummary" + defaultManufacturer: + type: string + defaultModelNumber: + type: string + defaultName: + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + type: string + description: + type: string + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + notes: + type: string + updatedAt: + type: string + repo.ItemTemplateSummary: + type: object + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + repo.ItemTemplateUpdate: + type: object + required: + - name + properties: + defaultDescription: + type: string + maxLength: 1000 + nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + type: array + items: + type: string + nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + nullable: true + defaultManufacturer: + type: string + maxLength: 255 + nullable: true + defaultModelNumber: + type: string + maxLength: 255 + nullable: true + defaultName: + type: string + maxLength: 255 + nullable: true + defaultQuantity: + description: Default values for items + type: integer + nullable: true + defaultWarrantyDetails: + type: string + maxLength: 1000 + nullable: true + description: + type: string + maxLength: 1000 + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + maxLength: 255 + minLength: 1 + notes: + type: string + maxLength: 1000 repo.ItemType: type: string enum: @@ -2698,6 +3193,31 @@ components: type: integer total: type: integer + repo.TemplateField: + type: object + properties: + id: + type: string + name: + type: string + textValue: + type: string + type: + type: string + repo.TemplateLabelSummary: + type: object + properties: + id: + type: string + name: + type: string + repo.TemplateLocationSummary: + type: object + properties: + id: + type: string + name: + type: string repo.TotalsByOrganizer: type: object properties: @@ -2737,6 +3257,10 @@ components: type: boolean name: type: string + oidcIssuer: + type: string + oidcSubject: + type: string repo.UserUpdate: type: object properties: @@ -2786,6 +3310,12 @@ components: type: string token: type: string + templatefield.Type: + type: string + enum: + - text + x-enum-varnames: + - TypeText user.Role: type: string enum: @@ -2813,6 +3343,8 @@ components: $ref: "#/components/schemas/services.Latest" message: type: string + oidc: + $ref: "#/components/schemas/v1.OIDCStatus" title: type: string versions: @@ -2865,6 +3397,27 @@ components: properties: token: type: string + v1.ItemTemplateCreateItemRequest: + type: object + required: + - locationId + - name + properties: + description: + type: string + maxLength: 1000 + labelIds: + type: array + items: + type: string + locationId: + type: string + name: + type: string + maxLength: 255 + minLength: 1 + quantity: + type: integer v1.LoginForm: type: object properties: @@ -2876,6 +3429,17 @@ components: username: type: string example: admin@admin.com + v1.OIDCStatus: + type: object + properties: + allowLocal: + type: boolean + autoRedirect: + type: boolean + buttonText: + type: string + enabled: + type: boolean v1.TokenResponse: type: object properties: diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 3fd96322..61b8612a 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -1961,6 +1961,209 @@ } } }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemTemplateSummary" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "parameters": [ + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.ItemTemplateCreateItemRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, "/v1/users/change-password": { "put": { "security": [ @@ -2030,6 +2233,51 @@ } } }, + "/v1/users/login/oidc": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "type": "string", + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "State parameter", + "name": "state", + "in": "query", + "required": true + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, "/v1/users/logout": { "post": { "security": [ @@ -2090,6 +2338,12 @@ "responses": { "204": { "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "schema": { + "type": "string" + } } } } @@ -2460,6 +2714,13 @@ "$ref": "#/definitions/ent.GroupInvitationToken" } }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ItemTemplate" + } + }, "items": { "description": "Items holds the value of the items edge.", "type": "array", @@ -2797,6 +3058,122 @@ } } }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + } + } + }, "ent.Label": { "type": "object", "properties": { @@ -3046,6 +3423,64 @@ } } }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplate" + } + ] + } + } + }, "ent.User": { "type": "object", "properties": { @@ -3081,6 +3516,14 @@ "description": "Name holds the value of the \"name\" field.", "type": "string" }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, "role": { "description": "Role holds the value of the \"role\" field.", "allOf": [ @@ -3581,6 +4024,280 @@ } } }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/definitions/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, "repo.ItemType": { "type": "string", "enum": [ @@ -4076,6 +4793,45 @@ } } }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "repo.TotalsByOrganizer": { "type": "object", "properties": { @@ -4133,6 +4889,12 @@ }, "name": { "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" } } }, @@ -4212,6 +4974,15 @@ } } }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, "user.Role": { "type": "string", "enum": [ @@ -4249,6 +5020,9 @@ "message": { "type": "string" }, + "oidc": { + "$ref": "#/definitions/v1.OIDCStatus" + }, "title": { "type": "string" }, @@ -4331,6 +5105,36 @@ } } }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, "v1.LoginForm": { "type": "object", "properties": { @@ -4347,6 +5151,23 @@ } } }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, "v1.TokenResponse": { "type": "object", "properties": { diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index 1fc5f05e..d18a8f45 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -179,6 +179,11 @@ definitions: items: $ref: '#/definitions/ent.GroupInvitationToken' type: array + item_templates: + description: ItemTemplates holds the value of the item_templates edge. + items: + $ref: '#/definitions/ent.ItemTemplate' + type: array items: description: Items holds the value of the items edge. items: @@ -414,6 +419,92 @@ definitions: - $ref: '#/definitions/ent.Item' description: Item holds the value of the item edge. type: object + ent.ItemTemplate: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + default_description: + description: Default description for items created from this template + type: string + default_insured: + description: DefaultInsured holds the value of the "default_insured" field. + type: boolean + default_label_ids: + description: Default label IDs for items created from this template + items: + type: string + type: array + default_lifetime_warranty: + description: DefaultLifetimeWarranty holds the value of the "default_lifetime_warranty" + field. + type: boolean + default_manufacturer: + description: DefaultManufacturer holds the value of the "default_manufacturer" + field. + type: string + default_model_number: + description: Default model number for items created from this template + type: string + default_name: + description: Default name template for items (can use placeholders) + type: string + default_quantity: + description: DefaultQuantity holds the value of the "default_quantity" field. + type: integer + default_warranty_details: + description: DefaultWarrantyDetails holds the value of the "default_warranty_details" + field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ItemTemplateEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ItemTemplateQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + include_purchase_fields: + description: Whether to include purchase fields in items created from this + template + type: boolean + include_sold_fields: + description: Whether to include sold fields in items created from this template + type: boolean + include_warranty_fields: + description: Whether to include warranty fields in items created from this + template + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.ItemTemplateEdges: + properties: + fields: + description: Fields holds the value of the fields edge. + items: + $ref: '#/definitions/ent.TemplateField' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + location: + allOf: + - $ref: '#/definitions/ent.Location' + description: Location holds the value of the location edge. + type: object ent.Label: properties: color: @@ -582,6 +673,44 @@ definitions: - $ref: '#/definitions/ent.User' description: User holds the value of the user edge. type: object + ent.TemplateField: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.TemplateFieldEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the TemplateFieldQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + type: + allOf: + - $ref: '#/definitions/templatefield.Type' + description: Type holds the value of the "type" field. + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.TemplateFieldEdges: + properties: + item_template: + allOf: + - $ref: '#/definitions/ent.ItemTemplate' + description: ItemTemplate holds the value of the item_template edge. + type: object ent.User: properties: activated_on: @@ -608,6 +737,12 @@ definitions: name: description: Name holds the value of the "name" field. type: string + oidc_issuer: + description: OidcIssuer holds the value of the "oidc_issuer" field. + type: string + oidc_subject: + description: OidcSubject holds the value of the "oidc_subject" field. + type: string role: allOf: - $ref: '#/definitions/user.Role' @@ -944,6 +1079,201 @@ definitions: updatedAt: type: string type: object + repo.ItemTemplateCreate: + properties: + defaultDescription: + maxLength: 1000 + type: string + x-nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + x-nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + x-nullable: true + defaultManufacturer: + maxLength: 255 + type: string + x-nullable: true + defaultModelNumber: + maxLength: 255 + type: string + x-nullable: true + defaultName: + maxLength: 255 + type: string + x-nullable: true + defaultQuantity: + description: Default values for items + type: integer + x-nullable: true + defaultWarrantyDetails: + maxLength: 1000 + type: string + x-nullable: true + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object + repo.ItemTemplateOut: + properties: + createdAt: + type: string + defaultDescription: + type: string + defaultInsured: + type: boolean + defaultLabels: + items: + $ref: '#/definitions/repo.TemplateLabelSummary' + type: array + defaultLifetimeWarranty: + type: boolean + defaultLocation: + allOf: + - $ref: '#/definitions/repo.TemplateLocationSummary' + description: Default location and labels + defaultManufacturer: + type: string + defaultModelNumber: + type: string + defaultName: + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + type: string + description: + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + notes: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateSummary: + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateUpdate: + properties: + defaultDescription: + maxLength: 1000 + type: string + x-nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + x-nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + x-nullable: true + defaultManufacturer: + maxLength: 255 + type: string + x-nullable: true + defaultModelNumber: + maxLength: 255 + type: string + x-nullable: true + defaultName: + maxLength: 255 + type: string + x-nullable: true + defaultQuantity: + description: Default values for items + type: integer + x-nullable: true + defaultWarrantyDetails: + maxLength: 1000 + type: string + x-nullable: true + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object repo.ItemType: enum: - location @@ -1281,6 +1611,31 @@ definitions: total: type: integer type: object + repo.TemplateField: + properties: + id: + type: string + name: + type: string + textValue: + type: string + type: + type: string + type: object + repo.TemplateLabelSummary: + properties: + id: + type: string + name: + type: string + type: object + repo.TemplateLocationSummary: + properties: + id: + type: string + name: + type: string + type: object repo.TotalsByOrganizer: properties: id: @@ -1319,6 +1674,10 @@ definitions: type: boolean name: type: string + oidcIssuer: + type: string + oidcSubject: + type: string type: object repo.UserUpdate: properties: @@ -1369,6 +1728,12 @@ definitions: token: type: string type: object + templatefield.Type: + enum: + - text + type: string + x-enum-varnames: + - TypeText user.Role: enum: - user @@ -1395,6 +1760,8 @@ definitions: $ref: '#/definitions/services.Latest' message: type: string + oidc: + $ref: '#/definitions/v1.OIDCStatus' title: type: string versions: @@ -1448,6 +1815,27 @@ definitions: token: type: string type: object + v1.ItemTemplateCreateItemRequest: + properties: + description: + maxLength: 1000 + type: string + labelIds: + items: + type: string + type: array + locationId: + type: string + name: + maxLength: 255 + minLength: 1 + type: string + quantity: + type: integer + required: + - locationId + - name + type: object v1.LoginForm: properties: password: @@ -1459,6 +1847,17 @@ definitions: example: admin@admin.com type: string type: object + v1.OIDCStatus: + properties: + allowLocal: + type: boolean + autoRedirect: + type: boolean + buttonText: + type: string + enabled: + type: boolean + type: object v1.TokenResponse: properties: attachmentToken: @@ -2679,6 +3078,130 @@ paths: summary: Application Info tags: - Base + /v1/templates: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.ItemTemplateSummary' + type: array + security: + - Bearer: [] + summary: Get All Item Templates + tags: + - Item Templates + post: + parameters: + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateCreate' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Create Item Template + tags: + - Item Templates + /v1/templates/{id}: + delete: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Item Template + tags: + - Item Templates + get: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Get Item Template + tags: + - Item Templates + put: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Update Item Template + tags: + - Item Templates + /v1/templates/{id}/create-item: + post: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.ItemTemplateCreateItemRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Create Item from Template + tags: + - Item Templates /v1/users/change-password: put: parameters: @@ -2722,6 +3245,35 @@ paths: summary: User Login tags: - Authentication + /v1/users/login/oidc: + get: + produces: + - application/json + responses: + "302": + description: Found + summary: OIDC Login Initiation + tags: + - Authentication + /v1/users/login/oidc/callback: + get: + parameters: + - description: Authorization code + in: query + name: code + required: true + type: string + - description: State parameter + in: query + name: state + required: true + type: string + responses: + "302": + description: Found + summary: OIDC Callback Handler + tags: + - Authentication /v1/users/logout: post: responses: @@ -2759,6 +3311,10 @@ paths: responses: "204": description: No Content + "403": + description: Local login is not enabled + schema: + type: string summary: Register New User tags: - User diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index 6c6c30b9..7cd5830c 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -23,10 +23,12 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -49,6 +51,8 @@ type Client struct { Item *ItemClient // ItemField is the client for interacting with the ItemField builders. ItemField *ItemFieldClient + // ItemTemplate is the client for interacting with the ItemTemplate builders. + ItemTemplate *ItemTemplateClient // Label is the client for interacting with the Label builders. Label *LabelClient // Location is the client for interacting with the Location builders. @@ -57,6 +61,8 @@ type Client struct { MaintenanceEntry *MaintenanceEntryClient // Notifier is the client for interacting with the Notifier builders. Notifier *NotifierClient + // TemplateField is the client for interacting with the TemplateField builders. + TemplateField *TemplateFieldClient // User is the client for interacting with the User builders. User *UserClient } @@ -77,10 +83,12 @@ func (c *Client) init() { c.GroupInvitationToken = NewGroupInvitationTokenClient(c.config) c.Item = NewItemClient(c.config) c.ItemField = NewItemFieldClient(c.config) + c.ItemTemplate = NewItemTemplateClient(c.config) c.Label = NewLabelClient(c.config) c.Location = NewLocationClient(c.config) c.MaintenanceEntry = NewMaintenanceEntryClient(c.config) c.Notifier = NewNotifierClient(c.config) + c.TemplateField = NewTemplateFieldClient(c.config) c.User = NewUserClient(c.config) } @@ -181,10 +189,12 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { GroupInvitationToken: NewGroupInvitationTokenClient(cfg), Item: NewItemClient(cfg), ItemField: NewItemFieldClient(cfg), + ItemTemplate: NewItemTemplateClient(cfg), Label: NewLabelClient(cfg), Location: NewLocationClient(cfg), MaintenanceEntry: NewMaintenanceEntryClient(cfg), Notifier: NewNotifierClient(cfg), + TemplateField: NewTemplateFieldClient(cfg), User: NewUserClient(cfg), }, nil } @@ -212,10 +222,12 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) GroupInvitationToken: NewGroupInvitationTokenClient(cfg), Item: NewItemClient(cfg), ItemField: NewItemFieldClient(cfg), + ItemTemplate: NewItemTemplateClient(cfg), Label: NewLabelClient(cfg), Location: NewLocationClient(cfg), MaintenanceEntry: NewMaintenanceEntryClient(cfg), Notifier: NewNotifierClient(cfg), + TemplateField: NewTemplateFieldClient(cfg), User: NewUserClient(cfg), }, nil } @@ -247,8 +259,8 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.Attachment, c.AuthRoles, c.AuthTokens, c.Group, c.GroupInvitationToken, - c.Item, c.ItemField, c.Label, c.Location, c.MaintenanceEntry, c.Notifier, - c.User, + c.Item, c.ItemField, c.ItemTemplate, c.Label, c.Location, c.MaintenanceEntry, + c.Notifier, c.TemplateField, c.User, } { n.Use(hooks...) } @@ -259,8 +271,8 @@ func (c *Client) Use(hooks ...Hook) { func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.Attachment, c.AuthRoles, c.AuthTokens, c.Group, c.GroupInvitationToken, - c.Item, c.ItemField, c.Label, c.Location, c.MaintenanceEntry, c.Notifier, - c.User, + c.Item, c.ItemField, c.ItemTemplate, c.Label, c.Location, c.MaintenanceEntry, + c.Notifier, c.TemplateField, c.User, } { n.Intercept(interceptors...) } @@ -283,6 +295,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.Item.mutate(ctx, m) case *ItemFieldMutation: return c.ItemField.mutate(ctx, m) + case *ItemTemplateMutation: + return c.ItemTemplate.mutate(ctx, m) case *LabelMutation: return c.Label.mutate(ctx, m) case *LocationMutation: @@ -291,6 +305,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.MaintenanceEntry.mutate(ctx, m) case *NotifierMutation: return c.Notifier.mutate(ctx, m) + case *TemplateFieldMutation: + return c.TemplateField.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) default: @@ -981,6 +997,22 @@ func (c *GroupClient) QueryNotifiers(_m *Group) *NotifierQuery { return query } +// QueryItemTemplates queries the item_templates edge of a Group. +func (c *GroupClient) QueryItemTemplates(_m *Group) *ItemTemplateQuery { + query := (&ItemTemplateClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(group.Table, group.FieldID, id), + sqlgraph.To(itemtemplate.Table, itemtemplate.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, group.ItemTemplatesTable, group.ItemTemplatesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *GroupClient) Hooks() []Hook { return c.hooks.Group @@ -1565,6 +1597,187 @@ func (c *ItemFieldClient) mutate(ctx context.Context, m *ItemFieldMutation) (Val } } +// ItemTemplateClient is a client for the ItemTemplate schema. +type ItemTemplateClient struct { + config +} + +// NewItemTemplateClient returns a client for the ItemTemplate from the given config. +func NewItemTemplateClient(c config) *ItemTemplateClient { + return &ItemTemplateClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `itemtemplate.Hooks(f(g(h())))`. +func (c *ItemTemplateClient) Use(hooks ...Hook) { + c.hooks.ItemTemplate = append(c.hooks.ItemTemplate, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `itemtemplate.Intercept(f(g(h())))`. +func (c *ItemTemplateClient) Intercept(interceptors ...Interceptor) { + c.inters.ItemTemplate = append(c.inters.ItemTemplate, interceptors...) +} + +// Create returns a builder for creating a ItemTemplate entity. +func (c *ItemTemplateClient) Create() *ItemTemplateCreate { + mutation := newItemTemplateMutation(c.config, OpCreate) + return &ItemTemplateCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ItemTemplate entities. +func (c *ItemTemplateClient) CreateBulk(builders ...*ItemTemplateCreate) *ItemTemplateCreateBulk { + return &ItemTemplateCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *ItemTemplateClient) MapCreateBulk(slice any, setFunc func(*ItemTemplateCreate, int)) *ItemTemplateCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ItemTemplateCreateBulk{err: fmt.Errorf("calling to ItemTemplateClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ItemTemplateCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ItemTemplateCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ItemTemplate. +func (c *ItemTemplateClient) Update() *ItemTemplateUpdate { + mutation := newItemTemplateMutation(c.config, OpUpdate) + return &ItemTemplateUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ItemTemplateClient) UpdateOne(_m *ItemTemplate) *ItemTemplateUpdateOne { + mutation := newItemTemplateMutation(c.config, OpUpdateOne, withItemTemplate(_m)) + return &ItemTemplateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ItemTemplateClient) UpdateOneID(id uuid.UUID) *ItemTemplateUpdateOne { + mutation := newItemTemplateMutation(c.config, OpUpdateOne, withItemTemplateID(id)) + return &ItemTemplateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ItemTemplate. +func (c *ItemTemplateClient) Delete() *ItemTemplateDelete { + mutation := newItemTemplateMutation(c.config, OpDelete) + return &ItemTemplateDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ItemTemplateClient) DeleteOne(_m *ItemTemplate) *ItemTemplateDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ItemTemplateClient) DeleteOneID(id uuid.UUID) *ItemTemplateDeleteOne { + builder := c.Delete().Where(itemtemplate.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ItemTemplateDeleteOne{builder} +} + +// Query returns a query builder for ItemTemplate. +func (c *ItemTemplateClient) Query() *ItemTemplateQuery { + return &ItemTemplateQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeItemTemplate}, + inters: c.Interceptors(), + } +} + +// Get returns a ItemTemplate entity by its id. +func (c *ItemTemplateClient) Get(ctx context.Context, id uuid.UUID) (*ItemTemplate, error) { + return c.Query().Where(itemtemplate.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ItemTemplateClient) GetX(ctx context.Context, id uuid.UUID) *ItemTemplate { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryGroup queries the group edge of a ItemTemplate. +func (c *ItemTemplateClient) QueryGroup(_m *ItemTemplate) *GroupQuery { + query := (&GroupClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, id), + sqlgraph.To(group.Table, group.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, itemtemplate.GroupTable, itemtemplate.GroupColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryFields queries the fields edge of a ItemTemplate. +func (c *ItemTemplateClient) QueryFields(_m *ItemTemplate) *TemplateFieldQuery { + query := (&TemplateFieldClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, id), + sqlgraph.To(templatefield.Table, templatefield.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, itemtemplate.FieldsTable, itemtemplate.FieldsColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryLocation queries the location edge of a ItemTemplate. +func (c *ItemTemplateClient) QueryLocation(_m *ItemTemplate) *LocationQuery { + query := (&LocationClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, id), + sqlgraph.To(location.Table, location.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, itemtemplate.LocationTable, itemtemplate.LocationColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ItemTemplateClient) Hooks() []Hook { + return c.hooks.ItemTemplate +} + +// Interceptors returns the client interceptors. +func (c *ItemTemplateClient) Interceptors() []Interceptor { + return c.inters.ItemTemplate +} + +func (c *ItemTemplateClient) mutate(ctx context.Context, m *ItemTemplateMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ItemTemplateCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ItemTemplateUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ItemTemplateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ItemTemplateDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown ItemTemplate mutation op: %q", m.Op()) + } +} + // LabelClient is a client for the Label schema. type LabelClient struct { config @@ -2241,6 +2454,155 @@ func (c *NotifierClient) mutate(ctx context.Context, m *NotifierMutation) (Value } } +// TemplateFieldClient is a client for the TemplateField schema. +type TemplateFieldClient struct { + config +} + +// NewTemplateFieldClient returns a client for the TemplateField from the given config. +func NewTemplateFieldClient(c config) *TemplateFieldClient { + return &TemplateFieldClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `templatefield.Hooks(f(g(h())))`. +func (c *TemplateFieldClient) Use(hooks ...Hook) { + c.hooks.TemplateField = append(c.hooks.TemplateField, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `templatefield.Intercept(f(g(h())))`. +func (c *TemplateFieldClient) Intercept(interceptors ...Interceptor) { + c.inters.TemplateField = append(c.inters.TemplateField, interceptors...) +} + +// Create returns a builder for creating a TemplateField entity. +func (c *TemplateFieldClient) Create() *TemplateFieldCreate { + mutation := newTemplateFieldMutation(c.config, OpCreate) + return &TemplateFieldCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of TemplateField entities. +func (c *TemplateFieldClient) CreateBulk(builders ...*TemplateFieldCreate) *TemplateFieldCreateBulk { + return &TemplateFieldCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TemplateFieldClient) MapCreateBulk(slice any, setFunc func(*TemplateFieldCreate, int)) *TemplateFieldCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TemplateFieldCreateBulk{err: fmt.Errorf("calling to TemplateFieldClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TemplateFieldCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TemplateFieldCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for TemplateField. +func (c *TemplateFieldClient) Update() *TemplateFieldUpdate { + mutation := newTemplateFieldMutation(c.config, OpUpdate) + return &TemplateFieldUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *TemplateFieldClient) UpdateOne(_m *TemplateField) *TemplateFieldUpdateOne { + mutation := newTemplateFieldMutation(c.config, OpUpdateOne, withTemplateField(_m)) + return &TemplateFieldUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *TemplateFieldClient) UpdateOneID(id uuid.UUID) *TemplateFieldUpdateOne { + mutation := newTemplateFieldMutation(c.config, OpUpdateOne, withTemplateFieldID(id)) + return &TemplateFieldUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for TemplateField. +func (c *TemplateFieldClient) Delete() *TemplateFieldDelete { + mutation := newTemplateFieldMutation(c.config, OpDelete) + return &TemplateFieldDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *TemplateFieldClient) DeleteOne(_m *TemplateField) *TemplateFieldDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *TemplateFieldClient) DeleteOneID(id uuid.UUID) *TemplateFieldDeleteOne { + builder := c.Delete().Where(templatefield.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &TemplateFieldDeleteOne{builder} +} + +// Query returns a query builder for TemplateField. +func (c *TemplateFieldClient) Query() *TemplateFieldQuery { + return &TemplateFieldQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeTemplateField}, + inters: c.Interceptors(), + } +} + +// Get returns a TemplateField entity by its id. +func (c *TemplateFieldClient) Get(ctx context.Context, id uuid.UUID) (*TemplateField, error) { + return c.Query().Where(templatefield.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *TemplateFieldClient) GetX(ctx context.Context, id uuid.UUID) *TemplateField { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryItemTemplate queries the item_template edge of a TemplateField. +func (c *TemplateFieldClient) QueryItemTemplate(_m *TemplateField) *ItemTemplateQuery { + query := (&ItemTemplateClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(templatefield.Table, templatefield.FieldID, id), + sqlgraph.To(itemtemplate.Table, itemtemplate.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, templatefield.ItemTemplateTable, templatefield.ItemTemplateColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *TemplateFieldClient) Hooks() []Hook { + return c.hooks.TemplateField +} + +// Interceptors returns the client interceptors. +func (c *TemplateFieldClient) Interceptors() []Interceptor { + return c.inters.TemplateField +} + +func (c *TemplateFieldClient) mutate(ctx context.Context, m *TemplateFieldMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TemplateFieldCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TemplateFieldUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TemplateFieldUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TemplateFieldDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown TemplateField mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -2426,10 +2788,12 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) type ( hooks struct { Attachment, AuthRoles, AuthTokens, Group, GroupInvitationToken, Item, ItemField, - Label, Location, MaintenanceEntry, Notifier, User []ent.Hook + ItemTemplate, Label, Location, MaintenanceEntry, Notifier, TemplateField, + User []ent.Hook } inters struct { Attachment, AuthRoles, AuthTokens, Group, GroupInvitationToken, Item, ItemField, - Label, Location, MaintenanceEntry, Notifier, User []ent.Interceptor + ItemTemplate, Label, Location, MaintenanceEntry, Notifier, TemplateField, + User []ent.Interceptor } ) diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index 173be97f..ee3abfa7 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -19,10 +19,12 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -91,10 +93,12 @@ func checkColumn(t, c string) error { groupinvitationtoken.Table: groupinvitationtoken.ValidColumn, item.Table: item.ValidColumn, itemfield.Table: itemfield.ValidColumn, + itemtemplate.Table: itemtemplate.ValidColumn, label.Table: label.ValidColumn, location.Table: location.ValidColumn, maintenanceentry.Table: maintenanceentry.ValidColumn, notifier.Table: notifier.ValidColumn, + templatefield.Table: templatefield.ValidColumn, user.Table: user.ValidColumn, }) }) diff --git a/backend/internal/data/ent/group.go b/backend/internal/data/ent/group.go index 9bb043aa..d20782b9 100644 --- a/backend/internal/data/ent/group.go +++ b/backend/internal/data/ent/group.go @@ -46,9 +46,11 @@ type GroupEdges struct { InvitationTokens []*GroupInvitationToken `json:"invitation_tokens,omitempty"` // Notifiers holds the value of the notifiers edge. Notifiers []*Notifier `json:"notifiers,omitempty"` + // ItemTemplates holds the value of the item_templates edge. + ItemTemplates []*ItemTemplate `json:"item_templates,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [6]bool + loadedTypes [7]bool } // UsersOrErr returns the Users value or an error if the edge @@ -105,6 +107,15 @@ func (e GroupEdges) NotifiersOrErr() ([]*Notifier, error) { return nil, &NotLoadedError{edge: "notifiers"} } +// ItemTemplatesOrErr returns the ItemTemplates value or an error if the edge +// was not loaded in eager-loading. +func (e GroupEdges) ItemTemplatesOrErr() ([]*ItemTemplate, error) { + if e.loadedTypes[6] { + return e.ItemTemplates, nil + } + return nil, &NotLoadedError{edge: "item_templates"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*Group) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -204,6 +215,11 @@ func (_m *Group) QueryNotifiers() *NotifierQuery { return NewGroupClient(_m.config).QueryNotifiers(_m) } +// QueryItemTemplates queries the "item_templates" edge of the Group entity. +func (_m *Group) QueryItemTemplates() *ItemTemplateQuery { + return NewGroupClient(_m.config).QueryItemTemplates(_m) +} + // Update returns a builder for updating this Group. // Note that you need to call Group.Unwrap() before calling this method if this Group // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/backend/internal/data/ent/group/group.go b/backend/internal/data/ent/group/group.go index 422d2b13..80dc3398 100644 --- a/backend/internal/data/ent/group/group.go +++ b/backend/internal/data/ent/group/group.go @@ -35,6 +35,8 @@ const ( EdgeInvitationTokens = "invitation_tokens" // EdgeNotifiers holds the string denoting the notifiers edge name in mutations. EdgeNotifiers = "notifiers" + // EdgeItemTemplates holds the string denoting the item_templates edge name in mutations. + EdgeItemTemplates = "item_templates" // Table holds the table name of the group in the database. Table = "groups" // UsersTable is the table that holds the users relation/edge. @@ -79,6 +81,13 @@ const ( NotifiersInverseTable = "notifiers" // NotifiersColumn is the table column denoting the notifiers relation/edge. NotifiersColumn = "group_id" + // ItemTemplatesTable is the table that holds the item_templates relation/edge. + ItemTemplatesTable = "item_templates" + // ItemTemplatesInverseTable is the table name for the ItemTemplate entity. + // It exists in this package in order to avoid circular dependency with the "itemtemplate" package. + ItemTemplatesInverseTable = "item_templates" + // ItemTemplatesColumn is the table column denoting the item_templates relation/edge. + ItemTemplatesColumn = "group_item_templates" ) // Columns holds all SQL columns for group fields. @@ -226,6 +235,20 @@ func ByNotifiers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { sqlgraph.OrderByNeighborTerms(s, newNotifiersStep(), append([]sql.OrderTerm{term}, terms...)...) } } + +// ByItemTemplatesCount orders the results by item_templates count. +func ByItemTemplatesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newItemTemplatesStep(), opts...) + } +} + +// ByItemTemplates orders the results by item_templates terms. +func ByItemTemplates(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newItemTemplatesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} func newUsersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -268,3 +291,10 @@ func newNotifiersStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, NotifiersTable, NotifiersColumn), ) } +func newItemTemplatesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ItemTemplatesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ItemTemplatesTable, ItemTemplatesColumn), + ) +} diff --git a/backend/internal/data/ent/group/where.go b/backend/internal/data/ent/group/where.go index d3205524..fec4b27c 100644 --- a/backend/internal/data/ent/group/where.go +++ b/backend/internal/data/ent/group/where.go @@ -424,6 +424,29 @@ func HasNotifiersWith(preds ...predicate.Notifier) predicate.Group { }) } +// HasItemTemplates applies the HasEdge predicate on the "item_templates" edge. +func HasItemTemplates() predicate.Group { + return predicate.Group(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ItemTemplatesTable, ItemTemplatesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasItemTemplatesWith applies the HasEdge predicate on the "item_templates" edge with a given conditions (other predicates). +func HasItemTemplatesWith(preds ...predicate.ItemTemplate) predicate.Group { + return predicate.Group(func(s *sql.Selector) { + step := newItemTemplatesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { return predicate.Group(sql.AndPredicates(predicates...)) diff --git a/backend/internal/data/ent/group_create.go b/backend/internal/data/ent/group_create.go index 978220cd..9eb4bac1 100644 --- a/backend/internal/data/ent/group_create.go +++ b/backend/internal/data/ent/group_create.go @@ -14,6 +14,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" @@ -179,6 +180,21 @@ func (_c *GroupCreate) AddNotifiers(v ...*Notifier) *GroupCreate { return _c.AddNotifierIDs(ids...) } +// AddItemTemplateIDs adds the "item_templates" edge to the ItemTemplate entity by IDs. +func (_c *GroupCreate) AddItemTemplateIDs(ids ...uuid.UUID) *GroupCreate { + _c.mutation.AddItemTemplateIDs(ids...) + return _c +} + +// AddItemTemplates adds the "item_templates" edges to the ItemTemplate entity. +func (_c *GroupCreate) AddItemTemplates(v ...*ItemTemplate) *GroupCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddItemTemplateIDs(ids...) +} + // Mutation returns the GroupMutation object of the builder. func (_c *GroupCreate) Mutation() *GroupMutation { return _c.mutation @@ -398,6 +414,22 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.ItemTemplatesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index 69d4e4a4..20124988 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -16,6 +16,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" @@ -36,6 +37,7 @@ type GroupQuery struct { withLabels *LabelQuery withInvitationTokens *GroupInvitationTokenQuery withNotifiers *NotifierQuery + withItemTemplates *ItemTemplateQuery // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -204,6 +206,28 @@ func (_q *GroupQuery) QueryNotifiers() *NotifierQuery { return query } +// QueryItemTemplates chains the current query on the "item_templates" edge. +func (_q *GroupQuery) QueryItemTemplates() *ItemTemplateQuery { + query := (&ItemTemplateClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(group.Table, group.FieldID, selector), + sqlgraph.To(itemtemplate.Table, itemtemplate.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, group.ItemTemplatesTable, group.ItemTemplatesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // First returns the first Group entity from the query. // Returns a *NotFoundError when no Group was found. func (_q *GroupQuery) First(ctx context.Context) (*Group, error) { @@ -402,6 +426,7 @@ func (_q *GroupQuery) Clone() *GroupQuery { withLabels: _q.withLabels.Clone(), withInvitationTokens: _q.withInvitationTokens.Clone(), withNotifiers: _q.withNotifiers.Clone(), + withItemTemplates: _q.withItemTemplates.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -474,6 +499,17 @@ func (_q *GroupQuery) WithNotifiers(opts ...func(*NotifierQuery)) *GroupQuery { return _q } +// WithItemTemplates tells the query-builder to eager-load the nodes that are connected to +// the "item_templates" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *GroupQuery) WithItemTemplates(opts ...func(*ItemTemplateQuery)) *GroupQuery { + query := (&ItemTemplateClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withItemTemplates = query + return _q +} + // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // @@ -552,13 +588,14 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, var ( nodes = []*Group{} _spec = _q.querySpec() - loadedTypes = [6]bool{ + loadedTypes = [7]bool{ _q.withUsers != nil, _q.withLocations != nil, _q.withItems != nil, _q.withLabels != nil, _q.withInvitationTokens != nil, _q.withNotifiers != nil, + _q.withItemTemplates != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { @@ -623,6 +660,13 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, return nil, err } } + if query := _q.withItemTemplates; query != nil { + if err := _q.loadItemTemplates(ctx, query, nodes, + func(n *Group) { n.Edges.ItemTemplates = []*ItemTemplate{} }, + func(n *Group, e *ItemTemplate) { n.Edges.ItemTemplates = append(n.Edges.ItemTemplates, e) }); err != nil { + return nil, err + } + } return nodes, nil } @@ -811,6 +855,37 @@ func (_q *GroupQuery) loadNotifiers(ctx context.Context, query *NotifierQuery, n } return nil } +func (_q *GroupQuery) loadItemTemplates(ctx context.Context, query *ItemTemplateQuery, nodes []*Group, init func(*Group), assign func(*Group, *ItemTemplate)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Group) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.ItemTemplate(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(group.ItemTemplatesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.group_item_templates + if fk == nil { + return fmt.Errorf(`foreign-key "group_item_templates" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "group_item_templates" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *GroupQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() diff --git a/backend/internal/data/ent/group_update.go b/backend/internal/data/ent/group_update.go index c0acecfe..d0190d49 100644 --- a/backend/internal/data/ent/group_update.go +++ b/backend/internal/data/ent/group_update.go @@ -15,6 +15,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" @@ -159,6 +160,21 @@ func (_u *GroupUpdate) AddNotifiers(v ...*Notifier) *GroupUpdate { return _u.AddNotifierIDs(ids...) } +// AddItemTemplateIDs adds the "item_templates" edge to the ItemTemplate entity by IDs. +func (_u *GroupUpdate) AddItemTemplateIDs(ids ...uuid.UUID) *GroupUpdate { + _u.mutation.AddItemTemplateIDs(ids...) + return _u +} + +// AddItemTemplates adds the "item_templates" edges to the ItemTemplate entity. +func (_u *GroupUpdate) AddItemTemplates(v ...*ItemTemplate) *GroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddItemTemplateIDs(ids...) +} + // Mutation returns the GroupMutation object of the builder. func (_u *GroupUpdate) Mutation() *GroupMutation { return _u.mutation @@ -290,6 +306,27 @@ func (_u *GroupUpdate) RemoveNotifiers(v ...*Notifier) *GroupUpdate { return _u.RemoveNotifierIDs(ids...) } +// ClearItemTemplates clears all "item_templates" edges to the ItemTemplate entity. +func (_u *GroupUpdate) ClearItemTemplates() *GroupUpdate { + _u.mutation.ClearItemTemplates() + return _u +} + +// RemoveItemTemplateIDs removes the "item_templates" edge to ItemTemplate entities by IDs. +func (_u *GroupUpdate) RemoveItemTemplateIDs(ids ...uuid.UUID) *GroupUpdate { + _u.mutation.RemoveItemTemplateIDs(ids...) + return _u +} + +// RemoveItemTemplates removes "item_templates" edges to ItemTemplate entities. +func (_u *GroupUpdate) RemoveItemTemplates(v ...*ItemTemplate) *GroupUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveItemTemplateIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (_u *GroupUpdate) Save(ctx context.Context) (int, error) { _u.defaults() @@ -627,6 +664,51 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.ItemTemplatesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedItemTemplatesIDs(); len(nodes) > 0 && !_u.mutation.ItemTemplatesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ItemTemplatesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{group.Label} @@ -771,6 +853,21 @@ func (_u *GroupUpdateOne) AddNotifiers(v ...*Notifier) *GroupUpdateOne { return _u.AddNotifierIDs(ids...) } +// AddItemTemplateIDs adds the "item_templates" edge to the ItemTemplate entity by IDs. +func (_u *GroupUpdateOne) AddItemTemplateIDs(ids ...uuid.UUID) *GroupUpdateOne { + _u.mutation.AddItemTemplateIDs(ids...) + return _u +} + +// AddItemTemplates adds the "item_templates" edges to the ItemTemplate entity. +func (_u *GroupUpdateOne) AddItemTemplates(v ...*ItemTemplate) *GroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddItemTemplateIDs(ids...) +} + // Mutation returns the GroupMutation object of the builder. func (_u *GroupUpdateOne) Mutation() *GroupMutation { return _u.mutation @@ -902,6 +999,27 @@ func (_u *GroupUpdateOne) RemoveNotifiers(v ...*Notifier) *GroupUpdateOne { return _u.RemoveNotifierIDs(ids...) } +// ClearItemTemplates clears all "item_templates" edges to the ItemTemplate entity. +func (_u *GroupUpdateOne) ClearItemTemplates() *GroupUpdateOne { + _u.mutation.ClearItemTemplates() + return _u +} + +// RemoveItemTemplateIDs removes the "item_templates" edge to ItemTemplate entities by IDs. +func (_u *GroupUpdateOne) RemoveItemTemplateIDs(ids ...uuid.UUID) *GroupUpdateOne { + _u.mutation.RemoveItemTemplateIDs(ids...) + return _u +} + +// RemoveItemTemplates removes "item_templates" edges to ItemTemplate entities. +func (_u *GroupUpdateOne) RemoveItemTemplates(v ...*ItemTemplate) *GroupUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveItemTemplateIDs(ids...) +} + // Where appends a list predicates to the GroupUpdate builder. func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne { _u.mutation.Where(ps...) @@ -1269,6 +1387,51 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.ItemTemplatesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedItemTemplatesIDs(); len(nodes) > 0 && !_u.mutation.ItemTemplatesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ItemTemplatesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: group.ItemTemplatesTable, + Columns: []string{group.ItemTemplatesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &Group{config: _u.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/backend/internal/data/ent/has_id.go b/backend/internal/data/ent/has_id.go index 758b3145..faf28d4e 100644 --- a/backend/internal/data/ent/has_id.go +++ b/backend/internal/data/ent/has_id.go @@ -32,6 +32,10 @@ func (_m *ItemField) GetID() uuid.UUID { return _m.ID } +func (_m *ItemTemplate) GetID() uuid.UUID { + return _m.ID +} + func (_m *Label) GetID() uuid.UUID { return _m.ID } @@ -48,6 +52,10 @@ func (_m *Notifier) GetID() uuid.UUID { return _m.ID } +func (_m *TemplateField) GetID() uuid.UUID { + return _m.ID +} + func (_m *User) GetID() uuid.UUID { return _m.ID } diff --git a/backend/internal/data/ent/hook/hook.go b/backend/internal/data/ent/hook/hook.go index 2a078c19..6859da52 100644 --- a/backend/internal/data/ent/hook/hook.go +++ b/backend/internal/data/ent/hook/hook.go @@ -93,6 +93,18 @@ func (f ItemFieldFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, e return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemFieldMutation", m) } +// The ItemTemplateFunc type is an adapter to allow the use of ordinary +// function as ItemTemplate mutator. +type ItemTemplateFunc func(context.Context, *ent.ItemTemplateMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ItemTemplateFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.ItemTemplateMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemTemplateMutation", m) +} + // The LabelFunc type is an adapter to allow the use of ordinary // function as Label mutator. type LabelFunc func(context.Context, *ent.LabelMutation) (ent.Value, error) @@ -141,6 +153,18 @@ func (f NotifierFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NotifierMutation", m) } +// The TemplateFieldFunc type is an adapter to allow the use of ordinary +// function as TemplateField mutator. +type TemplateFieldFunc func(context.Context, *ent.TemplateFieldMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f TemplateFieldFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.TemplateFieldMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TemplateFieldMutation", m) +} + // The UserFunc type is an adapter to allow the use of ordinary // function as User mutator. type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) diff --git a/backend/internal/data/ent/itemtemplate.go b/backend/internal/data/ent/itemtemplate.go new file mode 100644 index 00000000..0d9f1f2f --- /dev/null +++ b/backend/internal/data/ent/itemtemplate.go @@ -0,0 +1,376 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" +) + +// ItemTemplate is the model entity for the ItemTemplate schema. +type ItemTemplate struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Notes holds the value of the "notes" field. + Notes string `json:"notes,omitempty"` + // DefaultQuantity holds the value of the "default_quantity" field. + DefaultQuantity int `json:"default_quantity,omitempty"` + // DefaultInsured holds the value of the "default_insured" field. + DefaultInsured bool `json:"default_insured,omitempty"` + // Default name template for items (can use placeholders) + DefaultName string `json:"default_name,omitempty"` + // Default description for items created from this template + DefaultDescription string `json:"default_description,omitempty"` + // DefaultManufacturer holds the value of the "default_manufacturer" field. + DefaultManufacturer string `json:"default_manufacturer,omitempty"` + // Default model number for items created from this template + DefaultModelNumber string `json:"default_model_number,omitempty"` + // DefaultLifetimeWarranty holds the value of the "default_lifetime_warranty" field. + DefaultLifetimeWarranty bool `json:"default_lifetime_warranty,omitempty"` + // DefaultWarrantyDetails holds the value of the "default_warranty_details" field. + DefaultWarrantyDetails string `json:"default_warranty_details,omitempty"` + // Whether to include warranty fields in items created from this template + IncludeWarrantyFields bool `json:"include_warranty_fields,omitempty"` + // Whether to include purchase fields in items created from this template + IncludePurchaseFields bool `json:"include_purchase_fields,omitempty"` + // Whether to include sold fields in items created from this template + IncludeSoldFields bool `json:"include_sold_fields,omitempty"` + // Default label IDs for items created from this template + DefaultLabelIds []uuid.UUID `json:"default_label_ids,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ItemTemplateQuery when eager-loading is set. + Edges ItemTemplateEdges `json:"edges"` + group_item_templates *uuid.UUID + item_template_location *uuid.UUID + selectValues sql.SelectValues +} + +// ItemTemplateEdges holds the relations/edges for other nodes in the graph. +type ItemTemplateEdges struct { + // Group holds the value of the group edge. + Group *Group `json:"group,omitempty"` + // Fields holds the value of the fields edge. + Fields []*TemplateField `json:"fields,omitempty"` + // Location holds the value of the location edge. + Location *Location `json:"location,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// GroupOrErr returns the Group value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ItemTemplateEdges) GroupOrErr() (*Group, error) { + if e.Group != nil { + return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} + } + return nil, &NotLoadedError{edge: "group"} +} + +// FieldsOrErr returns the Fields value or an error if the edge +// was not loaded in eager-loading. +func (e ItemTemplateEdges) FieldsOrErr() ([]*TemplateField, error) { + if e.loadedTypes[1] { + return e.Fields, nil + } + return nil, &NotLoadedError{edge: "fields"} +} + +// LocationOrErr returns the Location value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ItemTemplateEdges) LocationOrErr() (*Location, error) { + if e.Location != nil { + return e.Location, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: location.Label} + } + return nil, &NotLoadedError{edge: "location"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ItemTemplate) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case itemtemplate.FieldDefaultLabelIds: + values[i] = new([]byte) + case itemtemplate.FieldDefaultInsured, itemtemplate.FieldDefaultLifetimeWarranty, itemtemplate.FieldIncludeWarrantyFields, itemtemplate.FieldIncludePurchaseFields, itemtemplate.FieldIncludeSoldFields: + values[i] = new(sql.NullBool) + case itemtemplate.FieldDefaultQuantity: + values[i] = new(sql.NullInt64) + case itemtemplate.FieldName, itemtemplate.FieldDescription, itemtemplate.FieldNotes, itemtemplate.FieldDefaultName, itemtemplate.FieldDefaultDescription, itemtemplate.FieldDefaultManufacturer, itemtemplate.FieldDefaultModelNumber, itemtemplate.FieldDefaultWarrantyDetails: + values[i] = new(sql.NullString) + case itemtemplate.FieldCreatedAt, itemtemplate.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case itemtemplate.FieldID: + values[i] = new(uuid.UUID) + case itemtemplate.ForeignKeys[0]: // group_item_templates + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + case itemtemplate.ForeignKeys[1]: // item_template_location + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the ItemTemplate fields. +func (_m *ItemTemplate) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case itemtemplate.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case itemtemplate.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case itemtemplate.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + case itemtemplate.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case itemtemplate.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = value.String + } + case itemtemplate.FieldNotes: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field notes", values[i]) + } else if value.Valid { + _m.Notes = value.String + } + case itemtemplate.FieldDefaultQuantity: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field default_quantity", values[i]) + } else if value.Valid { + _m.DefaultQuantity = int(value.Int64) + } + case itemtemplate.FieldDefaultInsured: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field default_insured", values[i]) + } else if value.Valid { + _m.DefaultInsured = value.Bool + } + case itemtemplate.FieldDefaultName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field default_name", values[i]) + } else if value.Valid { + _m.DefaultName = value.String + } + case itemtemplate.FieldDefaultDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field default_description", values[i]) + } else if value.Valid { + _m.DefaultDescription = value.String + } + case itemtemplate.FieldDefaultManufacturer: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field default_manufacturer", values[i]) + } else if value.Valid { + _m.DefaultManufacturer = value.String + } + case itemtemplate.FieldDefaultModelNumber: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field default_model_number", values[i]) + } else if value.Valid { + _m.DefaultModelNumber = value.String + } + case itemtemplate.FieldDefaultLifetimeWarranty: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field default_lifetime_warranty", values[i]) + } else if value.Valid { + _m.DefaultLifetimeWarranty = value.Bool + } + case itemtemplate.FieldDefaultWarrantyDetails: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field default_warranty_details", values[i]) + } else if value.Valid { + _m.DefaultWarrantyDetails = value.String + } + case itemtemplate.FieldIncludeWarrantyFields: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field include_warranty_fields", values[i]) + } else if value.Valid { + _m.IncludeWarrantyFields = value.Bool + } + case itemtemplate.FieldIncludePurchaseFields: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field include_purchase_fields", values[i]) + } else if value.Valid { + _m.IncludePurchaseFields = value.Bool + } + case itemtemplate.FieldIncludeSoldFields: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field include_sold_fields", values[i]) + } else if value.Valid { + _m.IncludeSoldFields = value.Bool + } + case itemtemplate.FieldDefaultLabelIds: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field default_label_ids", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.DefaultLabelIds); err != nil { + return fmt.Errorf("unmarshal field default_label_ids: %w", err) + } + } + case itemtemplate.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field group_item_templates", values[i]) + } else if value.Valid { + _m.group_item_templates = new(uuid.UUID) + *_m.group_item_templates = *value.S.(*uuid.UUID) + } + case itemtemplate.ForeignKeys[1]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field item_template_location", values[i]) + } else if value.Valid { + _m.item_template_location = new(uuid.UUID) + *_m.item_template_location = *value.S.(*uuid.UUID) + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the ItemTemplate. +// This includes values selected through modifiers, order, etc. +func (_m *ItemTemplate) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryGroup queries the "group" edge of the ItemTemplate entity. +func (_m *ItemTemplate) QueryGroup() *GroupQuery { + return NewItemTemplateClient(_m.config).QueryGroup(_m) +} + +// QueryFields queries the "fields" edge of the ItemTemplate entity. +func (_m *ItemTemplate) QueryFields() *TemplateFieldQuery { + return NewItemTemplateClient(_m.config).QueryFields(_m) +} + +// QueryLocation queries the "location" edge of the ItemTemplate entity. +func (_m *ItemTemplate) QueryLocation() *LocationQuery { + return NewItemTemplateClient(_m.config).QueryLocation(_m) +} + +// Update returns a builder for updating this ItemTemplate. +// Note that you need to call ItemTemplate.Unwrap() before calling this method if this ItemTemplate +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ItemTemplate) Update() *ItemTemplateUpdateOne { + return NewItemTemplateClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ItemTemplate entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *ItemTemplate) Unwrap() *ItemTemplate { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: ItemTemplate is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ItemTemplate) String() string { + var builder strings.Builder + builder.WriteString("ItemTemplate(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(_m.Description) + builder.WriteString(", ") + builder.WriteString("notes=") + builder.WriteString(_m.Notes) + builder.WriteString(", ") + builder.WriteString("default_quantity=") + builder.WriteString(fmt.Sprintf("%v", _m.DefaultQuantity)) + builder.WriteString(", ") + builder.WriteString("default_insured=") + builder.WriteString(fmt.Sprintf("%v", _m.DefaultInsured)) + builder.WriteString(", ") + builder.WriteString("default_name=") + builder.WriteString(_m.DefaultName) + builder.WriteString(", ") + builder.WriteString("default_description=") + builder.WriteString(_m.DefaultDescription) + builder.WriteString(", ") + builder.WriteString("default_manufacturer=") + builder.WriteString(_m.DefaultManufacturer) + builder.WriteString(", ") + builder.WriteString("default_model_number=") + builder.WriteString(_m.DefaultModelNumber) + builder.WriteString(", ") + builder.WriteString("default_lifetime_warranty=") + builder.WriteString(fmt.Sprintf("%v", _m.DefaultLifetimeWarranty)) + builder.WriteString(", ") + builder.WriteString("default_warranty_details=") + builder.WriteString(_m.DefaultWarrantyDetails) + builder.WriteString(", ") + builder.WriteString("include_warranty_fields=") + builder.WriteString(fmt.Sprintf("%v", _m.IncludeWarrantyFields)) + builder.WriteString(", ") + builder.WriteString("include_purchase_fields=") + builder.WriteString(fmt.Sprintf("%v", _m.IncludePurchaseFields)) + builder.WriteString(", ") + builder.WriteString("include_sold_fields=") + builder.WriteString(fmt.Sprintf("%v", _m.IncludeSoldFields)) + builder.WriteString(", ") + builder.WriteString("default_label_ids=") + builder.WriteString(fmt.Sprintf("%v", _m.DefaultLabelIds)) + builder.WriteByte(')') + return builder.String() +} + +// ItemTemplates is a parsable slice of ItemTemplate. +type ItemTemplates []*ItemTemplate diff --git a/backend/internal/data/ent/itemtemplate/itemtemplate.go b/backend/internal/data/ent/itemtemplate/itemtemplate.go new file mode 100644 index 00000000..ac308b9d --- /dev/null +++ b/backend/internal/data/ent/itemtemplate/itemtemplate.go @@ -0,0 +1,301 @@ +// Code generated by ent, DO NOT EDIT. + +package itemtemplate + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the itemtemplate type in the database. + Label = "item_template" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldNotes holds the string denoting the notes field in the database. + FieldNotes = "notes" + // FieldDefaultQuantity holds the string denoting the default_quantity field in the database. + FieldDefaultQuantity = "default_quantity" + // FieldDefaultInsured holds the string denoting the default_insured field in the database. + FieldDefaultInsured = "default_insured" + // FieldDefaultName holds the string denoting the default_name field in the database. + FieldDefaultName = "default_name" + // FieldDefaultDescription holds the string denoting the default_description field in the database. + FieldDefaultDescription = "default_description" + // FieldDefaultManufacturer holds the string denoting the default_manufacturer field in the database. + FieldDefaultManufacturer = "default_manufacturer" + // FieldDefaultModelNumber holds the string denoting the default_model_number field in the database. + FieldDefaultModelNumber = "default_model_number" + // FieldDefaultLifetimeWarranty holds the string denoting the default_lifetime_warranty field in the database. + FieldDefaultLifetimeWarranty = "default_lifetime_warranty" + // FieldDefaultWarrantyDetails holds the string denoting the default_warranty_details field in the database. + FieldDefaultWarrantyDetails = "default_warranty_details" + // FieldIncludeWarrantyFields holds the string denoting the include_warranty_fields field in the database. + FieldIncludeWarrantyFields = "include_warranty_fields" + // FieldIncludePurchaseFields holds the string denoting the include_purchase_fields field in the database. + FieldIncludePurchaseFields = "include_purchase_fields" + // FieldIncludeSoldFields holds the string denoting the include_sold_fields field in the database. + FieldIncludeSoldFields = "include_sold_fields" + // FieldDefaultLabelIds holds the string denoting the default_label_ids field in the database. + FieldDefaultLabelIds = "default_label_ids" + // EdgeGroup holds the string denoting the group edge name in mutations. + EdgeGroup = "group" + // EdgeFields holds the string denoting the fields edge name in mutations. + EdgeFields = "fields" + // EdgeLocation holds the string denoting the location edge name in mutations. + EdgeLocation = "location" + // Table holds the table name of the itemtemplate in the database. + Table = "item_templates" + // GroupTable is the table that holds the group relation/edge. + GroupTable = "item_templates" + // GroupInverseTable is the table name for the Group entity. + // It exists in this package in order to avoid circular dependency with the "group" package. + GroupInverseTable = "groups" + // GroupColumn is the table column denoting the group relation/edge. + GroupColumn = "group_item_templates" + // FieldsTable is the table that holds the fields relation/edge. + FieldsTable = "template_fields" + // FieldsInverseTable is the table name for the TemplateField entity. + // It exists in this package in order to avoid circular dependency with the "templatefield" package. + FieldsInverseTable = "template_fields" + // FieldsColumn is the table column denoting the fields relation/edge. + FieldsColumn = "item_template_fields" + // LocationTable is the table that holds the location relation/edge. + LocationTable = "item_templates" + // LocationInverseTable is the table name for the Location entity. + // It exists in this package in order to avoid circular dependency with the "location" package. + LocationInverseTable = "locations" + // LocationColumn is the table column denoting the location relation/edge. + LocationColumn = "item_template_location" +) + +// Columns holds all SQL columns for itemtemplate fields. +var Columns = []string{ + FieldID, + FieldCreatedAt, + FieldUpdatedAt, + FieldName, + FieldDescription, + FieldNotes, + FieldDefaultQuantity, + FieldDefaultInsured, + FieldDefaultName, + FieldDefaultDescription, + FieldDefaultManufacturer, + FieldDefaultModelNumber, + FieldDefaultLifetimeWarranty, + FieldDefaultWarrantyDetails, + FieldIncludeWarrantyFields, + FieldIncludePurchaseFields, + FieldIncludeSoldFields, + FieldDefaultLabelIds, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "item_templates" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "group_item_templates", + "item_template_location", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + DescriptionValidator func(string) error + // NotesValidator is a validator for the "notes" field. It is called by the builders before save. + NotesValidator func(string) error + // DefaultDefaultQuantity holds the default value on creation for the "default_quantity" field. + DefaultDefaultQuantity int + // DefaultDefaultInsured holds the default value on creation for the "default_insured" field. + DefaultDefaultInsured bool + // DefaultNameValidator is a validator for the "default_name" field. It is called by the builders before save. + DefaultNameValidator func(string) error + // DefaultDescriptionValidator is a validator for the "default_description" field. It is called by the builders before save. + DefaultDescriptionValidator func(string) error + // DefaultManufacturerValidator is a validator for the "default_manufacturer" field. It is called by the builders before save. + DefaultManufacturerValidator func(string) error + // DefaultModelNumberValidator is a validator for the "default_model_number" field. It is called by the builders before save. + DefaultModelNumberValidator func(string) error + // DefaultDefaultLifetimeWarranty holds the default value on creation for the "default_lifetime_warranty" field. + DefaultDefaultLifetimeWarranty bool + // DefaultWarrantyDetailsValidator is a validator for the "default_warranty_details" field. It is called by the builders before save. + DefaultWarrantyDetailsValidator func(string) error + // DefaultIncludeWarrantyFields holds the default value on creation for the "include_warranty_fields" field. + DefaultIncludeWarrantyFields bool + // DefaultIncludePurchaseFields holds the default value on creation for the "include_purchase_fields" field. + DefaultIncludePurchaseFields bool + // DefaultIncludeSoldFields holds the default value on creation for the "include_sold_fields" field. + DefaultIncludeSoldFields bool + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// OrderOption defines the ordering options for the ItemTemplate queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByNotes orders the results by the notes field. +func ByNotes(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNotes, opts...).ToFunc() +} + +// ByDefaultQuantity orders the results by the default_quantity field. +func ByDefaultQuantity(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultQuantity, opts...).ToFunc() +} + +// ByDefaultInsured orders the results by the default_insured field. +func ByDefaultInsured(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultInsured, opts...).ToFunc() +} + +// ByDefaultName orders the results by the default_name field. +func ByDefaultName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultName, opts...).ToFunc() +} + +// ByDefaultDescription orders the results by the default_description field. +func ByDefaultDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultDescription, opts...).ToFunc() +} + +// ByDefaultManufacturer orders the results by the default_manufacturer field. +func ByDefaultManufacturer(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultManufacturer, opts...).ToFunc() +} + +// ByDefaultModelNumber orders the results by the default_model_number field. +func ByDefaultModelNumber(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultModelNumber, opts...).ToFunc() +} + +// ByDefaultLifetimeWarranty orders the results by the default_lifetime_warranty field. +func ByDefaultLifetimeWarranty(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultLifetimeWarranty, opts...).ToFunc() +} + +// ByDefaultWarrantyDetails orders the results by the default_warranty_details field. +func ByDefaultWarrantyDetails(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDefaultWarrantyDetails, opts...).ToFunc() +} + +// ByIncludeWarrantyFields orders the results by the include_warranty_fields field. +func ByIncludeWarrantyFields(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIncludeWarrantyFields, opts...).ToFunc() +} + +// ByIncludePurchaseFields orders the results by the include_purchase_fields field. +func ByIncludePurchaseFields(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIncludePurchaseFields, opts...).ToFunc() +} + +// ByIncludeSoldFields orders the results by the include_sold_fields field. +func ByIncludeSoldFields(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIncludeSoldFields, opts...).ToFunc() +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} + +// ByFieldsCount orders the results by fields count. +func ByFieldsCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newFieldsStep(), opts...) + } +} + +// ByFields orders the results by fields terms. +func ByFields(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newFieldsStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByLocationField orders the results by location field. +func ByLocationField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newLocationStep(), sql.OrderByField(field, opts...)) + } +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) +} +func newFieldsStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(FieldsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, FieldsTable, FieldsColumn), + ) +} +func newLocationStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LocationInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, LocationTable, LocationColumn), + ) +} diff --git a/backend/internal/data/ent/itemtemplate/where.go b/backend/internal/data/ent/itemtemplate/where.go new file mode 100644 index 00000000..1ade7376 --- /dev/null +++ b/backend/internal/data/ent/itemtemplate/where.go @@ -0,0 +1,991 @@ +// Code generated by ent, DO NOT EDIT. + +package itemtemplate + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldName, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDescription, v)) +} + +// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ. +func Notes(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldNotes, v)) +} + +// DefaultQuantity applies equality check predicate on the "default_quantity" field. It's identical to DefaultQuantityEQ. +func DefaultQuantity(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultQuantity, v)) +} + +// DefaultInsured applies equality check predicate on the "default_insured" field. It's identical to DefaultInsuredEQ. +func DefaultInsured(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultInsured, v)) +} + +// DefaultName applies equality check predicate on the "default_name" field. It's identical to DefaultNameEQ. +func DefaultName(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultName, v)) +} + +// DefaultDescription applies equality check predicate on the "default_description" field. It's identical to DefaultDescriptionEQ. +func DefaultDescription(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultDescription, v)) +} + +// DefaultManufacturer applies equality check predicate on the "default_manufacturer" field. It's identical to DefaultManufacturerEQ. +func DefaultManufacturer(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultManufacturer, v)) +} + +// DefaultModelNumber applies equality check predicate on the "default_model_number" field. It's identical to DefaultModelNumberEQ. +func DefaultModelNumber(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultModelNumber, v)) +} + +// DefaultLifetimeWarranty applies equality check predicate on the "default_lifetime_warranty" field. It's identical to DefaultLifetimeWarrantyEQ. +func DefaultLifetimeWarranty(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultLifetimeWarranty, v)) +} + +// DefaultWarrantyDetails applies equality check predicate on the "default_warranty_details" field. It's identical to DefaultWarrantyDetailsEQ. +func DefaultWarrantyDetails(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultWarrantyDetails, v)) +} + +// IncludeWarrantyFields applies equality check predicate on the "include_warranty_fields" field. It's identical to IncludeWarrantyFieldsEQ. +func IncludeWarrantyFields(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludeWarrantyFields, v)) +} + +// IncludePurchaseFields applies equality check predicate on the "include_purchase_fields" field. It's identical to IncludePurchaseFieldsEQ. +func IncludePurchaseFields(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludePurchaseFields, v)) +} + +// IncludeSoldFields applies equality check predicate on the "include_sold_fields" field. It's identical to IncludeSoldFieldsEQ. +func IncludeSoldFields(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludeSoldFields, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldName, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDescription, v)) +} + +// NotesEQ applies the EQ predicate on the "notes" field. +func NotesEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldNotes, v)) +} + +// NotesNEQ applies the NEQ predicate on the "notes" field. +func NotesNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldNotes, v)) +} + +// NotesIn applies the In predicate on the "notes" field. +func NotesIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldNotes, vs...)) +} + +// NotesNotIn applies the NotIn predicate on the "notes" field. +func NotesNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldNotes, vs...)) +} + +// NotesGT applies the GT predicate on the "notes" field. +func NotesGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldNotes, v)) +} + +// NotesGTE applies the GTE predicate on the "notes" field. +func NotesGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldNotes, v)) +} + +// NotesLT applies the LT predicate on the "notes" field. +func NotesLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldNotes, v)) +} + +// NotesLTE applies the LTE predicate on the "notes" field. +func NotesLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldNotes, v)) +} + +// NotesContains applies the Contains predicate on the "notes" field. +func NotesContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldNotes, v)) +} + +// NotesHasPrefix applies the HasPrefix predicate on the "notes" field. +func NotesHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldNotes, v)) +} + +// NotesHasSuffix applies the HasSuffix predicate on the "notes" field. +func NotesHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldNotes, v)) +} + +// NotesIsNil applies the IsNil predicate on the "notes" field. +func NotesIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldNotes)) +} + +// NotesNotNil applies the NotNil predicate on the "notes" field. +func NotesNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldNotes)) +} + +// NotesEqualFold applies the EqualFold predicate on the "notes" field. +func NotesEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldNotes, v)) +} + +// NotesContainsFold applies the ContainsFold predicate on the "notes" field. +func NotesContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldNotes, v)) +} + +// DefaultQuantityEQ applies the EQ predicate on the "default_quantity" field. +func DefaultQuantityEQ(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultQuantity, v)) +} + +// DefaultQuantityNEQ applies the NEQ predicate on the "default_quantity" field. +func DefaultQuantityNEQ(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultQuantity, v)) +} + +// DefaultQuantityIn applies the In predicate on the "default_quantity" field. +func DefaultQuantityIn(vs ...int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultQuantity, vs...)) +} + +// DefaultQuantityNotIn applies the NotIn predicate on the "default_quantity" field. +func DefaultQuantityNotIn(vs ...int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultQuantity, vs...)) +} + +// DefaultQuantityGT applies the GT predicate on the "default_quantity" field. +func DefaultQuantityGT(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultQuantity, v)) +} + +// DefaultQuantityGTE applies the GTE predicate on the "default_quantity" field. +func DefaultQuantityGTE(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultQuantity, v)) +} + +// DefaultQuantityLT applies the LT predicate on the "default_quantity" field. +func DefaultQuantityLT(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultQuantity, v)) +} + +// DefaultQuantityLTE applies the LTE predicate on the "default_quantity" field. +func DefaultQuantityLTE(v int) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultQuantity, v)) +} + +// DefaultInsuredEQ applies the EQ predicate on the "default_insured" field. +func DefaultInsuredEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultInsured, v)) +} + +// DefaultInsuredNEQ applies the NEQ predicate on the "default_insured" field. +func DefaultInsuredNEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultInsured, v)) +} + +// DefaultNameEQ applies the EQ predicate on the "default_name" field. +func DefaultNameEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultName, v)) +} + +// DefaultNameNEQ applies the NEQ predicate on the "default_name" field. +func DefaultNameNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultName, v)) +} + +// DefaultNameIn applies the In predicate on the "default_name" field. +func DefaultNameIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultName, vs...)) +} + +// DefaultNameNotIn applies the NotIn predicate on the "default_name" field. +func DefaultNameNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultName, vs...)) +} + +// DefaultNameGT applies the GT predicate on the "default_name" field. +func DefaultNameGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultName, v)) +} + +// DefaultNameGTE applies the GTE predicate on the "default_name" field. +func DefaultNameGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultName, v)) +} + +// DefaultNameLT applies the LT predicate on the "default_name" field. +func DefaultNameLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultName, v)) +} + +// DefaultNameLTE applies the LTE predicate on the "default_name" field. +func DefaultNameLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultName, v)) +} + +// DefaultNameContains applies the Contains predicate on the "default_name" field. +func DefaultNameContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDefaultName, v)) +} + +// DefaultNameHasPrefix applies the HasPrefix predicate on the "default_name" field. +func DefaultNameHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDefaultName, v)) +} + +// DefaultNameHasSuffix applies the HasSuffix predicate on the "default_name" field. +func DefaultNameHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDefaultName, v)) +} + +// DefaultNameIsNil applies the IsNil predicate on the "default_name" field. +func DefaultNameIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultName)) +} + +// DefaultNameNotNil applies the NotNil predicate on the "default_name" field. +func DefaultNameNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultName)) +} + +// DefaultNameEqualFold applies the EqualFold predicate on the "default_name" field. +func DefaultNameEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDefaultName, v)) +} + +// DefaultNameContainsFold applies the ContainsFold predicate on the "default_name" field. +func DefaultNameContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDefaultName, v)) +} + +// DefaultDescriptionEQ applies the EQ predicate on the "default_description" field. +func DefaultDescriptionEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultDescription, v)) +} + +// DefaultDescriptionNEQ applies the NEQ predicate on the "default_description" field. +func DefaultDescriptionNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultDescription, v)) +} + +// DefaultDescriptionIn applies the In predicate on the "default_description" field. +func DefaultDescriptionIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultDescription, vs...)) +} + +// DefaultDescriptionNotIn applies the NotIn predicate on the "default_description" field. +func DefaultDescriptionNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultDescription, vs...)) +} + +// DefaultDescriptionGT applies the GT predicate on the "default_description" field. +func DefaultDescriptionGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultDescription, v)) +} + +// DefaultDescriptionGTE applies the GTE predicate on the "default_description" field. +func DefaultDescriptionGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultDescription, v)) +} + +// DefaultDescriptionLT applies the LT predicate on the "default_description" field. +func DefaultDescriptionLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultDescription, v)) +} + +// DefaultDescriptionLTE applies the LTE predicate on the "default_description" field. +func DefaultDescriptionLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultDescription, v)) +} + +// DefaultDescriptionContains applies the Contains predicate on the "default_description" field. +func DefaultDescriptionContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDefaultDescription, v)) +} + +// DefaultDescriptionHasPrefix applies the HasPrefix predicate on the "default_description" field. +func DefaultDescriptionHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDefaultDescription, v)) +} + +// DefaultDescriptionHasSuffix applies the HasSuffix predicate on the "default_description" field. +func DefaultDescriptionHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDefaultDescription, v)) +} + +// DefaultDescriptionIsNil applies the IsNil predicate on the "default_description" field. +func DefaultDescriptionIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultDescription)) +} + +// DefaultDescriptionNotNil applies the NotNil predicate on the "default_description" field. +func DefaultDescriptionNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultDescription)) +} + +// DefaultDescriptionEqualFold applies the EqualFold predicate on the "default_description" field. +func DefaultDescriptionEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDefaultDescription, v)) +} + +// DefaultDescriptionContainsFold applies the ContainsFold predicate on the "default_description" field. +func DefaultDescriptionContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDefaultDescription, v)) +} + +// DefaultManufacturerEQ applies the EQ predicate on the "default_manufacturer" field. +func DefaultManufacturerEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerNEQ applies the NEQ predicate on the "default_manufacturer" field. +func DefaultManufacturerNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerIn applies the In predicate on the "default_manufacturer" field. +func DefaultManufacturerIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultManufacturer, vs...)) +} + +// DefaultManufacturerNotIn applies the NotIn predicate on the "default_manufacturer" field. +func DefaultManufacturerNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultManufacturer, vs...)) +} + +// DefaultManufacturerGT applies the GT predicate on the "default_manufacturer" field. +func DefaultManufacturerGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerGTE applies the GTE predicate on the "default_manufacturer" field. +func DefaultManufacturerGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerLT applies the LT predicate on the "default_manufacturer" field. +func DefaultManufacturerLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerLTE applies the LTE predicate on the "default_manufacturer" field. +func DefaultManufacturerLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerContains applies the Contains predicate on the "default_manufacturer" field. +func DefaultManufacturerContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerHasPrefix applies the HasPrefix predicate on the "default_manufacturer" field. +func DefaultManufacturerHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerHasSuffix applies the HasSuffix predicate on the "default_manufacturer" field. +func DefaultManufacturerHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerIsNil applies the IsNil predicate on the "default_manufacturer" field. +func DefaultManufacturerIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultManufacturer)) +} + +// DefaultManufacturerNotNil applies the NotNil predicate on the "default_manufacturer" field. +func DefaultManufacturerNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultManufacturer)) +} + +// DefaultManufacturerEqualFold applies the EqualFold predicate on the "default_manufacturer" field. +func DefaultManufacturerEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDefaultManufacturer, v)) +} + +// DefaultManufacturerContainsFold applies the ContainsFold predicate on the "default_manufacturer" field. +func DefaultManufacturerContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDefaultManufacturer, v)) +} + +// DefaultModelNumberEQ applies the EQ predicate on the "default_model_number" field. +func DefaultModelNumberEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberNEQ applies the NEQ predicate on the "default_model_number" field. +func DefaultModelNumberNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberIn applies the In predicate on the "default_model_number" field. +func DefaultModelNumberIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultModelNumber, vs...)) +} + +// DefaultModelNumberNotIn applies the NotIn predicate on the "default_model_number" field. +func DefaultModelNumberNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultModelNumber, vs...)) +} + +// DefaultModelNumberGT applies the GT predicate on the "default_model_number" field. +func DefaultModelNumberGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberGTE applies the GTE predicate on the "default_model_number" field. +func DefaultModelNumberGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberLT applies the LT predicate on the "default_model_number" field. +func DefaultModelNumberLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberLTE applies the LTE predicate on the "default_model_number" field. +func DefaultModelNumberLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberContains applies the Contains predicate on the "default_model_number" field. +func DefaultModelNumberContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberHasPrefix applies the HasPrefix predicate on the "default_model_number" field. +func DefaultModelNumberHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberHasSuffix applies the HasSuffix predicate on the "default_model_number" field. +func DefaultModelNumberHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberIsNil applies the IsNil predicate on the "default_model_number" field. +func DefaultModelNumberIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultModelNumber)) +} + +// DefaultModelNumberNotNil applies the NotNil predicate on the "default_model_number" field. +func DefaultModelNumberNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultModelNumber)) +} + +// DefaultModelNumberEqualFold applies the EqualFold predicate on the "default_model_number" field. +func DefaultModelNumberEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDefaultModelNumber, v)) +} + +// DefaultModelNumberContainsFold applies the ContainsFold predicate on the "default_model_number" field. +func DefaultModelNumberContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDefaultModelNumber, v)) +} + +// DefaultLifetimeWarrantyEQ applies the EQ predicate on the "default_lifetime_warranty" field. +func DefaultLifetimeWarrantyEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultLifetimeWarranty, v)) +} + +// DefaultLifetimeWarrantyNEQ applies the NEQ predicate on the "default_lifetime_warranty" field. +func DefaultLifetimeWarrantyNEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultLifetimeWarranty, v)) +} + +// DefaultWarrantyDetailsEQ applies the EQ predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsNEQ applies the NEQ predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsNEQ(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsIn applies the In predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIn(FieldDefaultWarrantyDetails, vs...)) +} + +// DefaultWarrantyDetailsNotIn applies the NotIn predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsNotIn(vs ...string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotIn(FieldDefaultWarrantyDetails, vs...)) +} + +// DefaultWarrantyDetailsGT applies the GT predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsGT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGT(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsGTE applies the GTE predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsGTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldGTE(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsLT applies the LT predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsLT(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLT(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsLTE applies the LTE predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsLTE(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldLTE(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsContains applies the Contains predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsContains(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContains(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsHasPrefix applies the HasPrefix predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsHasPrefix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasPrefix(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsHasSuffix applies the HasSuffix predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsHasSuffix(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldHasSuffix(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsIsNil applies the IsNil predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultWarrantyDetails)) +} + +// DefaultWarrantyDetailsNotNil applies the NotNil predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultWarrantyDetails)) +} + +// DefaultWarrantyDetailsEqualFold applies the EqualFold predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsEqualFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEqualFold(FieldDefaultWarrantyDetails, v)) +} + +// DefaultWarrantyDetailsContainsFold applies the ContainsFold predicate on the "default_warranty_details" field. +func DefaultWarrantyDetailsContainsFold(v string) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldContainsFold(FieldDefaultWarrantyDetails, v)) +} + +// IncludeWarrantyFieldsEQ applies the EQ predicate on the "include_warranty_fields" field. +func IncludeWarrantyFieldsEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludeWarrantyFields, v)) +} + +// IncludeWarrantyFieldsNEQ applies the NEQ predicate on the "include_warranty_fields" field. +func IncludeWarrantyFieldsNEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldIncludeWarrantyFields, v)) +} + +// IncludePurchaseFieldsEQ applies the EQ predicate on the "include_purchase_fields" field. +func IncludePurchaseFieldsEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludePurchaseFields, v)) +} + +// IncludePurchaseFieldsNEQ applies the NEQ predicate on the "include_purchase_fields" field. +func IncludePurchaseFieldsNEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldIncludePurchaseFields, v)) +} + +// IncludeSoldFieldsEQ applies the EQ predicate on the "include_sold_fields" field. +func IncludeSoldFieldsEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldEQ(FieldIncludeSoldFields, v)) +} + +// IncludeSoldFieldsNEQ applies the NEQ predicate on the "include_sold_fields" field. +func IncludeSoldFieldsNEQ(v bool) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNEQ(FieldIncludeSoldFields, v)) +} + +// DefaultLabelIdsIsNil applies the IsNil predicate on the "default_label_ids" field. +func DefaultLabelIdsIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultLabelIds)) +} + +// DefaultLabelIdsNotNil applies the NotNil predicate on the "default_label_ids" field. +func DefaultLabelIdsNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultLabelIds)) +} + +// HasGroup applies the HasEdge predicate on the "group" edge. +func HasGroup() predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). +func HasGroupWith(preds ...predicate.Group) predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := newGroupStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasFields applies the HasEdge predicate on the "fields" edge. +func HasFields() predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, FieldsTable, FieldsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasFieldsWith applies the HasEdge predicate on the "fields" edge with a given conditions (other predicates). +func HasFieldsWith(preds ...predicate.TemplateField) predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := newFieldsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasLocation applies the HasEdge predicate on the "location" edge. +func HasLocation() predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, LocationTable, LocationColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasLocationWith applies the HasEdge predicate on the "location" edge with a given conditions (other predicates). +func HasLocationWith(preds ...predicate.Location) predicate.ItemTemplate { + return predicate.ItemTemplate(func(s *sql.Selector) { + step := newLocationStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.ItemTemplate) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ItemTemplate) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ItemTemplate) predicate.ItemTemplate { + return predicate.ItemTemplate(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/itemtemplate_create.go b/backend/internal/data/ent/itemtemplate_create.go new file mode 100644 index 00000000..30abd074 --- /dev/null +++ b/backend/internal/data/ent/itemtemplate_create.go @@ -0,0 +1,691 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// ItemTemplateCreate is the builder for creating a ItemTemplate entity. +type ItemTemplateCreate struct { + config + mutation *ItemTemplateMutation + hooks []Hook +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ItemTemplateCreate) SetCreatedAt(v time.Time) *ItemTemplateCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableCreatedAt(v *time.Time) *ItemTemplateCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ItemTemplateCreate) SetUpdatedAt(v time.Time) *ItemTemplateCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableUpdatedAt(v *time.Time) *ItemTemplateCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetName sets the "name" field. +func (_c *ItemTemplateCreate) SetName(v string) *ItemTemplateCreate { + _c.mutation.SetName(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *ItemTemplateCreate) SetDescription(v string) *ItemTemplateCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDescription(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetNotes sets the "notes" field. +func (_c *ItemTemplateCreate) SetNotes(v string) *ItemTemplateCreate { + _c.mutation.SetNotes(v) + return _c +} + +// SetNillableNotes sets the "notes" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableNotes(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetNotes(*v) + } + return _c +} + +// SetDefaultQuantity sets the "default_quantity" field. +func (_c *ItemTemplateCreate) SetDefaultQuantity(v int) *ItemTemplateCreate { + _c.mutation.SetDefaultQuantity(v) + return _c +} + +// SetNillableDefaultQuantity sets the "default_quantity" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultQuantity(v *int) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultQuantity(*v) + } + return _c +} + +// SetDefaultInsured sets the "default_insured" field. +func (_c *ItemTemplateCreate) SetDefaultInsured(v bool) *ItemTemplateCreate { + _c.mutation.SetDefaultInsured(v) + return _c +} + +// SetNillableDefaultInsured sets the "default_insured" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultInsured(v *bool) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultInsured(*v) + } + return _c +} + +// SetDefaultName sets the "default_name" field. +func (_c *ItemTemplateCreate) SetDefaultName(v string) *ItemTemplateCreate { + _c.mutation.SetDefaultName(v) + return _c +} + +// SetNillableDefaultName sets the "default_name" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultName(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultName(*v) + } + return _c +} + +// SetDefaultDescription sets the "default_description" field. +func (_c *ItemTemplateCreate) SetDefaultDescription(v string) *ItemTemplateCreate { + _c.mutation.SetDefaultDescription(v) + return _c +} + +// SetNillableDefaultDescription sets the "default_description" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultDescription(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultDescription(*v) + } + return _c +} + +// SetDefaultManufacturer sets the "default_manufacturer" field. +func (_c *ItemTemplateCreate) SetDefaultManufacturer(v string) *ItemTemplateCreate { + _c.mutation.SetDefaultManufacturer(v) + return _c +} + +// SetNillableDefaultManufacturer sets the "default_manufacturer" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultManufacturer(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultManufacturer(*v) + } + return _c +} + +// SetDefaultModelNumber sets the "default_model_number" field. +func (_c *ItemTemplateCreate) SetDefaultModelNumber(v string) *ItemTemplateCreate { + _c.mutation.SetDefaultModelNumber(v) + return _c +} + +// SetNillableDefaultModelNumber sets the "default_model_number" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultModelNumber(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultModelNumber(*v) + } + return _c +} + +// SetDefaultLifetimeWarranty sets the "default_lifetime_warranty" field. +func (_c *ItemTemplateCreate) SetDefaultLifetimeWarranty(v bool) *ItemTemplateCreate { + _c.mutation.SetDefaultLifetimeWarranty(v) + return _c +} + +// SetNillableDefaultLifetimeWarranty sets the "default_lifetime_warranty" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultLifetimeWarranty(v *bool) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultLifetimeWarranty(*v) + } + return _c +} + +// SetDefaultWarrantyDetails sets the "default_warranty_details" field. +func (_c *ItemTemplateCreate) SetDefaultWarrantyDetails(v string) *ItemTemplateCreate { + _c.mutation.SetDefaultWarrantyDetails(v) + return _c +} + +// SetNillableDefaultWarrantyDetails sets the "default_warranty_details" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableDefaultWarrantyDetails(v *string) *ItemTemplateCreate { + if v != nil { + _c.SetDefaultWarrantyDetails(*v) + } + return _c +} + +// SetIncludeWarrantyFields sets the "include_warranty_fields" field. +func (_c *ItemTemplateCreate) SetIncludeWarrantyFields(v bool) *ItemTemplateCreate { + _c.mutation.SetIncludeWarrantyFields(v) + return _c +} + +// SetNillableIncludeWarrantyFields sets the "include_warranty_fields" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableIncludeWarrantyFields(v *bool) *ItemTemplateCreate { + if v != nil { + _c.SetIncludeWarrantyFields(*v) + } + return _c +} + +// SetIncludePurchaseFields sets the "include_purchase_fields" field. +func (_c *ItemTemplateCreate) SetIncludePurchaseFields(v bool) *ItemTemplateCreate { + _c.mutation.SetIncludePurchaseFields(v) + return _c +} + +// SetNillableIncludePurchaseFields sets the "include_purchase_fields" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableIncludePurchaseFields(v *bool) *ItemTemplateCreate { + if v != nil { + _c.SetIncludePurchaseFields(*v) + } + return _c +} + +// SetIncludeSoldFields sets the "include_sold_fields" field. +func (_c *ItemTemplateCreate) SetIncludeSoldFields(v bool) *ItemTemplateCreate { + _c.mutation.SetIncludeSoldFields(v) + return _c +} + +// SetNillableIncludeSoldFields sets the "include_sold_fields" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableIncludeSoldFields(v *bool) *ItemTemplateCreate { + if v != nil { + _c.SetIncludeSoldFields(*v) + } + return _c +} + +// SetDefaultLabelIds sets the "default_label_ids" field. +func (_c *ItemTemplateCreate) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateCreate { + _c.mutation.SetDefaultLabelIds(v) + return _c +} + +// SetID sets the "id" field. +func (_c *ItemTemplateCreate) SetID(v uuid.UUID) *ItemTemplateCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableID(v *uuid.UUID) *ItemTemplateCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetGroupID sets the "group" edge to the Group entity by ID. +func (_c *ItemTemplateCreate) SetGroupID(id uuid.UUID) *ItemTemplateCreate { + _c.mutation.SetGroupID(id) + return _c +} + +// SetGroup sets the "group" edge to the Group entity. +func (_c *ItemTemplateCreate) SetGroup(v *Group) *ItemTemplateCreate { + return _c.SetGroupID(v.ID) +} + +// AddFieldIDs adds the "fields" edge to the TemplateField entity by IDs. +func (_c *ItemTemplateCreate) AddFieldIDs(ids ...uuid.UUID) *ItemTemplateCreate { + _c.mutation.AddFieldIDs(ids...) + return _c +} + +// AddFields adds the "fields" edges to the TemplateField entity. +func (_c *ItemTemplateCreate) AddFields(v ...*TemplateField) *ItemTemplateCreate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddFieldIDs(ids...) +} + +// SetLocationID sets the "location" edge to the Location entity by ID. +func (_c *ItemTemplateCreate) SetLocationID(id uuid.UUID) *ItemTemplateCreate { + _c.mutation.SetLocationID(id) + return _c +} + +// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. +func (_c *ItemTemplateCreate) SetNillableLocationID(id *uuid.UUID) *ItemTemplateCreate { + if id != nil { + _c = _c.SetLocationID(*id) + } + return _c +} + +// SetLocation sets the "location" edge to the Location entity. +func (_c *ItemTemplateCreate) SetLocation(v *Location) *ItemTemplateCreate { + return _c.SetLocationID(v.ID) +} + +// Mutation returns the ItemTemplateMutation object of the builder. +func (_c *ItemTemplateCreate) Mutation() *ItemTemplateMutation { + return _c.mutation +} + +// Save creates the ItemTemplate in the database. +func (_c *ItemTemplateCreate) Save(ctx context.Context) (*ItemTemplate, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ItemTemplateCreate) SaveX(ctx context.Context) *ItemTemplate { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ItemTemplateCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ItemTemplateCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *ItemTemplateCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := itemtemplate.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := itemtemplate.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.DefaultQuantity(); !ok { + v := itemtemplate.DefaultDefaultQuantity + _c.mutation.SetDefaultQuantity(v) + } + if _, ok := _c.mutation.DefaultInsured(); !ok { + v := itemtemplate.DefaultDefaultInsured + _c.mutation.SetDefaultInsured(v) + } + if _, ok := _c.mutation.DefaultLifetimeWarranty(); !ok { + v := itemtemplate.DefaultDefaultLifetimeWarranty + _c.mutation.SetDefaultLifetimeWarranty(v) + } + if _, ok := _c.mutation.IncludeWarrantyFields(); !ok { + v := itemtemplate.DefaultIncludeWarrantyFields + _c.mutation.SetIncludeWarrantyFields(v) + } + if _, ok := _c.mutation.IncludePurchaseFields(); !ok { + v := itemtemplate.DefaultIncludePurchaseFields + _c.mutation.SetIncludePurchaseFields(v) + } + if _, ok := _c.mutation.IncludeSoldFields(); !ok { + v := itemtemplate.DefaultIncludeSoldFields + _c.mutation.SetIncludeSoldFields(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := itemtemplate.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ItemTemplateCreate) check() error { + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ItemTemplate.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ItemTemplate.updated_at"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ItemTemplate.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := itemtemplate.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.name": %w`, err)} + } + } + if v, ok := _c.mutation.Description(); ok { + if err := itemtemplate.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.description": %w`, err)} + } + } + if v, ok := _c.mutation.Notes(); ok { + if err := itemtemplate.NotesValidator(v); err != nil { + return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.notes": %w`, err)} + } + } + if _, ok := _c.mutation.DefaultQuantity(); !ok { + return &ValidationError{Name: "default_quantity", err: errors.New(`ent: missing required field "ItemTemplate.default_quantity"`)} + } + if _, ok := _c.mutation.DefaultInsured(); !ok { + return &ValidationError{Name: "default_insured", err: errors.New(`ent: missing required field "ItemTemplate.default_insured"`)} + } + if v, ok := _c.mutation.DefaultName(); ok { + if err := itemtemplate.DefaultNameValidator(v); err != nil { + return &ValidationError{Name: "default_name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_name": %w`, err)} + } + } + if v, ok := _c.mutation.DefaultDescription(); ok { + if err := itemtemplate.DefaultDescriptionValidator(v); err != nil { + return &ValidationError{Name: "default_description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_description": %w`, err)} + } + } + if v, ok := _c.mutation.DefaultManufacturer(); ok { + if err := itemtemplate.DefaultManufacturerValidator(v); err != nil { + return &ValidationError{Name: "default_manufacturer", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_manufacturer": %w`, err)} + } + } + if v, ok := _c.mutation.DefaultModelNumber(); ok { + if err := itemtemplate.DefaultModelNumberValidator(v); err != nil { + return &ValidationError{Name: "default_model_number", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_model_number": %w`, err)} + } + } + if _, ok := _c.mutation.DefaultLifetimeWarranty(); !ok { + return &ValidationError{Name: "default_lifetime_warranty", err: errors.New(`ent: missing required field "ItemTemplate.default_lifetime_warranty"`)} + } + if v, ok := _c.mutation.DefaultWarrantyDetails(); ok { + if err := itemtemplate.DefaultWarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "default_warranty_details", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_warranty_details": %w`, err)} + } + } + if _, ok := _c.mutation.IncludeWarrantyFields(); !ok { + return &ValidationError{Name: "include_warranty_fields", err: errors.New(`ent: missing required field "ItemTemplate.include_warranty_fields"`)} + } + if _, ok := _c.mutation.IncludePurchaseFields(); !ok { + return &ValidationError{Name: "include_purchase_fields", err: errors.New(`ent: missing required field "ItemTemplate.include_purchase_fields"`)} + } + if _, ok := _c.mutation.IncludeSoldFields(); !ok { + return &ValidationError{Name: "include_sold_fields", err: errors.New(`ent: missing required field "ItemTemplate.include_sold_fields"`)} + } + if len(_c.mutation.GroupIDs()) == 0 { + return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "ItemTemplate.group"`)} + } + return nil +} + +func (_c *ItemTemplateCreate) sqlSave(ctx context.Context) (*ItemTemplate, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ItemTemplateCreate) createSpec() (*ItemTemplate, *sqlgraph.CreateSpec) { + var ( + _node = &ItemTemplate{config: _c.config} + _spec = sqlgraph.NewCreateSpec(itemtemplate.Table, sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(itemtemplate.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(itemtemplate.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(itemtemplate.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(itemtemplate.FieldDescription, field.TypeString, value) + _node.Description = value + } + if value, ok := _c.mutation.Notes(); ok { + _spec.SetField(itemtemplate.FieldNotes, field.TypeString, value) + _node.Notes = value + } + if value, ok := _c.mutation.DefaultQuantity(); ok { + _spec.SetField(itemtemplate.FieldDefaultQuantity, field.TypeInt, value) + _node.DefaultQuantity = value + } + if value, ok := _c.mutation.DefaultInsured(); ok { + _spec.SetField(itemtemplate.FieldDefaultInsured, field.TypeBool, value) + _node.DefaultInsured = value + } + if value, ok := _c.mutation.DefaultName(); ok { + _spec.SetField(itemtemplate.FieldDefaultName, field.TypeString, value) + _node.DefaultName = value + } + if value, ok := _c.mutation.DefaultDescription(); ok { + _spec.SetField(itemtemplate.FieldDefaultDescription, field.TypeString, value) + _node.DefaultDescription = value + } + if value, ok := _c.mutation.DefaultManufacturer(); ok { + _spec.SetField(itemtemplate.FieldDefaultManufacturer, field.TypeString, value) + _node.DefaultManufacturer = value + } + if value, ok := _c.mutation.DefaultModelNumber(); ok { + _spec.SetField(itemtemplate.FieldDefaultModelNumber, field.TypeString, value) + _node.DefaultModelNumber = value + } + if value, ok := _c.mutation.DefaultLifetimeWarranty(); ok { + _spec.SetField(itemtemplate.FieldDefaultLifetimeWarranty, field.TypeBool, value) + _node.DefaultLifetimeWarranty = value + } + if value, ok := _c.mutation.DefaultWarrantyDetails(); ok { + _spec.SetField(itemtemplate.FieldDefaultWarrantyDetails, field.TypeString, value) + _node.DefaultWarrantyDetails = value + } + if value, ok := _c.mutation.IncludeWarrantyFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeWarrantyFields, field.TypeBool, value) + _node.IncludeWarrantyFields = value + } + if value, ok := _c.mutation.IncludePurchaseFields(); ok { + _spec.SetField(itemtemplate.FieldIncludePurchaseFields, field.TypeBool, value) + _node.IncludePurchaseFields = value + } + if value, ok := _c.mutation.IncludeSoldFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) + _node.IncludeSoldFields = value + } + if value, ok := _c.mutation.DefaultLabelIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) + _node.DefaultLabelIds = value + } + if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: itemtemplate.GroupTable, + Columns: []string{itemtemplate.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.group_item_templates = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.FieldsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.LocationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: itemtemplate.LocationTable, + Columns: []string{itemtemplate.LocationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.item_template_location = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// ItemTemplateCreateBulk is the builder for creating many ItemTemplate entities in bulk. +type ItemTemplateCreateBulk struct { + config + err error + builders []*ItemTemplateCreate +} + +// Save creates the ItemTemplate entities in the database. +func (_c *ItemTemplateCreateBulk) Save(ctx context.Context) ([]*ItemTemplate, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ItemTemplate, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*ItemTemplateMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *ItemTemplateCreateBulk) SaveX(ctx context.Context) []*ItemTemplate { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ItemTemplateCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ItemTemplateCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/itemtemplate_delete.go b/backend/internal/data/ent/itemtemplate_delete.go new file mode 100644 index 00000000..843804df --- /dev/null +++ b/backend/internal/data/ent/itemtemplate_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" +) + +// ItemTemplateDelete is the builder for deleting a ItemTemplate entity. +type ItemTemplateDelete struct { + config + hooks []Hook + mutation *ItemTemplateMutation +} + +// Where appends a list predicates to the ItemTemplateDelete builder. +func (_d *ItemTemplateDelete) Where(ps ...predicate.ItemTemplate) *ItemTemplateDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ItemTemplateDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ItemTemplateDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ItemTemplateDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(itemtemplate.Table, sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// ItemTemplateDeleteOne is the builder for deleting a single ItemTemplate entity. +type ItemTemplateDeleteOne struct { + _d *ItemTemplateDelete +} + +// Where appends a list predicates to the ItemTemplateDelete builder. +func (_d *ItemTemplateDeleteOne) Where(ps ...predicate.ItemTemplate) *ItemTemplateDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ItemTemplateDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{itemtemplate.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ItemTemplateDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/itemtemplate_query.go b/backend/internal/data/ent/itemtemplate_query.go new file mode 100644 index 00000000..5e339f1f --- /dev/null +++ b/backend/internal/data/ent/itemtemplate_query.go @@ -0,0 +1,766 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// ItemTemplateQuery is the builder for querying ItemTemplate entities. +type ItemTemplateQuery struct { + config + ctx *QueryContext + order []itemtemplate.OrderOption + inters []Interceptor + predicates []predicate.ItemTemplate + withGroup *GroupQuery + withFields *TemplateFieldQuery + withLocation *LocationQuery + withFKs bool + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the ItemTemplateQuery builder. +func (_q *ItemTemplateQuery) Where(ps ...predicate.ItemTemplate) *ItemTemplateQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ItemTemplateQuery) Limit(limit int) *ItemTemplateQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ItemTemplateQuery) Offset(offset int) *ItemTemplateQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *ItemTemplateQuery) Unique(unique bool) *ItemTemplateQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ItemTemplateQuery) Order(o ...itemtemplate.OrderOption) *ItemTemplateQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryGroup chains the current query on the "group" edge. +func (_q *ItemTemplateQuery) QueryGroup() *GroupQuery { + query := (&GroupClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, selector), + sqlgraph.To(group.Table, group.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, itemtemplate.GroupTable, itemtemplate.GroupColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryFields chains the current query on the "fields" edge. +func (_q *ItemTemplateQuery) QueryFields() *TemplateFieldQuery { + query := (&TemplateFieldClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, selector), + sqlgraph.To(templatefield.Table, templatefield.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, itemtemplate.FieldsTable, itemtemplate.FieldsColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryLocation chains the current query on the "location" edge. +func (_q *ItemTemplateQuery) QueryLocation() *LocationQuery { + query := (&LocationClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(itemtemplate.Table, itemtemplate.FieldID, selector), + sqlgraph.To(location.Table, location.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, itemtemplate.LocationTable, itemtemplate.LocationColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first ItemTemplate entity from the query. +// Returns a *NotFoundError when no ItemTemplate was found. +func (_q *ItemTemplateQuery) First(ctx context.Context) (*ItemTemplate, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{itemtemplate.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ItemTemplateQuery) FirstX(ctx context.Context) *ItemTemplate { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ItemTemplate ID from the query. +// Returns a *NotFoundError when no ItemTemplate ID was found. +func (_q *ItemTemplateQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{itemtemplate.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ItemTemplateQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ItemTemplate entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ItemTemplate entity is found. +// Returns a *NotFoundError when no ItemTemplate entities are found. +func (_q *ItemTemplateQuery) Only(ctx context.Context) (*ItemTemplate, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{itemtemplate.Label} + default: + return nil, &NotSingularError{itemtemplate.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ItemTemplateQuery) OnlyX(ctx context.Context) *ItemTemplate { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ItemTemplate ID in the query. +// Returns a *NotSingularError when more than one ItemTemplate ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ItemTemplateQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{itemtemplate.Label} + default: + err = &NotSingularError{itemtemplate.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ItemTemplateQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of ItemTemplates. +func (_q *ItemTemplateQuery) All(ctx context.Context) ([]*ItemTemplate, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ItemTemplate, *ItemTemplateQuery]() + return withInterceptors[[]*ItemTemplate](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ItemTemplateQuery) AllX(ctx context.Context) []*ItemTemplate { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ItemTemplate IDs. +func (_q *ItemTemplateQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(itemtemplate.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ItemTemplateQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *ItemTemplateQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*ItemTemplateQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ItemTemplateQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *ItemTemplateQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *ItemTemplateQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ItemTemplateQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *ItemTemplateQuery) Clone() *ItemTemplateQuery { + if _q == nil { + return nil + } + return &ItemTemplateQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]itemtemplate.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ItemTemplate{}, _q.predicates...), + withGroup: _q.withGroup.Clone(), + withFields: _q.withFields.Clone(), + withLocation: _q.withLocation.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithGroup tells the query-builder to eager-load the nodes that are connected to +// the "group" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ItemTemplateQuery) WithGroup(opts ...func(*GroupQuery)) *ItemTemplateQuery { + query := (&GroupClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withGroup = query + return _q +} + +// WithFields tells the query-builder to eager-load the nodes that are connected to +// the "fields" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ItemTemplateQuery) WithFields(opts ...func(*TemplateFieldQuery)) *ItemTemplateQuery { + query := (&TemplateFieldClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withFields = query + return _q +} + +// WithLocation tells the query-builder to eager-load the nodes that are connected to +// the "location" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ItemTemplateQuery) WithLocation(opts ...func(*LocationQuery)) *ItemTemplateQuery { + query := (&LocationClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withLocation = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ItemTemplate.Query(). +// GroupBy(itemtemplate.FieldCreatedAt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *ItemTemplateQuery) GroupBy(field string, fields ...string) *ItemTemplateGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ItemTemplateGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = itemtemplate.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// } +// +// client.ItemTemplate.Query(). +// Select(itemtemplate.FieldCreatedAt). +// Scan(ctx, &v) +func (_q *ItemTemplateQuery) Select(fields ...string) *ItemTemplateSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ItemTemplateSelect{ItemTemplateQuery: _q} + sbuild.label = itemtemplate.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ItemTemplateSelect configured with the given aggregations. +func (_q *ItemTemplateQuery) Aggregate(fns ...AggregateFunc) *ItemTemplateSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ItemTemplateQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !itemtemplate.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *ItemTemplateQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ItemTemplate, error) { + var ( + nodes = []*ItemTemplate{} + withFKs = _q.withFKs + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withGroup != nil, + _q.withFields != nil, + _q.withLocation != nil, + } + ) + if _q.withGroup != nil || _q.withLocation != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, itemtemplate.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ItemTemplate).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ItemTemplate{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withGroup; query != nil { + if err := _q.loadGroup(ctx, query, nodes, nil, + func(n *ItemTemplate, e *Group) { n.Edges.Group = e }); err != nil { + return nil, err + } + } + if query := _q.withFields; query != nil { + if err := _q.loadFields(ctx, query, nodes, + func(n *ItemTemplate) { n.Edges.Fields = []*TemplateField{} }, + func(n *ItemTemplate, e *TemplateField) { n.Edges.Fields = append(n.Edges.Fields, e) }); err != nil { + return nil, err + } + } + if query := _q.withLocation; query != nil { + if err := _q.loadLocation(ctx, query, nodes, nil, + func(n *ItemTemplate, e *Location) { n.Edges.Location = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ItemTemplateQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*ItemTemplate, init func(*ItemTemplate), assign func(*ItemTemplate, *Group)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*ItemTemplate) + for i := range nodes { + if nodes[i].group_item_templates == nil { + continue + } + fk := *nodes[i].group_item_templates + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(group.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "group_item_templates" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ItemTemplateQuery) loadFields(ctx context.Context, query *TemplateFieldQuery, nodes []*ItemTemplate, init func(*ItemTemplate), assign func(*ItemTemplate, *TemplateField)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*ItemTemplate) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + query.withFKs = true + query.Where(predicate.TemplateField(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(itemtemplate.FieldsColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.item_template_fields + if fk == nil { + return fmt.Errorf(`foreign-key "item_template_fields" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "item_template_fields" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} +func (_q *ItemTemplateQuery) loadLocation(ctx context.Context, query *LocationQuery, nodes []*ItemTemplate, init func(*ItemTemplate), assign func(*ItemTemplate, *Location)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*ItemTemplate) + for i := range nodes { + if nodes[i].item_template_location == nil { + continue + } + fk := *nodes[i].item_template_location + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(location.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "item_template_location" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *ItemTemplateQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *ItemTemplateQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(itemtemplate.Table, itemtemplate.Columns, sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, itemtemplate.FieldID) + for i := range fields { + if fields[i] != itemtemplate.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *ItemTemplateQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(itemtemplate.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = itemtemplate.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ItemTemplateGroupBy is the group-by builder for ItemTemplate entities. +type ItemTemplateGroupBy struct { + selector + build *ItemTemplateQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ItemTemplateGroupBy) Aggregate(fns ...AggregateFunc) *ItemTemplateGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ItemTemplateGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ItemTemplateQuery, *ItemTemplateGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ItemTemplateGroupBy) sqlScan(ctx context.Context, root *ItemTemplateQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// ItemTemplateSelect is the builder for selecting fields of ItemTemplate entities. +type ItemTemplateSelect struct { + *ItemTemplateQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ItemTemplateSelect) Aggregate(fns ...AggregateFunc) *ItemTemplateSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ItemTemplateSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*ItemTemplateQuery, *ItemTemplateSelect](ctx, _s.ItemTemplateQuery, _s, _s.inters, v) +} + +func (_s *ItemTemplateSelect) sqlScan(ctx context.Context, root *ItemTemplateQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/itemtemplate_update.go b/backend/internal/data/ent/itemtemplate_update.go new file mode 100644 index 00000000..768505ba --- /dev/null +++ b/backend/internal/data/ent/itemtemplate_update.go @@ -0,0 +1,1361 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// ItemTemplateUpdate is the builder for updating ItemTemplate entities. +type ItemTemplateUpdate struct { + config + hooks []Hook + mutation *ItemTemplateMutation +} + +// Where appends a list predicates to the ItemTemplateUpdate builder. +func (_u *ItemTemplateUpdate) Where(ps ...predicate.ItemTemplate) *ItemTemplateUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ItemTemplateUpdate) SetUpdatedAt(v time.Time) *ItemTemplateUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetName sets the "name" field. +func (_u *ItemTemplateUpdate) SetName(v string) *ItemTemplateUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableName(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *ItemTemplateUpdate) SetDescription(v string) *ItemTemplateUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDescription(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ItemTemplateUpdate) ClearDescription() *ItemTemplateUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetNotes sets the "notes" field. +func (_u *ItemTemplateUpdate) SetNotes(v string) *ItemTemplateUpdate { + _u.mutation.SetNotes(v) + return _u +} + +// SetNillableNotes sets the "notes" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableNotes(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetNotes(*v) + } + return _u +} + +// ClearNotes clears the value of the "notes" field. +func (_u *ItemTemplateUpdate) ClearNotes() *ItemTemplateUpdate { + _u.mutation.ClearNotes() + return _u +} + +// SetDefaultQuantity sets the "default_quantity" field. +func (_u *ItemTemplateUpdate) SetDefaultQuantity(v int) *ItemTemplateUpdate { + _u.mutation.ResetDefaultQuantity() + _u.mutation.SetDefaultQuantity(v) + return _u +} + +// SetNillableDefaultQuantity sets the "default_quantity" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultQuantity(v *int) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultQuantity(*v) + } + return _u +} + +// AddDefaultQuantity adds value to the "default_quantity" field. +func (_u *ItemTemplateUpdate) AddDefaultQuantity(v int) *ItemTemplateUpdate { + _u.mutation.AddDefaultQuantity(v) + return _u +} + +// SetDefaultInsured sets the "default_insured" field. +func (_u *ItemTemplateUpdate) SetDefaultInsured(v bool) *ItemTemplateUpdate { + _u.mutation.SetDefaultInsured(v) + return _u +} + +// SetNillableDefaultInsured sets the "default_insured" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultInsured(v *bool) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultInsured(*v) + } + return _u +} + +// SetDefaultName sets the "default_name" field. +func (_u *ItemTemplateUpdate) SetDefaultName(v string) *ItemTemplateUpdate { + _u.mutation.SetDefaultName(v) + return _u +} + +// SetNillableDefaultName sets the "default_name" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultName(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultName(*v) + } + return _u +} + +// ClearDefaultName clears the value of the "default_name" field. +func (_u *ItemTemplateUpdate) ClearDefaultName() *ItemTemplateUpdate { + _u.mutation.ClearDefaultName() + return _u +} + +// SetDefaultDescription sets the "default_description" field. +func (_u *ItemTemplateUpdate) SetDefaultDescription(v string) *ItemTemplateUpdate { + _u.mutation.SetDefaultDescription(v) + return _u +} + +// SetNillableDefaultDescription sets the "default_description" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultDescription(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultDescription(*v) + } + return _u +} + +// ClearDefaultDescription clears the value of the "default_description" field. +func (_u *ItemTemplateUpdate) ClearDefaultDescription() *ItemTemplateUpdate { + _u.mutation.ClearDefaultDescription() + return _u +} + +// SetDefaultManufacturer sets the "default_manufacturer" field. +func (_u *ItemTemplateUpdate) SetDefaultManufacturer(v string) *ItemTemplateUpdate { + _u.mutation.SetDefaultManufacturer(v) + return _u +} + +// SetNillableDefaultManufacturer sets the "default_manufacturer" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultManufacturer(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultManufacturer(*v) + } + return _u +} + +// ClearDefaultManufacturer clears the value of the "default_manufacturer" field. +func (_u *ItemTemplateUpdate) ClearDefaultManufacturer() *ItemTemplateUpdate { + _u.mutation.ClearDefaultManufacturer() + return _u +} + +// SetDefaultModelNumber sets the "default_model_number" field. +func (_u *ItemTemplateUpdate) SetDefaultModelNumber(v string) *ItemTemplateUpdate { + _u.mutation.SetDefaultModelNumber(v) + return _u +} + +// SetNillableDefaultModelNumber sets the "default_model_number" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultModelNumber(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultModelNumber(*v) + } + return _u +} + +// ClearDefaultModelNumber clears the value of the "default_model_number" field. +func (_u *ItemTemplateUpdate) ClearDefaultModelNumber() *ItemTemplateUpdate { + _u.mutation.ClearDefaultModelNumber() + return _u +} + +// SetDefaultLifetimeWarranty sets the "default_lifetime_warranty" field. +func (_u *ItemTemplateUpdate) SetDefaultLifetimeWarranty(v bool) *ItemTemplateUpdate { + _u.mutation.SetDefaultLifetimeWarranty(v) + return _u +} + +// SetNillableDefaultLifetimeWarranty sets the "default_lifetime_warranty" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultLifetimeWarranty(v *bool) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultLifetimeWarranty(*v) + } + return _u +} + +// SetDefaultWarrantyDetails sets the "default_warranty_details" field. +func (_u *ItemTemplateUpdate) SetDefaultWarrantyDetails(v string) *ItemTemplateUpdate { + _u.mutation.SetDefaultWarrantyDetails(v) + return _u +} + +// SetNillableDefaultWarrantyDetails sets the "default_warranty_details" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableDefaultWarrantyDetails(v *string) *ItemTemplateUpdate { + if v != nil { + _u.SetDefaultWarrantyDetails(*v) + } + return _u +} + +// ClearDefaultWarrantyDetails clears the value of the "default_warranty_details" field. +func (_u *ItemTemplateUpdate) ClearDefaultWarrantyDetails() *ItemTemplateUpdate { + _u.mutation.ClearDefaultWarrantyDetails() + return _u +} + +// SetIncludeWarrantyFields sets the "include_warranty_fields" field. +func (_u *ItemTemplateUpdate) SetIncludeWarrantyFields(v bool) *ItemTemplateUpdate { + _u.mutation.SetIncludeWarrantyFields(v) + return _u +} + +// SetNillableIncludeWarrantyFields sets the "include_warranty_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableIncludeWarrantyFields(v *bool) *ItemTemplateUpdate { + if v != nil { + _u.SetIncludeWarrantyFields(*v) + } + return _u +} + +// SetIncludePurchaseFields sets the "include_purchase_fields" field. +func (_u *ItemTemplateUpdate) SetIncludePurchaseFields(v bool) *ItemTemplateUpdate { + _u.mutation.SetIncludePurchaseFields(v) + return _u +} + +// SetNillableIncludePurchaseFields sets the "include_purchase_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableIncludePurchaseFields(v *bool) *ItemTemplateUpdate { + if v != nil { + _u.SetIncludePurchaseFields(*v) + } + return _u +} + +// SetIncludeSoldFields sets the "include_sold_fields" field. +func (_u *ItemTemplateUpdate) SetIncludeSoldFields(v bool) *ItemTemplateUpdate { + _u.mutation.SetIncludeSoldFields(v) + return _u +} + +// SetNillableIncludeSoldFields sets the "include_sold_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableIncludeSoldFields(v *bool) *ItemTemplateUpdate { + if v != nil { + _u.SetIncludeSoldFields(*v) + } + return _u +} + +// SetDefaultLabelIds sets the "default_label_ids" field. +func (_u *ItemTemplateUpdate) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdate { + _u.mutation.SetDefaultLabelIds(v) + return _u +} + +// AppendDefaultLabelIds appends value to the "default_label_ids" field. +func (_u *ItemTemplateUpdate) AppendDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdate { + _u.mutation.AppendDefaultLabelIds(v) + return _u +} + +// ClearDefaultLabelIds clears the value of the "default_label_ids" field. +func (_u *ItemTemplateUpdate) ClearDefaultLabelIds() *ItemTemplateUpdate { + _u.mutation.ClearDefaultLabelIds() + return _u +} + +// SetGroupID sets the "group" edge to the Group entity by ID. +func (_u *ItemTemplateUpdate) SetGroupID(id uuid.UUID) *ItemTemplateUpdate { + _u.mutation.SetGroupID(id) + return _u +} + +// SetGroup sets the "group" edge to the Group entity. +func (_u *ItemTemplateUpdate) SetGroup(v *Group) *ItemTemplateUpdate { + return _u.SetGroupID(v.ID) +} + +// AddFieldIDs adds the "fields" edge to the TemplateField entity by IDs. +func (_u *ItemTemplateUpdate) AddFieldIDs(ids ...uuid.UUID) *ItemTemplateUpdate { + _u.mutation.AddFieldIDs(ids...) + return _u +} + +// AddFields adds the "fields" edges to the TemplateField entity. +func (_u *ItemTemplateUpdate) AddFields(v ...*TemplateField) *ItemTemplateUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddFieldIDs(ids...) +} + +// SetLocationID sets the "location" edge to the Location entity by ID. +func (_u *ItemTemplateUpdate) SetLocationID(id uuid.UUID) *ItemTemplateUpdate { + _u.mutation.SetLocationID(id) + return _u +} + +// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. +func (_u *ItemTemplateUpdate) SetNillableLocationID(id *uuid.UUID) *ItemTemplateUpdate { + if id != nil { + _u = _u.SetLocationID(*id) + } + return _u +} + +// SetLocation sets the "location" edge to the Location entity. +func (_u *ItemTemplateUpdate) SetLocation(v *Location) *ItemTemplateUpdate { + return _u.SetLocationID(v.ID) +} + +// Mutation returns the ItemTemplateMutation object of the builder. +func (_u *ItemTemplateUpdate) Mutation() *ItemTemplateMutation { + return _u.mutation +} + +// ClearGroup clears the "group" edge to the Group entity. +func (_u *ItemTemplateUpdate) ClearGroup() *ItemTemplateUpdate { + _u.mutation.ClearGroup() + return _u +} + +// ClearFields clears all "fields" edges to the TemplateField entity. +func (_u *ItemTemplateUpdate) ClearFields() *ItemTemplateUpdate { + _u.mutation.ClearFields() + return _u +} + +// RemoveFieldIDs removes the "fields" edge to TemplateField entities by IDs. +func (_u *ItemTemplateUpdate) RemoveFieldIDs(ids ...uuid.UUID) *ItemTemplateUpdate { + _u.mutation.RemoveFieldIDs(ids...) + return _u +} + +// RemoveFields removes "fields" edges to TemplateField entities. +func (_u *ItemTemplateUpdate) RemoveFields(v ...*TemplateField) *ItemTemplateUpdate { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveFieldIDs(ids...) +} + +// ClearLocation clears the "location" edge to the Location entity. +func (_u *ItemTemplateUpdate) ClearLocation() *ItemTemplateUpdate { + _u.mutation.ClearLocation() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ItemTemplateUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ItemTemplateUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ItemTemplateUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ItemTemplateUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ItemTemplateUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := itemtemplate.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ItemTemplateUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := itemtemplate.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := itemtemplate.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.description": %w`, err)} + } + } + if v, ok := _u.mutation.Notes(); ok { + if err := itemtemplate.NotesValidator(v); err != nil { + return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.notes": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultName(); ok { + if err := itemtemplate.DefaultNameValidator(v); err != nil { + return &ValidationError{Name: "default_name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_name": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultDescription(); ok { + if err := itemtemplate.DefaultDescriptionValidator(v); err != nil { + return &ValidationError{Name: "default_description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_description": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultManufacturer(); ok { + if err := itemtemplate.DefaultManufacturerValidator(v); err != nil { + return &ValidationError{Name: "default_manufacturer", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_manufacturer": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultModelNumber(); ok { + if err := itemtemplate.DefaultModelNumberValidator(v); err != nil { + return &ValidationError{Name: "default_model_number", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_model_number": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultWarrantyDetails(); ok { + if err := itemtemplate.DefaultWarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "default_warranty_details", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_warranty_details": %w`, err)} + } + } + if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "ItemTemplate.group"`) + } + return nil +} + +func (_u *ItemTemplateUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(itemtemplate.Table, itemtemplate.Columns, sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(itemtemplate.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(itemtemplate.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(itemtemplate.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(itemtemplate.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Notes(); ok { + _spec.SetField(itemtemplate.FieldNotes, field.TypeString, value) + } + if _u.mutation.NotesCleared() { + _spec.ClearField(itemtemplate.FieldNotes, field.TypeString) + } + if value, ok := _u.mutation.DefaultQuantity(); ok { + _spec.SetField(itemtemplate.FieldDefaultQuantity, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedDefaultQuantity(); ok { + _spec.AddField(itemtemplate.FieldDefaultQuantity, field.TypeInt, value) + } + if value, ok := _u.mutation.DefaultInsured(); ok { + _spec.SetField(itemtemplate.FieldDefaultInsured, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultName(); ok { + _spec.SetField(itemtemplate.FieldDefaultName, field.TypeString, value) + } + if _u.mutation.DefaultNameCleared() { + _spec.ClearField(itemtemplate.FieldDefaultName, field.TypeString) + } + if value, ok := _u.mutation.DefaultDescription(); ok { + _spec.SetField(itemtemplate.FieldDefaultDescription, field.TypeString, value) + } + if _u.mutation.DefaultDescriptionCleared() { + _spec.ClearField(itemtemplate.FieldDefaultDescription, field.TypeString) + } + if value, ok := _u.mutation.DefaultManufacturer(); ok { + _spec.SetField(itemtemplate.FieldDefaultManufacturer, field.TypeString, value) + } + if _u.mutation.DefaultManufacturerCleared() { + _spec.ClearField(itemtemplate.FieldDefaultManufacturer, field.TypeString) + } + if value, ok := _u.mutation.DefaultModelNumber(); ok { + _spec.SetField(itemtemplate.FieldDefaultModelNumber, field.TypeString, value) + } + if _u.mutation.DefaultModelNumberCleared() { + _spec.ClearField(itemtemplate.FieldDefaultModelNumber, field.TypeString) + } + if value, ok := _u.mutation.DefaultLifetimeWarranty(); ok { + _spec.SetField(itemtemplate.FieldDefaultLifetimeWarranty, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultWarrantyDetails(); ok { + _spec.SetField(itemtemplate.FieldDefaultWarrantyDetails, field.TypeString, value) + } + if _u.mutation.DefaultWarrantyDetailsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultWarrantyDetails, field.TypeString) + } + if value, ok := _u.mutation.IncludeWarrantyFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeWarrantyFields, field.TypeBool, value) + } + if value, ok := _u.mutation.IncludePurchaseFields(); ok { + _spec.SetField(itemtemplate.FieldIncludePurchaseFields, field.TypeBool, value) + } + if value, ok := _u.mutation.IncludeSoldFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultLabelIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedDefaultLabelIds(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, itemtemplate.FieldDefaultLabelIds, value) + }) + } + if _u.mutation.DefaultLabelIdsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON) + } + if _u.mutation.GroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: itemtemplate.GroupTable, + Columns: []string{itemtemplate.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: itemtemplate.GroupTable, + Columns: []string{itemtemplate.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.FieldsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !_u.mutation.FieldsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.FieldsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.LocationCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: itemtemplate.LocationTable, + Columns: []string{itemtemplate.LocationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LocationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: itemtemplate.LocationTable, + Columns: []string{itemtemplate.LocationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{itemtemplate.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ItemTemplateUpdateOne is the builder for updating a single ItemTemplate entity. +type ItemTemplateUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ItemTemplateMutation +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ItemTemplateUpdateOne) SetUpdatedAt(v time.Time) *ItemTemplateUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetName sets the "name" field. +func (_u *ItemTemplateUpdateOne) SetName(v string) *ItemTemplateUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableName(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *ItemTemplateUpdateOne) SetDescription(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDescription(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *ItemTemplateUpdateOne) ClearDescription() *ItemTemplateUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetNotes sets the "notes" field. +func (_u *ItemTemplateUpdateOne) SetNotes(v string) *ItemTemplateUpdateOne { + _u.mutation.SetNotes(v) + return _u +} + +// SetNillableNotes sets the "notes" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableNotes(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetNotes(*v) + } + return _u +} + +// ClearNotes clears the value of the "notes" field. +func (_u *ItemTemplateUpdateOne) ClearNotes() *ItemTemplateUpdateOne { + _u.mutation.ClearNotes() + return _u +} + +// SetDefaultQuantity sets the "default_quantity" field. +func (_u *ItemTemplateUpdateOne) SetDefaultQuantity(v int) *ItemTemplateUpdateOne { + _u.mutation.ResetDefaultQuantity() + _u.mutation.SetDefaultQuantity(v) + return _u +} + +// SetNillableDefaultQuantity sets the "default_quantity" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultQuantity(v *int) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultQuantity(*v) + } + return _u +} + +// AddDefaultQuantity adds value to the "default_quantity" field. +func (_u *ItemTemplateUpdateOne) AddDefaultQuantity(v int) *ItemTemplateUpdateOne { + _u.mutation.AddDefaultQuantity(v) + return _u +} + +// SetDefaultInsured sets the "default_insured" field. +func (_u *ItemTemplateUpdateOne) SetDefaultInsured(v bool) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultInsured(v) + return _u +} + +// SetNillableDefaultInsured sets the "default_insured" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultInsured(v *bool) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultInsured(*v) + } + return _u +} + +// SetDefaultName sets the "default_name" field. +func (_u *ItemTemplateUpdateOne) SetDefaultName(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultName(v) + return _u +} + +// SetNillableDefaultName sets the "default_name" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultName(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultName(*v) + } + return _u +} + +// ClearDefaultName clears the value of the "default_name" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultName() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultName() + return _u +} + +// SetDefaultDescription sets the "default_description" field. +func (_u *ItemTemplateUpdateOne) SetDefaultDescription(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultDescription(v) + return _u +} + +// SetNillableDefaultDescription sets the "default_description" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultDescription(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultDescription(*v) + } + return _u +} + +// ClearDefaultDescription clears the value of the "default_description" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultDescription() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultDescription() + return _u +} + +// SetDefaultManufacturer sets the "default_manufacturer" field. +func (_u *ItemTemplateUpdateOne) SetDefaultManufacturer(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultManufacturer(v) + return _u +} + +// SetNillableDefaultManufacturer sets the "default_manufacturer" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultManufacturer(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultManufacturer(*v) + } + return _u +} + +// ClearDefaultManufacturer clears the value of the "default_manufacturer" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultManufacturer() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultManufacturer() + return _u +} + +// SetDefaultModelNumber sets the "default_model_number" field. +func (_u *ItemTemplateUpdateOne) SetDefaultModelNumber(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultModelNumber(v) + return _u +} + +// SetNillableDefaultModelNumber sets the "default_model_number" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultModelNumber(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultModelNumber(*v) + } + return _u +} + +// ClearDefaultModelNumber clears the value of the "default_model_number" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultModelNumber() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultModelNumber() + return _u +} + +// SetDefaultLifetimeWarranty sets the "default_lifetime_warranty" field. +func (_u *ItemTemplateUpdateOne) SetDefaultLifetimeWarranty(v bool) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultLifetimeWarranty(v) + return _u +} + +// SetNillableDefaultLifetimeWarranty sets the "default_lifetime_warranty" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultLifetimeWarranty(v *bool) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultLifetimeWarranty(*v) + } + return _u +} + +// SetDefaultWarrantyDetails sets the "default_warranty_details" field. +func (_u *ItemTemplateUpdateOne) SetDefaultWarrantyDetails(v string) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultWarrantyDetails(v) + return _u +} + +// SetNillableDefaultWarrantyDetails sets the "default_warranty_details" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableDefaultWarrantyDetails(v *string) *ItemTemplateUpdateOne { + if v != nil { + _u.SetDefaultWarrantyDetails(*v) + } + return _u +} + +// ClearDefaultWarrantyDetails clears the value of the "default_warranty_details" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultWarrantyDetails() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultWarrantyDetails() + return _u +} + +// SetIncludeWarrantyFields sets the "include_warranty_fields" field. +func (_u *ItemTemplateUpdateOne) SetIncludeWarrantyFields(v bool) *ItemTemplateUpdateOne { + _u.mutation.SetIncludeWarrantyFields(v) + return _u +} + +// SetNillableIncludeWarrantyFields sets the "include_warranty_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableIncludeWarrantyFields(v *bool) *ItemTemplateUpdateOne { + if v != nil { + _u.SetIncludeWarrantyFields(*v) + } + return _u +} + +// SetIncludePurchaseFields sets the "include_purchase_fields" field. +func (_u *ItemTemplateUpdateOne) SetIncludePurchaseFields(v bool) *ItemTemplateUpdateOne { + _u.mutation.SetIncludePurchaseFields(v) + return _u +} + +// SetNillableIncludePurchaseFields sets the "include_purchase_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableIncludePurchaseFields(v *bool) *ItemTemplateUpdateOne { + if v != nil { + _u.SetIncludePurchaseFields(*v) + } + return _u +} + +// SetIncludeSoldFields sets the "include_sold_fields" field. +func (_u *ItemTemplateUpdateOne) SetIncludeSoldFields(v bool) *ItemTemplateUpdateOne { + _u.mutation.SetIncludeSoldFields(v) + return _u +} + +// SetNillableIncludeSoldFields sets the "include_sold_fields" field if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableIncludeSoldFields(v *bool) *ItemTemplateUpdateOne { + if v != nil { + _u.SetIncludeSoldFields(*v) + } + return _u +} + +// SetDefaultLabelIds sets the "default_label_ids" field. +func (_u *ItemTemplateUpdateOne) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultLabelIds(v) + return _u +} + +// AppendDefaultLabelIds appends value to the "default_label_ids" field. +func (_u *ItemTemplateUpdateOne) AppendDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.AppendDefaultLabelIds(v) + return _u +} + +// ClearDefaultLabelIds clears the value of the "default_label_ids" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultLabelIds() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultLabelIds() + return _u +} + +// SetGroupID sets the "group" edge to the Group entity by ID. +func (_u *ItemTemplateUpdateOne) SetGroupID(id uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.SetGroupID(id) + return _u +} + +// SetGroup sets the "group" edge to the Group entity. +func (_u *ItemTemplateUpdateOne) SetGroup(v *Group) *ItemTemplateUpdateOne { + return _u.SetGroupID(v.ID) +} + +// AddFieldIDs adds the "fields" edge to the TemplateField entity by IDs. +func (_u *ItemTemplateUpdateOne) AddFieldIDs(ids ...uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.AddFieldIDs(ids...) + return _u +} + +// AddFields adds the "fields" edges to the TemplateField entity. +func (_u *ItemTemplateUpdateOne) AddFields(v ...*TemplateField) *ItemTemplateUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddFieldIDs(ids...) +} + +// SetLocationID sets the "location" edge to the Location entity by ID. +func (_u *ItemTemplateUpdateOne) SetLocationID(id uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.SetLocationID(id) + return _u +} + +// SetNillableLocationID sets the "location" edge to the Location entity by ID if the given value is not nil. +func (_u *ItemTemplateUpdateOne) SetNillableLocationID(id *uuid.UUID) *ItemTemplateUpdateOne { + if id != nil { + _u = _u.SetLocationID(*id) + } + return _u +} + +// SetLocation sets the "location" edge to the Location entity. +func (_u *ItemTemplateUpdateOne) SetLocation(v *Location) *ItemTemplateUpdateOne { + return _u.SetLocationID(v.ID) +} + +// Mutation returns the ItemTemplateMutation object of the builder. +func (_u *ItemTemplateUpdateOne) Mutation() *ItemTemplateMutation { + return _u.mutation +} + +// ClearGroup clears the "group" edge to the Group entity. +func (_u *ItemTemplateUpdateOne) ClearGroup() *ItemTemplateUpdateOne { + _u.mutation.ClearGroup() + return _u +} + +// ClearFields clears all "fields" edges to the TemplateField entity. +func (_u *ItemTemplateUpdateOne) ClearFields() *ItemTemplateUpdateOne { + _u.mutation.ClearFields() + return _u +} + +// RemoveFieldIDs removes the "fields" edge to TemplateField entities by IDs. +func (_u *ItemTemplateUpdateOne) RemoveFieldIDs(ids ...uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.RemoveFieldIDs(ids...) + return _u +} + +// RemoveFields removes "fields" edges to TemplateField entities. +func (_u *ItemTemplateUpdateOne) RemoveFields(v ...*TemplateField) *ItemTemplateUpdateOne { + ids := make([]uuid.UUID, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveFieldIDs(ids...) +} + +// ClearLocation clears the "location" edge to the Location entity. +func (_u *ItemTemplateUpdateOne) ClearLocation() *ItemTemplateUpdateOne { + _u.mutation.ClearLocation() + return _u +} + +// Where appends a list predicates to the ItemTemplateUpdate builder. +func (_u *ItemTemplateUpdateOne) Where(ps ...predicate.ItemTemplate) *ItemTemplateUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *ItemTemplateUpdateOne) Select(field string, fields ...string) *ItemTemplateUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ItemTemplate entity. +func (_u *ItemTemplateUpdateOne) Save(ctx context.Context) (*ItemTemplate, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ItemTemplateUpdateOne) SaveX(ctx context.Context) *ItemTemplate { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ItemTemplateUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ItemTemplateUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ItemTemplateUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := itemtemplate.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ItemTemplateUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := itemtemplate.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := itemtemplate.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.description": %w`, err)} + } + } + if v, ok := _u.mutation.Notes(); ok { + if err := itemtemplate.NotesValidator(v); err != nil { + return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.notes": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultName(); ok { + if err := itemtemplate.DefaultNameValidator(v); err != nil { + return &ValidationError{Name: "default_name", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_name": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultDescription(); ok { + if err := itemtemplate.DefaultDescriptionValidator(v); err != nil { + return &ValidationError{Name: "default_description", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_description": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultManufacturer(); ok { + if err := itemtemplate.DefaultManufacturerValidator(v); err != nil { + return &ValidationError{Name: "default_manufacturer", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_manufacturer": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultModelNumber(); ok { + if err := itemtemplate.DefaultModelNumberValidator(v); err != nil { + return &ValidationError{Name: "default_model_number", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_model_number": %w`, err)} + } + } + if v, ok := _u.mutation.DefaultWarrantyDetails(); ok { + if err := itemtemplate.DefaultWarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "default_warranty_details", err: fmt.Errorf(`ent: validator failed for field "ItemTemplate.default_warranty_details": %w`, err)} + } + } + if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "ItemTemplate.group"`) + } + return nil +} + +func (_u *ItemTemplateUpdateOne) sqlSave(ctx context.Context) (_node *ItemTemplate, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(itemtemplate.Table, itemtemplate.Columns, sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ItemTemplate.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, itemtemplate.FieldID) + for _, f := range fields { + if !itemtemplate.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != itemtemplate.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(itemtemplate.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(itemtemplate.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(itemtemplate.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(itemtemplate.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.Notes(); ok { + _spec.SetField(itemtemplate.FieldNotes, field.TypeString, value) + } + if _u.mutation.NotesCleared() { + _spec.ClearField(itemtemplate.FieldNotes, field.TypeString) + } + if value, ok := _u.mutation.DefaultQuantity(); ok { + _spec.SetField(itemtemplate.FieldDefaultQuantity, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedDefaultQuantity(); ok { + _spec.AddField(itemtemplate.FieldDefaultQuantity, field.TypeInt, value) + } + if value, ok := _u.mutation.DefaultInsured(); ok { + _spec.SetField(itemtemplate.FieldDefaultInsured, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultName(); ok { + _spec.SetField(itemtemplate.FieldDefaultName, field.TypeString, value) + } + if _u.mutation.DefaultNameCleared() { + _spec.ClearField(itemtemplate.FieldDefaultName, field.TypeString) + } + if value, ok := _u.mutation.DefaultDescription(); ok { + _spec.SetField(itemtemplate.FieldDefaultDescription, field.TypeString, value) + } + if _u.mutation.DefaultDescriptionCleared() { + _spec.ClearField(itemtemplate.FieldDefaultDescription, field.TypeString) + } + if value, ok := _u.mutation.DefaultManufacturer(); ok { + _spec.SetField(itemtemplate.FieldDefaultManufacturer, field.TypeString, value) + } + if _u.mutation.DefaultManufacturerCleared() { + _spec.ClearField(itemtemplate.FieldDefaultManufacturer, field.TypeString) + } + if value, ok := _u.mutation.DefaultModelNumber(); ok { + _spec.SetField(itemtemplate.FieldDefaultModelNumber, field.TypeString, value) + } + if _u.mutation.DefaultModelNumberCleared() { + _spec.ClearField(itemtemplate.FieldDefaultModelNumber, field.TypeString) + } + if value, ok := _u.mutation.DefaultLifetimeWarranty(); ok { + _spec.SetField(itemtemplate.FieldDefaultLifetimeWarranty, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultWarrantyDetails(); ok { + _spec.SetField(itemtemplate.FieldDefaultWarrantyDetails, field.TypeString, value) + } + if _u.mutation.DefaultWarrantyDetailsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultWarrantyDetails, field.TypeString) + } + if value, ok := _u.mutation.IncludeWarrantyFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeWarrantyFields, field.TypeBool, value) + } + if value, ok := _u.mutation.IncludePurchaseFields(); ok { + _spec.SetField(itemtemplate.FieldIncludePurchaseFields, field.TypeBool, value) + } + if value, ok := _u.mutation.IncludeSoldFields(); ok { + _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) + } + if value, ok := _u.mutation.DefaultLabelIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedDefaultLabelIds(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, itemtemplate.FieldDefaultLabelIds, value) + }) + } + if _u.mutation.DefaultLabelIdsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON) + } + if _u.mutation.GroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: itemtemplate.GroupTable, + Columns: []string{itemtemplate.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: itemtemplate.GroupTable, + Columns: []string{itemtemplate.GroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.FieldsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedFieldsIDs(); len(nodes) > 0 && !_u.mutation.FieldsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.FieldsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: itemtemplate.FieldsTable, + Columns: []string{itemtemplate.FieldsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.LocationCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: itemtemplate.LocationTable, + Columns: []string{itemtemplate.LocationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.LocationIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: itemtemplate.LocationTable, + Columns: []string{itemtemplate.LocationColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &ItemTemplate{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{itemtemplate.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.go index 6669df41..ef6161d8 100644 --- a/backend/internal/data/ent/migrate/schema.go +++ b/backend/internal/data/ent/migrate/schema.go @@ -246,6 +246,56 @@ var ( }, }, } + // ItemTemplatesColumns holds the columns for the "item_templates" table. + ItemTemplatesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "name", Type: field.TypeString, Size: 255}, + {Name: "description", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "notes", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "default_quantity", Type: field.TypeInt, Default: 1}, + {Name: "default_insured", Type: field.TypeBool, Default: false}, + {Name: "default_name", Type: field.TypeString, Nullable: true, Size: 255}, + {Name: "default_description", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "default_manufacturer", Type: field.TypeString, Nullable: true, Size: 255}, + {Name: "default_model_number", Type: field.TypeString, Nullable: true, Size: 255}, + {Name: "default_lifetime_warranty", Type: field.TypeBool, Default: false}, + {Name: "default_warranty_details", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "include_warranty_fields", Type: field.TypeBool, Default: false}, + {Name: "include_purchase_fields", Type: field.TypeBool, Default: false}, + {Name: "include_sold_fields", Type: field.TypeBool, Default: false}, + {Name: "default_label_ids", Type: field.TypeJSON, Nullable: true}, + {Name: "group_item_templates", Type: field.TypeUUID}, + {Name: "item_template_location", Type: field.TypeUUID, Nullable: true}, + } + // ItemTemplatesTable holds the schema information for the "item_templates" table. + ItemTemplatesTable = &schema.Table{ + Name: "item_templates", + Columns: ItemTemplatesColumns, + PrimaryKey: []*schema.Column{ItemTemplatesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "item_templates_groups_item_templates", + Columns: []*schema.Column{ItemTemplatesColumns[18]}, + RefColumns: []*schema.Column{GroupsColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "item_templates_locations_location", + Columns: []*schema.Column{ItemTemplatesColumns[19]}, + RefColumns: []*schema.Column{LocationsColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + Indexes: []*schema.Index{ + { + Name: "itemtemplate_name", + Unique: false, + Columns: []*schema.Column{ItemTemplatesColumns[3]}, + }, + }, + } // LabelsColumns holds the columns for the "labels" table. LabelsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -379,6 +429,31 @@ var ( }, }, } + // TemplateFieldsColumns holds the columns for the "template_fields" table. + TemplateFieldsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "name", Type: field.TypeString, Size: 255}, + {Name: "description", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "type", Type: field.TypeEnum, Enums: []string{"text"}}, + {Name: "text_value", Type: field.TypeString, Nullable: true, Size: 500}, + {Name: "item_template_fields", Type: field.TypeUUID, Nullable: true}, + } + // TemplateFieldsTable holds the schema information for the "template_fields" table. + TemplateFieldsTable = &schema.Table{ + Name: "template_fields", + Columns: TemplateFieldsColumns, + PrimaryKey: []*schema.Column{TemplateFieldsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "template_fields_item_templates_fields", + Columns: []*schema.Column{TemplateFieldsColumns[7]}, + RefColumns: []*schema.Column{ItemTemplatesColumns[0]}, + OnDelete: schema.Cascade, + }, + }, + } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -450,10 +525,12 @@ var ( GroupInvitationTokensTable, ItemsTable, ItemFieldsTable, + ItemTemplatesTable, LabelsTable, LocationsTable, MaintenanceEntriesTable, NotifiersTable, + TemplateFieldsTable, UsersTable, LabelItemsTable, } @@ -469,12 +546,15 @@ func init() { ItemsTable.ForeignKeys[1].RefTable = ItemsTable ItemsTable.ForeignKeys[2].RefTable = LocationsTable ItemFieldsTable.ForeignKeys[0].RefTable = ItemsTable + ItemTemplatesTable.ForeignKeys[0].RefTable = GroupsTable + ItemTemplatesTable.ForeignKeys[1].RefTable = LocationsTable LabelsTable.ForeignKeys[0].RefTable = GroupsTable LocationsTable.ForeignKeys[0].RefTable = GroupsTable LocationsTable.ForeignKeys[1].RefTable = LocationsTable MaintenanceEntriesTable.ForeignKeys[0].RefTable = ItemsTable NotifiersTable.ForeignKeys[0].RefTable = GroupsTable NotifiersTable.ForeignKeys[1].RefTable = UsersTable + TemplateFieldsTable.ForeignKeys[0].RefTable = ItemTemplatesTable UsersTable.ForeignKeys[0].RefTable = GroupsTable LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.go index 22908884..f5a1b13d 100644 --- a/backend/internal/data/ent/mutation.go +++ b/backend/internal/data/ent/mutation.go @@ -19,11 +19,13 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -43,10 +45,12 @@ const ( TypeGroupInvitationToken = "GroupInvitationToken" TypeItem = "Item" TypeItemField = "ItemField" + TypeItemTemplate = "ItemTemplate" TypeLabel = "Label" TypeLocation = "Location" TypeMaintenanceEntry = "MaintenanceEntry" TypeNotifier = "Notifier" + TypeTemplateField = "TemplateField" TypeUser = "User" ) @@ -1874,6 +1878,9 @@ type GroupMutation struct { notifiers map[uuid.UUID]struct{} removednotifiers map[uuid.UUID]struct{} clearednotifiers bool + item_templates map[uuid.UUID]struct{} + removeditem_templates map[uuid.UUID]struct{} + cleareditem_templates bool done bool oldValue func(context.Context) (*Group, error) predicates []predicate.Group @@ -2451,6 +2458,60 @@ func (m *GroupMutation) ResetNotifiers() { m.removednotifiers = nil } +// AddItemTemplateIDs adds the "item_templates" edge to the ItemTemplate entity by ids. +func (m *GroupMutation) AddItemTemplateIDs(ids ...uuid.UUID) { + if m.item_templates == nil { + m.item_templates = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.item_templates[ids[i]] = struct{}{} + } +} + +// ClearItemTemplates clears the "item_templates" edge to the ItemTemplate entity. +func (m *GroupMutation) ClearItemTemplates() { + m.cleareditem_templates = true +} + +// ItemTemplatesCleared reports if the "item_templates" edge to the ItemTemplate entity was cleared. +func (m *GroupMutation) ItemTemplatesCleared() bool { + return m.cleareditem_templates +} + +// RemoveItemTemplateIDs removes the "item_templates" edge to the ItemTemplate entity by IDs. +func (m *GroupMutation) RemoveItemTemplateIDs(ids ...uuid.UUID) { + if m.removeditem_templates == nil { + m.removeditem_templates = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.item_templates, ids[i]) + m.removeditem_templates[ids[i]] = struct{}{} + } +} + +// RemovedItemTemplates returns the removed IDs of the "item_templates" edge to the ItemTemplate entity. +func (m *GroupMutation) RemovedItemTemplatesIDs() (ids []uuid.UUID) { + for id := range m.removeditem_templates { + ids = append(ids, id) + } + return +} + +// ItemTemplatesIDs returns the "item_templates" edge IDs in the mutation. +func (m *GroupMutation) ItemTemplatesIDs() (ids []uuid.UUID) { + for id := range m.item_templates { + ids = append(ids, id) + } + return +} + +// ResetItemTemplates resets all changes to the "item_templates" edge. +func (m *GroupMutation) ResetItemTemplates() { + m.item_templates = nil + m.cleareditem_templates = false + m.removeditem_templates = nil +} + // Where appends a list predicates to the GroupMutation builder. func (m *GroupMutation) Where(ps ...predicate.Group) { m.predicates = append(m.predicates, ps...) @@ -2635,7 +2696,7 @@ func (m *GroupMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *GroupMutation) AddedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.users != nil { edges = append(edges, group.EdgeUsers) } @@ -2654,6 +2715,9 @@ func (m *GroupMutation) AddedEdges() []string { if m.notifiers != nil { edges = append(edges, group.EdgeNotifiers) } + if m.item_templates != nil { + edges = append(edges, group.EdgeItemTemplates) + } return edges } @@ -2697,13 +2761,19 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case group.EdgeItemTemplates: + ids := make([]ent.Value, 0, len(m.item_templates)) + for id := range m.item_templates { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *GroupMutation) RemovedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.removedusers != nil { edges = append(edges, group.EdgeUsers) } @@ -2722,6 +2792,9 @@ func (m *GroupMutation) RemovedEdges() []string { if m.removednotifiers != nil { edges = append(edges, group.EdgeNotifiers) } + if m.removeditem_templates != nil { + edges = append(edges, group.EdgeItemTemplates) + } return edges } @@ -2765,13 +2838,19 @@ func (m *GroupMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case group.EdgeItemTemplates: + ids := make([]ent.Value, 0, len(m.removeditem_templates)) + for id := range m.removeditem_templates { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *GroupMutation) ClearedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.clearedusers { edges = append(edges, group.EdgeUsers) } @@ -2790,6 +2869,9 @@ func (m *GroupMutation) ClearedEdges() []string { if m.clearednotifiers { edges = append(edges, group.EdgeNotifiers) } + if m.cleareditem_templates { + edges = append(edges, group.EdgeItemTemplates) + } return edges } @@ -2809,6 +2891,8 @@ func (m *GroupMutation) EdgeCleared(name string) bool { return m.clearedinvitation_tokens case group.EdgeNotifiers: return m.clearednotifiers + case group.EdgeItemTemplates: + return m.cleareditem_templates } return false } @@ -2843,6 +2927,9 @@ func (m *GroupMutation) ResetEdge(name string) error { case group.EdgeNotifiers: m.ResetNotifiers() return nil + case group.EdgeItemTemplates: + m.ResetItemTemplates() + return nil } return fmt.Errorf("unknown Group edge %s", name) } @@ -6987,6 +7074,1621 @@ func (m *ItemFieldMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ItemField edge %s", name) } +// ItemTemplateMutation represents an operation that mutates the ItemTemplate nodes in the graph. +type ItemTemplateMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + name *string + description *string + notes *string + default_quantity *int + adddefault_quantity *int + default_insured *bool + default_name *string + default_description *string + default_manufacturer *string + default_model_number *string + default_lifetime_warranty *bool + default_warranty_details *string + include_warranty_fields *bool + include_purchase_fields *bool + include_sold_fields *bool + default_label_ids *[]uuid.UUID + appenddefault_label_ids []uuid.UUID + clearedFields map[string]struct{} + group *uuid.UUID + clearedgroup bool + fields map[uuid.UUID]struct{} + removedfields map[uuid.UUID]struct{} + clearedfields bool + location *uuid.UUID + clearedlocation bool + done bool + oldValue func(context.Context) (*ItemTemplate, error) + predicates []predicate.ItemTemplate +} + +var _ ent.Mutation = (*ItemTemplateMutation)(nil) + +// itemtemplateOption allows management of the mutation configuration using functional options. +type itemtemplateOption func(*ItemTemplateMutation) + +// newItemTemplateMutation creates new mutation for the ItemTemplate entity. +func newItemTemplateMutation(c config, op Op, opts ...itemtemplateOption) *ItemTemplateMutation { + m := &ItemTemplateMutation{ + config: c, + op: op, + typ: TypeItemTemplate, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withItemTemplateID sets the ID field of the mutation. +func withItemTemplateID(id uuid.UUID) itemtemplateOption { + return func(m *ItemTemplateMutation) { + var ( + err error + once sync.Once + value *ItemTemplate + ) + m.oldValue = func(ctx context.Context) (*ItemTemplate, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ItemTemplate.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withItemTemplate sets the old ItemTemplate of the mutation. +func withItemTemplate(node *ItemTemplate) itemtemplateOption { + return func(m *ItemTemplateMutation) { + m.oldValue = func(context.Context) (*ItemTemplate, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m ItemTemplateMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ItemTemplateMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ItemTemplate entities. +func (m *ItemTemplateMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *ItemTemplateMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ItemTemplateMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().ItemTemplate.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *ItemTemplateMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ItemTemplateMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ItemTemplateMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ItemTemplateMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ItemTemplateMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ItemTemplateMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetName sets the "name" field. +func (m *ItemTemplateMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ItemTemplateMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *ItemTemplateMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *ItemTemplateMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *ItemTemplateMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *ItemTemplateMutation) ClearDescription() { + m.description = nil + m.clearedFields[itemtemplate.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ItemTemplateMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *ItemTemplateMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, itemtemplate.FieldDescription) +} + +// SetNotes sets the "notes" field. +func (m *ItemTemplateMutation) SetNotes(s string) { + m.notes = &s +} + +// Notes returns the value of the "notes" field in the mutation. +func (m *ItemTemplateMutation) Notes() (r string, exists bool) { + v := m.notes + if v == nil { + return + } + return *v, true +} + +// OldNotes returns the old "notes" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldNotes(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNotes is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNotes requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNotes: %w", err) + } + return oldValue.Notes, nil +} + +// ClearNotes clears the value of the "notes" field. +func (m *ItemTemplateMutation) ClearNotes() { + m.notes = nil + m.clearedFields[itemtemplate.FieldNotes] = struct{}{} +} + +// NotesCleared returns if the "notes" field was cleared in this mutation. +func (m *ItemTemplateMutation) NotesCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldNotes] + return ok +} + +// ResetNotes resets all changes to the "notes" field. +func (m *ItemTemplateMutation) ResetNotes() { + m.notes = nil + delete(m.clearedFields, itemtemplate.FieldNotes) +} + +// SetDefaultQuantity sets the "default_quantity" field. +func (m *ItemTemplateMutation) SetDefaultQuantity(i int) { + m.default_quantity = &i + m.adddefault_quantity = nil +} + +// DefaultQuantity returns the value of the "default_quantity" field in the mutation. +func (m *ItemTemplateMutation) DefaultQuantity() (r int, exists bool) { + v := m.default_quantity + if v == nil { + return + } + return *v, true +} + +// OldDefaultQuantity returns the old "default_quantity" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultQuantity(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultQuantity is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultQuantity requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultQuantity: %w", err) + } + return oldValue.DefaultQuantity, nil +} + +// AddDefaultQuantity adds i to the "default_quantity" field. +func (m *ItemTemplateMutation) AddDefaultQuantity(i int) { + if m.adddefault_quantity != nil { + *m.adddefault_quantity += i + } else { + m.adddefault_quantity = &i + } +} + +// AddedDefaultQuantity returns the value that was added to the "default_quantity" field in this mutation. +func (m *ItemTemplateMutation) AddedDefaultQuantity() (r int, exists bool) { + v := m.adddefault_quantity + if v == nil { + return + } + return *v, true +} + +// ResetDefaultQuantity resets all changes to the "default_quantity" field. +func (m *ItemTemplateMutation) ResetDefaultQuantity() { + m.default_quantity = nil + m.adddefault_quantity = nil +} + +// SetDefaultInsured sets the "default_insured" field. +func (m *ItemTemplateMutation) SetDefaultInsured(b bool) { + m.default_insured = &b +} + +// DefaultInsured returns the value of the "default_insured" field in the mutation. +func (m *ItemTemplateMutation) DefaultInsured() (r bool, exists bool) { + v := m.default_insured + if v == nil { + return + } + return *v, true +} + +// OldDefaultInsured returns the old "default_insured" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultInsured(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultInsured is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultInsured requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultInsured: %w", err) + } + return oldValue.DefaultInsured, nil +} + +// ResetDefaultInsured resets all changes to the "default_insured" field. +func (m *ItemTemplateMutation) ResetDefaultInsured() { + m.default_insured = nil +} + +// SetDefaultName sets the "default_name" field. +func (m *ItemTemplateMutation) SetDefaultName(s string) { + m.default_name = &s +} + +// DefaultName returns the value of the "default_name" field in the mutation. +func (m *ItemTemplateMutation) DefaultName() (r string, exists bool) { + v := m.default_name + if v == nil { + return + } + return *v, true +} + +// OldDefaultName returns the old "default_name" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultName: %w", err) + } + return oldValue.DefaultName, nil +} + +// ClearDefaultName clears the value of the "default_name" field. +func (m *ItemTemplateMutation) ClearDefaultName() { + m.default_name = nil + m.clearedFields[itemtemplate.FieldDefaultName] = struct{}{} +} + +// DefaultNameCleared returns if the "default_name" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultNameCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultName] + return ok +} + +// ResetDefaultName resets all changes to the "default_name" field. +func (m *ItemTemplateMutation) ResetDefaultName() { + m.default_name = nil + delete(m.clearedFields, itemtemplate.FieldDefaultName) +} + +// SetDefaultDescription sets the "default_description" field. +func (m *ItemTemplateMutation) SetDefaultDescription(s string) { + m.default_description = &s +} + +// DefaultDescription returns the value of the "default_description" field in the mutation. +func (m *ItemTemplateMutation) DefaultDescription() (r string, exists bool) { + v := m.default_description + if v == nil { + return + } + return *v, true +} + +// OldDefaultDescription returns the old "default_description" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultDescription: %w", err) + } + return oldValue.DefaultDescription, nil +} + +// ClearDefaultDescription clears the value of the "default_description" field. +func (m *ItemTemplateMutation) ClearDefaultDescription() { + m.default_description = nil + m.clearedFields[itemtemplate.FieldDefaultDescription] = struct{}{} +} + +// DefaultDescriptionCleared returns if the "default_description" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultDescriptionCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultDescription] + return ok +} + +// ResetDefaultDescription resets all changes to the "default_description" field. +func (m *ItemTemplateMutation) ResetDefaultDescription() { + m.default_description = nil + delete(m.clearedFields, itemtemplate.FieldDefaultDescription) +} + +// SetDefaultManufacturer sets the "default_manufacturer" field. +func (m *ItemTemplateMutation) SetDefaultManufacturer(s string) { + m.default_manufacturer = &s +} + +// DefaultManufacturer returns the value of the "default_manufacturer" field in the mutation. +func (m *ItemTemplateMutation) DefaultManufacturer() (r string, exists bool) { + v := m.default_manufacturer + if v == nil { + return + } + return *v, true +} + +// OldDefaultManufacturer returns the old "default_manufacturer" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultManufacturer(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultManufacturer is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultManufacturer requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultManufacturer: %w", err) + } + return oldValue.DefaultManufacturer, nil +} + +// ClearDefaultManufacturer clears the value of the "default_manufacturer" field. +func (m *ItemTemplateMutation) ClearDefaultManufacturer() { + m.default_manufacturer = nil + m.clearedFields[itemtemplate.FieldDefaultManufacturer] = struct{}{} +} + +// DefaultManufacturerCleared returns if the "default_manufacturer" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultManufacturerCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultManufacturer] + return ok +} + +// ResetDefaultManufacturer resets all changes to the "default_manufacturer" field. +func (m *ItemTemplateMutation) ResetDefaultManufacturer() { + m.default_manufacturer = nil + delete(m.clearedFields, itemtemplate.FieldDefaultManufacturer) +} + +// SetDefaultModelNumber sets the "default_model_number" field. +func (m *ItemTemplateMutation) SetDefaultModelNumber(s string) { + m.default_model_number = &s +} + +// DefaultModelNumber returns the value of the "default_model_number" field in the mutation. +func (m *ItemTemplateMutation) DefaultModelNumber() (r string, exists bool) { + v := m.default_model_number + if v == nil { + return + } + return *v, true +} + +// OldDefaultModelNumber returns the old "default_model_number" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultModelNumber(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultModelNumber is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultModelNumber requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultModelNumber: %w", err) + } + return oldValue.DefaultModelNumber, nil +} + +// ClearDefaultModelNumber clears the value of the "default_model_number" field. +func (m *ItemTemplateMutation) ClearDefaultModelNumber() { + m.default_model_number = nil + m.clearedFields[itemtemplate.FieldDefaultModelNumber] = struct{}{} +} + +// DefaultModelNumberCleared returns if the "default_model_number" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultModelNumberCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultModelNumber] + return ok +} + +// ResetDefaultModelNumber resets all changes to the "default_model_number" field. +func (m *ItemTemplateMutation) ResetDefaultModelNumber() { + m.default_model_number = nil + delete(m.clearedFields, itemtemplate.FieldDefaultModelNumber) +} + +// SetDefaultLifetimeWarranty sets the "default_lifetime_warranty" field. +func (m *ItemTemplateMutation) SetDefaultLifetimeWarranty(b bool) { + m.default_lifetime_warranty = &b +} + +// DefaultLifetimeWarranty returns the value of the "default_lifetime_warranty" field in the mutation. +func (m *ItemTemplateMutation) DefaultLifetimeWarranty() (r bool, exists bool) { + v := m.default_lifetime_warranty + if v == nil { + return + } + return *v, true +} + +// OldDefaultLifetimeWarranty returns the old "default_lifetime_warranty" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultLifetimeWarranty(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultLifetimeWarranty is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultLifetimeWarranty requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultLifetimeWarranty: %w", err) + } + return oldValue.DefaultLifetimeWarranty, nil +} + +// ResetDefaultLifetimeWarranty resets all changes to the "default_lifetime_warranty" field. +func (m *ItemTemplateMutation) ResetDefaultLifetimeWarranty() { + m.default_lifetime_warranty = nil +} + +// SetDefaultWarrantyDetails sets the "default_warranty_details" field. +func (m *ItemTemplateMutation) SetDefaultWarrantyDetails(s string) { + m.default_warranty_details = &s +} + +// DefaultWarrantyDetails returns the value of the "default_warranty_details" field in the mutation. +func (m *ItemTemplateMutation) DefaultWarrantyDetails() (r string, exists bool) { + v := m.default_warranty_details + if v == nil { + return + } + return *v, true +} + +// OldDefaultWarrantyDetails returns the old "default_warranty_details" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultWarrantyDetails(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultWarrantyDetails is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultWarrantyDetails requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultWarrantyDetails: %w", err) + } + return oldValue.DefaultWarrantyDetails, nil +} + +// ClearDefaultWarrantyDetails clears the value of the "default_warranty_details" field. +func (m *ItemTemplateMutation) ClearDefaultWarrantyDetails() { + m.default_warranty_details = nil + m.clearedFields[itemtemplate.FieldDefaultWarrantyDetails] = struct{}{} +} + +// DefaultWarrantyDetailsCleared returns if the "default_warranty_details" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultWarrantyDetailsCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultWarrantyDetails] + return ok +} + +// ResetDefaultWarrantyDetails resets all changes to the "default_warranty_details" field. +func (m *ItemTemplateMutation) ResetDefaultWarrantyDetails() { + m.default_warranty_details = nil + delete(m.clearedFields, itemtemplate.FieldDefaultWarrantyDetails) +} + +// SetIncludeWarrantyFields sets the "include_warranty_fields" field. +func (m *ItemTemplateMutation) SetIncludeWarrantyFields(b bool) { + m.include_warranty_fields = &b +} + +// IncludeWarrantyFields returns the value of the "include_warranty_fields" field in the mutation. +func (m *ItemTemplateMutation) IncludeWarrantyFields() (r bool, exists bool) { + v := m.include_warranty_fields + if v == nil { + return + } + return *v, true +} + +// OldIncludeWarrantyFields returns the old "include_warranty_fields" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldIncludeWarrantyFields(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIncludeWarrantyFields is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIncludeWarrantyFields requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIncludeWarrantyFields: %w", err) + } + return oldValue.IncludeWarrantyFields, nil +} + +// ResetIncludeWarrantyFields resets all changes to the "include_warranty_fields" field. +func (m *ItemTemplateMutation) ResetIncludeWarrantyFields() { + m.include_warranty_fields = nil +} + +// SetIncludePurchaseFields sets the "include_purchase_fields" field. +func (m *ItemTemplateMutation) SetIncludePurchaseFields(b bool) { + m.include_purchase_fields = &b +} + +// IncludePurchaseFields returns the value of the "include_purchase_fields" field in the mutation. +func (m *ItemTemplateMutation) IncludePurchaseFields() (r bool, exists bool) { + v := m.include_purchase_fields + if v == nil { + return + } + return *v, true +} + +// OldIncludePurchaseFields returns the old "include_purchase_fields" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldIncludePurchaseFields(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIncludePurchaseFields is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIncludePurchaseFields requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIncludePurchaseFields: %w", err) + } + return oldValue.IncludePurchaseFields, nil +} + +// ResetIncludePurchaseFields resets all changes to the "include_purchase_fields" field. +func (m *ItemTemplateMutation) ResetIncludePurchaseFields() { + m.include_purchase_fields = nil +} + +// SetIncludeSoldFields sets the "include_sold_fields" field. +func (m *ItemTemplateMutation) SetIncludeSoldFields(b bool) { + m.include_sold_fields = &b +} + +// IncludeSoldFields returns the value of the "include_sold_fields" field in the mutation. +func (m *ItemTemplateMutation) IncludeSoldFields() (r bool, exists bool) { + v := m.include_sold_fields + if v == nil { + return + } + return *v, true +} + +// OldIncludeSoldFields returns the old "include_sold_fields" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldIncludeSoldFields(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIncludeSoldFields is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIncludeSoldFields requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIncludeSoldFields: %w", err) + } + return oldValue.IncludeSoldFields, nil +} + +// ResetIncludeSoldFields resets all changes to the "include_sold_fields" field. +func (m *ItemTemplateMutation) ResetIncludeSoldFields() { + m.include_sold_fields = nil +} + +// SetDefaultLabelIds sets the "default_label_ids" field. +func (m *ItemTemplateMutation) SetDefaultLabelIds(u []uuid.UUID) { + m.default_label_ids = &u + m.appenddefault_label_ids = nil +} + +// DefaultLabelIds returns the value of the "default_label_ids" field in the mutation. +func (m *ItemTemplateMutation) DefaultLabelIds() (r []uuid.UUID, exists bool) { + v := m.default_label_ids + if v == nil { + return + } + return *v, true +} + +// OldDefaultLabelIds returns the old "default_label_ids" field's value of the ItemTemplate entity. +// If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemTemplateMutation) OldDefaultLabelIds(ctx context.Context) (v []uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDefaultLabelIds is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDefaultLabelIds requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDefaultLabelIds: %w", err) + } + return oldValue.DefaultLabelIds, nil +} + +// AppendDefaultLabelIds adds u to the "default_label_ids" field. +func (m *ItemTemplateMutation) AppendDefaultLabelIds(u []uuid.UUID) { + m.appenddefault_label_ids = append(m.appenddefault_label_ids, u...) +} + +// AppendedDefaultLabelIds returns the list of values that were appended to the "default_label_ids" field in this mutation. +func (m *ItemTemplateMutation) AppendedDefaultLabelIds() ([]uuid.UUID, bool) { + if len(m.appenddefault_label_ids) == 0 { + return nil, false + } + return m.appenddefault_label_ids, true +} + +// ClearDefaultLabelIds clears the value of the "default_label_ids" field. +func (m *ItemTemplateMutation) ClearDefaultLabelIds() { + m.default_label_ids = nil + m.appenddefault_label_ids = nil + m.clearedFields[itemtemplate.FieldDefaultLabelIds] = struct{}{} +} + +// DefaultLabelIdsCleared returns if the "default_label_ids" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultLabelIdsCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultLabelIds] + return ok +} + +// ResetDefaultLabelIds resets all changes to the "default_label_ids" field. +func (m *ItemTemplateMutation) ResetDefaultLabelIds() { + m.default_label_ids = nil + m.appenddefault_label_ids = nil + delete(m.clearedFields, itemtemplate.FieldDefaultLabelIds) +} + +// SetGroupID sets the "group" edge to the Group entity by id. +func (m *ItemTemplateMutation) SetGroupID(id uuid.UUID) { + m.group = &id +} + +// ClearGroup clears the "group" edge to the Group entity. +func (m *ItemTemplateMutation) ClearGroup() { + m.clearedgroup = true +} + +// GroupCleared reports if the "group" edge to the Group entity was cleared. +func (m *ItemTemplateMutation) GroupCleared() bool { + return m.clearedgroup +} + +// GroupID returns the "group" edge ID in the mutation. +func (m *ItemTemplateMutation) GroupID() (id uuid.UUID, exists bool) { + if m.group != nil { + return *m.group, true + } + return +} + +// GroupIDs returns the "group" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// GroupID instead. It exists only for internal usage by the builders. +func (m *ItemTemplateMutation) GroupIDs() (ids []uuid.UUID) { + if id := m.group; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetGroup resets all changes to the "group" edge. +func (m *ItemTemplateMutation) ResetGroup() { + m.group = nil + m.clearedgroup = false +} + +// AddFieldIDs adds the "fields" edge to the TemplateField entity by ids. +func (m *ItemTemplateMutation) AddFieldIDs(ids ...uuid.UUID) { + if m.fields == nil { + m.fields = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.fields[ids[i]] = struct{}{} + } +} + +// ClearFields clears the "fields" edge to the TemplateField entity. +func (m *ItemTemplateMutation) ClearFields() { + m.clearedfields = true +} + +// FieldsCleared reports if the "fields" edge to the TemplateField entity was cleared. +func (m *ItemTemplateMutation) FieldsCleared() bool { + return m.clearedfields +} + +// RemoveFieldIDs removes the "fields" edge to the TemplateField entity by IDs. +func (m *ItemTemplateMutation) RemoveFieldIDs(ids ...uuid.UUID) { + if m.removedfields == nil { + m.removedfields = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.fields, ids[i]) + m.removedfields[ids[i]] = struct{}{} + } +} + +// RemovedFields returns the removed IDs of the "fields" edge to the TemplateField entity. +func (m *ItemTemplateMutation) RemovedFieldsIDs() (ids []uuid.UUID) { + for id := range m.removedfields { + ids = append(ids, id) + } + return +} + +// FieldsIDs returns the "fields" edge IDs in the mutation. +func (m *ItemTemplateMutation) FieldsIDs() (ids []uuid.UUID) { + for id := range m.fields { + ids = append(ids, id) + } + return +} + +// ResetFields resets all changes to the "fields" edge. +func (m *ItemTemplateMutation) ResetFields() { + m.fields = nil + m.clearedfields = false + m.removedfields = nil +} + +// SetLocationID sets the "location" edge to the Location entity by id. +func (m *ItemTemplateMutation) SetLocationID(id uuid.UUID) { + m.location = &id +} + +// ClearLocation clears the "location" edge to the Location entity. +func (m *ItemTemplateMutation) ClearLocation() { + m.clearedlocation = true +} + +// LocationCleared reports if the "location" edge to the Location entity was cleared. +func (m *ItemTemplateMutation) LocationCleared() bool { + return m.clearedlocation +} + +// LocationID returns the "location" edge ID in the mutation. +func (m *ItemTemplateMutation) LocationID() (id uuid.UUID, exists bool) { + if m.location != nil { + return *m.location, true + } + return +} + +// LocationIDs returns the "location" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// LocationID instead. It exists only for internal usage by the builders. +func (m *ItemTemplateMutation) LocationIDs() (ids []uuid.UUID) { + if id := m.location; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetLocation resets all changes to the "location" edge. +func (m *ItemTemplateMutation) ResetLocation() { + m.location = nil + m.clearedlocation = false +} + +// Where appends a list predicates to the ItemTemplateMutation builder. +func (m *ItemTemplateMutation) Where(ps ...predicate.ItemTemplate) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ItemTemplateMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ItemTemplateMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ItemTemplate, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ItemTemplateMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ItemTemplateMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ItemTemplate). +func (m *ItemTemplateMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *ItemTemplateMutation) Fields() []string { + fields := make([]string, 0, 17) + if m.created_at != nil { + fields = append(fields, itemtemplate.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, itemtemplate.FieldUpdatedAt) + } + if m.name != nil { + fields = append(fields, itemtemplate.FieldName) + } + if m.description != nil { + fields = append(fields, itemtemplate.FieldDescription) + } + if m.notes != nil { + fields = append(fields, itemtemplate.FieldNotes) + } + if m.default_quantity != nil { + fields = append(fields, itemtemplate.FieldDefaultQuantity) + } + if m.default_insured != nil { + fields = append(fields, itemtemplate.FieldDefaultInsured) + } + if m.default_name != nil { + fields = append(fields, itemtemplate.FieldDefaultName) + } + if m.default_description != nil { + fields = append(fields, itemtemplate.FieldDefaultDescription) + } + if m.default_manufacturer != nil { + fields = append(fields, itemtemplate.FieldDefaultManufacturer) + } + if m.default_model_number != nil { + fields = append(fields, itemtemplate.FieldDefaultModelNumber) + } + if m.default_lifetime_warranty != nil { + fields = append(fields, itemtemplate.FieldDefaultLifetimeWarranty) + } + if m.default_warranty_details != nil { + fields = append(fields, itemtemplate.FieldDefaultWarrantyDetails) + } + if m.include_warranty_fields != nil { + fields = append(fields, itemtemplate.FieldIncludeWarrantyFields) + } + if m.include_purchase_fields != nil { + fields = append(fields, itemtemplate.FieldIncludePurchaseFields) + } + if m.include_sold_fields != nil { + fields = append(fields, itemtemplate.FieldIncludeSoldFields) + } + if m.default_label_ids != nil { + fields = append(fields, itemtemplate.FieldDefaultLabelIds) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *ItemTemplateMutation) Field(name string) (ent.Value, bool) { + switch name { + case itemtemplate.FieldCreatedAt: + return m.CreatedAt() + case itemtemplate.FieldUpdatedAt: + return m.UpdatedAt() + case itemtemplate.FieldName: + return m.Name() + case itemtemplate.FieldDescription: + return m.Description() + case itemtemplate.FieldNotes: + return m.Notes() + case itemtemplate.FieldDefaultQuantity: + return m.DefaultQuantity() + case itemtemplate.FieldDefaultInsured: + return m.DefaultInsured() + case itemtemplate.FieldDefaultName: + return m.DefaultName() + case itemtemplate.FieldDefaultDescription: + return m.DefaultDescription() + case itemtemplate.FieldDefaultManufacturer: + return m.DefaultManufacturer() + case itemtemplate.FieldDefaultModelNumber: + return m.DefaultModelNumber() + case itemtemplate.FieldDefaultLifetimeWarranty: + return m.DefaultLifetimeWarranty() + case itemtemplate.FieldDefaultWarrantyDetails: + return m.DefaultWarrantyDetails() + case itemtemplate.FieldIncludeWarrantyFields: + return m.IncludeWarrantyFields() + case itemtemplate.FieldIncludePurchaseFields: + return m.IncludePurchaseFields() + case itemtemplate.FieldIncludeSoldFields: + return m.IncludeSoldFields() + case itemtemplate.FieldDefaultLabelIds: + return m.DefaultLabelIds() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ItemTemplateMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case itemtemplate.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case itemtemplate.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case itemtemplate.FieldName: + return m.OldName(ctx) + case itemtemplate.FieldDescription: + return m.OldDescription(ctx) + case itemtemplate.FieldNotes: + return m.OldNotes(ctx) + case itemtemplate.FieldDefaultQuantity: + return m.OldDefaultQuantity(ctx) + case itemtemplate.FieldDefaultInsured: + return m.OldDefaultInsured(ctx) + case itemtemplate.FieldDefaultName: + return m.OldDefaultName(ctx) + case itemtemplate.FieldDefaultDescription: + return m.OldDefaultDescription(ctx) + case itemtemplate.FieldDefaultManufacturer: + return m.OldDefaultManufacturer(ctx) + case itemtemplate.FieldDefaultModelNumber: + return m.OldDefaultModelNumber(ctx) + case itemtemplate.FieldDefaultLifetimeWarranty: + return m.OldDefaultLifetimeWarranty(ctx) + case itemtemplate.FieldDefaultWarrantyDetails: + return m.OldDefaultWarrantyDetails(ctx) + case itemtemplate.FieldIncludeWarrantyFields: + return m.OldIncludeWarrantyFields(ctx) + case itemtemplate.FieldIncludePurchaseFields: + return m.OldIncludePurchaseFields(ctx) + case itemtemplate.FieldIncludeSoldFields: + return m.OldIncludeSoldFields(ctx) + case itemtemplate.FieldDefaultLabelIds: + return m.OldDefaultLabelIds(ctx) + } + return nil, fmt.Errorf("unknown ItemTemplate field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ItemTemplateMutation) SetField(name string, value ent.Value) error { + switch name { + case itemtemplate.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case itemtemplate.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case itemtemplate.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case itemtemplate.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case itemtemplate.FieldNotes: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNotes(v) + return nil + case itemtemplate.FieldDefaultQuantity: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultQuantity(v) + return nil + case itemtemplate.FieldDefaultInsured: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultInsured(v) + return nil + case itemtemplate.FieldDefaultName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultName(v) + return nil + case itemtemplate.FieldDefaultDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultDescription(v) + return nil + case itemtemplate.FieldDefaultManufacturer: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultManufacturer(v) + return nil + case itemtemplate.FieldDefaultModelNumber: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultModelNumber(v) + return nil + case itemtemplate.FieldDefaultLifetimeWarranty: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultLifetimeWarranty(v) + return nil + case itemtemplate.FieldDefaultWarrantyDetails: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultWarrantyDetails(v) + return nil + case itemtemplate.FieldIncludeWarrantyFields: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIncludeWarrantyFields(v) + return nil + case itemtemplate.FieldIncludePurchaseFields: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIncludePurchaseFields(v) + return nil + case itemtemplate.FieldIncludeSoldFields: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIncludeSoldFields(v) + return nil + case itemtemplate.FieldDefaultLabelIds: + v, ok := value.([]uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDefaultLabelIds(v) + return nil + } + return fmt.Errorf("unknown ItemTemplate field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ItemTemplateMutation) AddedFields() []string { + var fields []string + if m.adddefault_quantity != nil { + fields = append(fields, itemtemplate.FieldDefaultQuantity) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *ItemTemplateMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case itemtemplate.FieldDefaultQuantity: + return m.AddedDefaultQuantity() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ItemTemplateMutation) AddField(name string, value ent.Value) error { + switch name { + case itemtemplate.FieldDefaultQuantity: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddDefaultQuantity(v) + return nil + } + return fmt.Errorf("unknown ItemTemplate numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ItemTemplateMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(itemtemplate.FieldDescription) { + fields = append(fields, itemtemplate.FieldDescription) + } + if m.FieldCleared(itemtemplate.FieldNotes) { + fields = append(fields, itemtemplate.FieldNotes) + } + if m.FieldCleared(itemtemplate.FieldDefaultName) { + fields = append(fields, itemtemplate.FieldDefaultName) + } + if m.FieldCleared(itemtemplate.FieldDefaultDescription) { + fields = append(fields, itemtemplate.FieldDefaultDescription) + } + if m.FieldCleared(itemtemplate.FieldDefaultManufacturer) { + fields = append(fields, itemtemplate.FieldDefaultManufacturer) + } + if m.FieldCleared(itemtemplate.FieldDefaultModelNumber) { + fields = append(fields, itemtemplate.FieldDefaultModelNumber) + } + if m.FieldCleared(itemtemplate.FieldDefaultWarrantyDetails) { + fields = append(fields, itemtemplate.FieldDefaultWarrantyDetails) + } + if m.FieldCleared(itemtemplate.FieldDefaultLabelIds) { + fields = append(fields, itemtemplate.FieldDefaultLabelIds) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ItemTemplateMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *ItemTemplateMutation) ClearField(name string) error { + switch name { + case itemtemplate.FieldDescription: + m.ClearDescription() + return nil + case itemtemplate.FieldNotes: + m.ClearNotes() + return nil + case itemtemplate.FieldDefaultName: + m.ClearDefaultName() + return nil + case itemtemplate.FieldDefaultDescription: + m.ClearDefaultDescription() + return nil + case itemtemplate.FieldDefaultManufacturer: + m.ClearDefaultManufacturer() + return nil + case itemtemplate.FieldDefaultModelNumber: + m.ClearDefaultModelNumber() + return nil + case itemtemplate.FieldDefaultWarrantyDetails: + m.ClearDefaultWarrantyDetails() + return nil + case itemtemplate.FieldDefaultLabelIds: + m.ClearDefaultLabelIds() + return nil + } + return fmt.Errorf("unknown ItemTemplate nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *ItemTemplateMutation) ResetField(name string) error { + switch name { + case itemtemplate.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case itemtemplate.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case itemtemplate.FieldName: + m.ResetName() + return nil + case itemtemplate.FieldDescription: + m.ResetDescription() + return nil + case itemtemplate.FieldNotes: + m.ResetNotes() + return nil + case itemtemplate.FieldDefaultQuantity: + m.ResetDefaultQuantity() + return nil + case itemtemplate.FieldDefaultInsured: + m.ResetDefaultInsured() + return nil + case itemtemplate.FieldDefaultName: + m.ResetDefaultName() + return nil + case itemtemplate.FieldDefaultDescription: + m.ResetDefaultDescription() + return nil + case itemtemplate.FieldDefaultManufacturer: + m.ResetDefaultManufacturer() + return nil + case itemtemplate.FieldDefaultModelNumber: + m.ResetDefaultModelNumber() + return nil + case itemtemplate.FieldDefaultLifetimeWarranty: + m.ResetDefaultLifetimeWarranty() + return nil + case itemtemplate.FieldDefaultWarrantyDetails: + m.ResetDefaultWarrantyDetails() + return nil + case itemtemplate.FieldIncludeWarrantyFields: + m.ResetIncludeWarrantyFields() + return nil + case itemtemplate.FieldIncludePurchaseFields: + m.ResetIncludePurchaseFields() + return nil + case itemtemplate.FieldIncludeSoldFields: + m.ResetIncludeSoldFields() + return nil + case itemtemplate.FieldDefaultLabelIds: + m.ResetDefaultLabelIds() + return nil + } + return fmt.Errorf("unknown ItemTemplate field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ItemTemplateMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.group != nil { + edges = append(edges, itemtemplate.EdgeGroup) + } + if m.fields != nil { + edges = append(edges, itemtemplate.EdgeFields) + } + if m.location != nil { + edges = append(edges, itemtemplate.EdgeLocation) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ItemTemplateMutation) AddedIDs(name string) []ent.Value { + switch name { + case itemtemplate.EdgeGroup: + if id := m.group; id != nil { + return []ent.Value{*id} + } + case itemtemplate.EdgeFields: + ids := make([]ent.Value, 0, len(m.fields)) + for id := range m.fields { + ids = append(ids, id) + } + return ids + case itemtemplate.EdgeLocation: + if id := m.location; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ItemTemplateMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) + if m.removedfields != nil { + edges = append(edges, itemtemplate.EdgeFields) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ItemTemplateMutation) RemovedIDs(name string) []ent.Value { + switch name { + case itemtemplate.EdgeFields: + ids := make([]ent.Value, 0, len(m.removedfields)) + for id := range m.removedfields { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ItemTemplateMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedgroup { + edges = append(edges, itemtemplate.EdgeGroup) + } + if m.clearedfields { + edges = append(edges, itemtemplate.EdgeFields) + } + if m.clearedlocation { + edges = append(edges, itemtemplate.EdgeLocation) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ItemTemplateMutation) EdgeCleared(name string) bool { + switch name { + case itemtemplate.EdgeGroup: + return m.clearedgroup + case itemtemplate.EdgeFields: + return m.clearedfields + case itemtemplate.EdgeLocation: + return m.clearedlocation + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *ItemTemplateMutation) ClearEdge(name string) error { + switch name { + case itemtemplate.EdgeGroup: + m.ClearGroup() + return nil + case itemtemplate.EdgeLocation: + m.ClearLocation() + return nil + } + return fmt.Errorf("unknown ItemTemplate unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *ItemTemplateMutation) ResetEdge(name string) error { + switch name { + case itemtemplate.EdgeGroup: + m.ResetGroup() + return nil + case itemtemplate.EdgeFields: + m.ResetFields() + return nil + case itemtemplate.EdgeLocation: + m.ResetLocation() + return nil + } + return fmt.Errorf("unknown ItemTemplate edge %s", name) +} + // LabelMutation represents an operation that mutates the Label nodes in the graph. type LabelMutation struct { config @@ -10154,6 +11856,716 @@ func (m *NotifierMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Notifier edge %s", name) } +// TemplateFieldMutation represents an operation that mutates the TemplateField nodes in the graph. +type TemplateFieldMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + name *string + description *string + _type *templatefield.Type + text_value *string + clearedFields map[string]struct{} + item_template *uuid.UUID + cleareditem_template bool + done bool + oldValue func(context.Context) (*TemplateField, error) + predicates []predicate.TemplateField +} + +var _ ent.Mutation = (*TemplateFieldMutation)(nil) + +// templatefieldOption allows management of the mutation configuration using functional options. +type templatefieldOption func(*TemplateFieldMutation) + +// newTemplateFieldMutation creates new mutation for the TemplateField entity. +func newTemplateFieldMutation(c config, op Op, opts ...templatefieldOption) *TemplateFieldMutation { + m := &TemplateFieldMutation{ + config: c, + op: op, + typ: TypeTemplateField, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withTemplateFieldID sets the ID field of the mutation. +func withTemplateFieldID(id uuid.UUID) templatefieldOption { + return func(m *TemplateFieldMutation) { + var ( + err error + once sync.Once + value *TemplateField + ) + m.oldValue = func(ctx context.Context) (*TemplateField, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().TemplateField.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withTemplateField sets the old TemplateField of the mutation. +func withTemplateField(node *TemplateField) templatefieldOption { + return func(m *TemplateFieldMutation) { + m.oldValue = func(context.Context) (*TemplateField, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m TemplateFieldMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m TemplateFieldMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of TemplateField entities. +func (m *TemplateFieldMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *TemplateFieldMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *TemplateFieldMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().TemplateField.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *TemplateFieldMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *TemplateFieldMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *TemplateFieldMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *TemplateFieldMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *TemplateFieldMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *TemplateFieldMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetName sets the "name" field. +func (m *TemplateFieldMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TemplateFieldMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *TemplateFieldMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *TemplateFieldMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *TemplateFieldMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *TemplateFieldMutation) ClearDescription() { + m.description = nil + m.clearedFields[templatefield.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *TemplateFieldMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[templatefield.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *TemplateFieldMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, templatefield.FieldDescription) +} + +// SetType sets the "type" field. +func (m *TemplateFieldMutation) SetType(t templatefield.Type) { + m._type = &t +} + +// GetType returns the value of the "type" field in the mutation. +func (m *TemplateFieldMutation) GetType() (r templatefield.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldType(ctx context.Context) (v templatefield.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *TemplateFieldMutation) ResetType() { + m._type = nil +} + +// SetTextValue sets the "text_value" field. +func (m *TemplateFieldMutation) SetTextValue(s string) { + m.text_value = &s +} + +// TextValue returns the value of the "text_value" field in the mutation. +func (m *TemplateFieldMutation) TextValue() (r string, exists bool) { + v := m.text_value + if v == nil { + return + } + return *v, true +} + +// OldTextValue returns the old "text_value" field's value of the TemplateField entity. +// If the TemplateField object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TemplateFieldMutation) OldTextValue(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTextValue is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTextValue requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTextValue: %w", err) + } + return oldValue.TextValue, nil +} + +// ClearTextValue clears the value of the "text_value" field. +func (m *TemplateFieldMutation) ClearTextValue() { + m.text_value = nil + m.clearedFields[templatefield.FieldTextValue] = struct{}{} +} + +// TextValueCleared returns if the "text_value" field was cleared in this mutation. +func (m *TemplateFieldMutation) TextValueCleared() bool { + _, ok := m.clearedFields[templatefield.FieldTextValue] + return ok +} + +// ResetTextValue resets all changes to the "text_value" field. +func (m *TemplateFieldMutation) ResetTextValue() { + m.text_value = nil + delete(m.clearedFields, templatefield.FieldTextValue) +} + +// SetItemTemplateID sets the "item_template" edge to the ItemTemplate entity by id. +func (m *TemplateFieldMutation) SetItemTemplateID(id uuid.UUID) { + m.item_template = &id +} + +// ClearItemTemplate clears the "item_template" edge to the ItemTemplate entity. +func (m *TemplateFieldMutation) ClearItemTemplate() { + m.cleareditem_template = true +} + +// ItemTemplateCleared reports if the "item_template" edge to the ItemTemplate entity was cleared. +func (m *TemplateFieldMutation) ItemTemplateCleared() bool { + return m.cleareditem_template +} + +// ItemTemplateID returns the "item_template" edge ID in the mutation. +func (m *TemplateFieldMutation) ItemTemplateID() (id uuid.UUID, exists bool) { + if m.item_template != nil { + return *m.item_template, true + } + return +} + +// ItemTemplateIDs returns the "item_template" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ItemTemplateID instead. It exists only for internal usage by the builders. +func (m *TemplateFieldMutation) ItemTemplateIDs() (ids []uuid.UUID) { + if id := m.item_template; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetItemTemplate resets all changes to the "item_template" edge. +func (m *TemplateFieldMutation) ResetItemTemplate() { + m.item_template = nil + m.cleareditem_template = false +} + +// Where appends a list predicates to the TemplateFieldMutation builder. +func (m *TemplateFieldMutation) Where(ps ...predicate.TemplateField) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the TemplateFieldMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TemplateFieldMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.TemplateField, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *TemplateFieldMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *TemplateFieldMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (TemplateField). +func (m *TemplateFieldMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *TemplateFieldMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.created_at != nil { + fields = append(fields, templatefield.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, templatefield.FieldUpdatedAt) + } + if m.name != nil { + fields = append(fields, templatefield.FieldName) + } + if m.description != nil { + fields = append(fields, templatefield.FieldDescription) + } + if m._type != nil { + fields = append(fields, templatefield.FieldType) + } + if m.text_value != nil { + fields = append(fields, templatefield.FieldTextValue) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *TemplateFieldMutation) Field(name string) (ent.Value, bool) { + switch name { + case templatefield.FieldCreatedAt: + return m.CreatedAt() + case templatefield.FieldUpdatedAt: + return m.UpdatedAt() + case templatefield.FieldName: + return m.Name() + case templatefield.FieldDescription: + return m.Description() + case templatefield.FieldType: + return m.GetType() + case templatefield.FieldTextValue: + return m.TextValue() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *TemplateFieldMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case templatefield.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case templatefield.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case templatefield.FieldName: + return m.OldName(ctx) + case templatefield.FieldDescription: + return m.OldDescription(ctx) + case templatefield.FieldType: + return m.OldType(ctx) + case templatefield.FieldTextValue: + return m.OldTextValue(ctx) + } + return nil, fmt.Errorf("unknown TemplateField field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TemplateFieldMutation) SetField(name string, value ent.Value) error { + switch name { + case templatefield.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case templatefield.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case templatefield.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case templatefield.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case templatefield.FieldType: + v, ok := value.(templatefield.Type) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetType(v) + return nil + case templatefield.FieldTextValue: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTextValue(v) + return nil + } + return fmt.Errorf("unknown TemplateField field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *TemplateFieldMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *TemplateFieldMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TemplateFieldMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown TemplateField numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *TemplateFieldMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(templatefield.FieldDescription) { + fields = append(fields, templatefield.FieldDescription) + } + if m.FieldCleared(templatefield.FieldTextValue) { + fields = append(fields, templatefield.FieldTextValue) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *TemplateFieldMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *TemplateFieldMutation) ClearField(name string) error { + switch name { + case templatefield.FieldDescription: + m.ClearDescription() + return nil + case templatefield.FieldTextValue: + m.ClearTextValue() + return nil + } + return fmt.Errorf("unknown TemplateField nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *TemplateFieldMutation) ResetField(name string) error { + switch name { + case templatefield.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case templatefield.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case templatefield.FieldName: + m.ResetName() + return nil + case templatefield.FieldDescription: + m.ResetDescription() + return nil + case templatefield.FieldType: + m.ResetType() + return nil + case templatefield.FieldTextValue: + m.ResetTextValue() + return nil + } + return fmt.Errorf("unknown TemplateField field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *TemplateFieldMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.item_template != nil { + edges = append(edges, templatefield.EdgeItemTemplate) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *TemplateFieldMutation) AddedIDs(name string) []ent.Value { + switch name { + case templatefield.EdgeItemTemplate: + if id := m.item_template; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *TemplateFieldMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *TemplateFieldMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *TemplateFieldMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.cleareditem_template { + edges = append(edges, templatefield.EdgeItemTemplate) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *TemplateFieldMutation) EdgeCleared(name string) bool { + switch name { + case templatefield.EdgeItemTemplate: + return m.cleareditem_template + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *TemplateFieldMutation) ClearEdge(name string) error { + switch name { + case templatefield.EdgeItemTemplate: + m.ClearItemTemplate() + return nil + } + return fmt.Errorf("unknown TemplateField unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *TemplateFieldMutation) ResetEdge(name string) error { + switch name { + case templatefield.EdgeItemTemplate: + m.ResetItemTemplate() + return nil + } + return fmt.Errorf("unknown TemplateField edge %s", name) +} + // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config diff --git a/backend/internal/data/ent/predicate/predicate.go b/backend/internal/data/ent/predicate/predicate.go index 26e42325..0d9d47f5 100644 --- a/backend/internal/data/ent/predicate/predicate.go +++ b/backend/internal/data/ent/predicate/predicate.go @@ -27,6 +27,9 @@ type Item func(*sql.Selector) // ItemField is the predicate function for itemfield builders. type ItemField func(*sql.Selector) +// ItemTemplate is the predicate function for itemtemplate builders. +type ItemTemplate func(*sql.Selector) + // Label is the predicate function for label builders. type Label func(*sql.Selector) @@ -39,5 +42,8 @@ type MaintenanceEntry func(*sql.Selector) // Notifier is the predicate function for notifier builders. type Notifier func(*sql.Selector) +// TemplateField is the predicate function for templatefield builders. +type TemplateField func(*sql.Selector) + // User is the predicate function for user builders. type User func(*sql.Selector) diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.go index 2ac6b536..0476c5c6 100644 --- a/backend/internal/data/ent/runtime.go +++ b/backend/internal/data/ent/runtime.go @@ -12,11 +12,13 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -310,6 +312,97 @@ func init() { itemfieldDescID := itemfieldMixinFields0[0].Descriptor() // itemfield.DefaultID holds the default value on creation for the id field. itemfield.DefaultID = itemfieldDescID.Default.(func() uuid.UUID) + itemtemplateMixin := schema.ItemTemplate{}.Mixin() + itemtemplateMixinFields0 := itemtemplateMixin[0].Fields() + _ = itemtemplateMixinFields0 + itemtemplateMixinFields1 := itemtemplateMixin[1].Fields() + _ = itemtemplateMixinFields1 + itemtemplateFields := schema.ItemTemplate{}.Fields() + _ = itemtemplateFields + // itemtemplateDescCreatedAt is the schema descriptor for created_at field. + itemtemplateDescCreatedAt := itemtemplateMixinFields0[1].Descriptor() + // itemtemplate.DefaultCreatedAt holds the default value on creation for the created_at field. + itemtemplate.DefaultCreatedAt = itemtemplateDescCreatedAt.Default.(func() time.Time) + // itemtemplateDescUpdatedAt is the schema descriptor for updated_at field. + itemtemplateDescUpdatedAt := itemtemplateMixinFields0[2].Descriptor() + // itemtemplate.DefaultUpdatedAt holds the default value on creation for the updated_at field. + itemtemplate.DefaultUpdatedAt = itemtemplateDescUpdatedAt.Default.(func() time.Time) + // itemtemplate.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + itemtemplate.UpdateDefaultUpdatedAt = itemtemplateDescUpdatedAt.UpdateDefault.(func() time.Time) + // itemtemplateDescName is the schema descriptor for name field. + itemtemplateDescName := itemtemplateMixinFields1[0].Descriptor() + // itemtemplate.NameValidator is a validator for the "name" field. It is called by the builders before save. + itemtemplate.NameValidator = func() func(string) error { + validators := itemtemplateDescName.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(name string) error { + for _, fn := range fns { + if err := fn(name); err != nil { + return err + } + } + return nil + } + }() + // itemtemplateDescDescription is the schema descriptor for description field. + itemtemplateDescDescription := itemtemplateMixinFields1[1].Descriptor() + // itemtemplate.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + itemtemplate.DescriptionValidator = itemtemplateDescDescription.Validators[0].(func(string) error) + // itemtemplateDescNotes is the schema descriptor for notes field. + itemtemplateDescNotes := itemtemplateFields[0].Descriptor() + // itemtemplate.NotesValidator is a validator for the "notes" field. It is called by the builders before save. + itemtemplate.NotesValidator = itemtemplateDescNotes.Validators[0].(func(string) error) + // itemtemplateDescDefaultQuantity is the schema descriptor for default_quantity field. + itemtemplateDescDefaultQuantity := itemtemplateFields[1].Descriptor() + // itemtemplate.DefaultDefaultQuantity holds the default value on creation for the default_quantity field. + itemtemplate.DefaultDefaultQuantity = itemtemplateDescDefaultQuantity.Default.(int) + // itemtemplateDescDefaultInsured is the schema descriptor for default_insured field. + itemtemplateDescDefaultInsured := itemtemplateFields[2].Descriptor() + // itemtemplate.DefaultDefaultInsured holds the default value on creation for the default_insured field. + itemtemplate.DefaultDefaultInsured = itemtemplateDescDefaultInsured.Default.(bool) + // itemtemplateDescDefaultName is the schema descriptor for default_name field. + itemtemplateDescDefaultName := itemtemplateFields[3].Descriptor() + // itemtemplate.DefaultNameValidator is a validator for the "default_name" field. It is called by the builders before save. + itemtemplate.DefaultNameValidator = itemtemplateDescDefaultName.Validators[0].(func(string) error) + // itemtemplateDescDefaultDescription is the schema descriptor for default_description field. + itemtemplateDescDefaultDescription := itemtemplateFields[4].Descriptor() + // itemtemplate.DefaultDescriptionValidator is a validator for the "default_description" field. It is called by the builders before save. + itemtemplate.DefaultDescriptionValidator = itemtemplateDescDefaultDescription.Validators[0].(func(string) error) + // itemtemplateDescDefaultManufacturer is the schema descriptor for default_manufacturer field. + itemtemplateDescDefaultManufacturer := itemtemplateFields[5].Descriptor() + // itemtemplate.DefaultManufacturerValidator is a validator for the "default_manufacturer" field. It is called by the builders before save. + itemtemplate.DefaultManufacturerValidator = itemtemplateDescDefaultManufacturer.Validators[0].(func(string) error) + // itemtemplateDescDefaultModelNumber is the schema descriptor for default_model_number field. + itemtemplateDescDefaultModelNumber := itemtemplateFields[6].Descriptor() + // itemtemplate.DefaultModelNumberValidator is a validator for the "default_model_number" field. It is called by the builders before save. + itemtemplate.DefaultModelNumberValidator = itemtemplateDescDefaultModelNumber.Validators[0].(func(string) error) + // itemtemplateDescDefaultLifetimeWarranty is the schema descriptor for default_lifetime_warranty field. + itemtemplateDescDefaultLifetimeWarranty := itemtemplateFields[7].Descriptor() + // itemtemplate.DefaultDefaultLifetimeWarranty holds the default value on creation for the default_lifetime_warranty field. + itemtemplate.DefaultDefaultLifetimeWarranty = itemtemplateDescDefaultLifetimeWarranty.Default.(bool) + // itemtemplateDescDefaultWarrantyDetails is the schema descriptor for default_warranty_details field. + itemtemplateDescDefaultWarrantyDetails := itemtemplateFields[8].Descriptor() + // itemtemplate.DefaultWarrantyDetailsValidator is a validator for the "default_warranty_details" field. It is called by the builders before save. + itemtemplate.DefaultWarrantyDetailsValidator = itemtemplateDescDefaultWarrantyDetails.Validators[0].(func(string) error) + // itemtemplateDescIncludeWarrantyFields is the schema descriptor for include_warranty_fields field. + itemtemplateDescIncludeWarrantyFields := itemtemplateFields[9].Descriptor() + // itemtemplate.DefaultIncludeWarrantyFields holds the default value on creation for the include_warranty_fields field. + itemtemplate.DefaultIncludeWarrantyFields = itemtemplateDescIncludeWarrantyFields.Default.(bool) + // itemtemplateDescIncludePurchaseFields is the schema descriptor for include_purchase_fields field. + itemtemplateDescIncludePurchaseFields := itemtemplateFields[10].Descriptor() + // itemtemplate.DefaultIncludePurchaseFields holds the default value on creation for the include_purchase_fields field. + itemtemplate.DefaultIncludePurchaseFields = itemtemplateDescIncludePurchaseFields.Default.(bool) + // itemtemplateDescIncludeSoldFields is the schema descriptor for include_sold_fields field. + itemtemplateDescIncludeSoldFields := itemtemplateFields[11].Descriptor() + // itemtemplate.DefaultIncludeSoldFields holds the default value on creation for the include_sold_fields field. + itemtemplate.DefaultIncludeSoldFields = itemtemplateDescIncludeSoldFields.Default.(bool) + // itemtemplateDescID is the schema descriptor for id field. + itemtemplateDescID := itemtemplateMixinFields0[0].Descriptor() + // itemtemplate.DefaultID holds the default value on creation for the id field. + itemtemplate.DefaultID = itemtemplateDescID.Default.(func() uuid.UUID) labelMixin := schema.Label{}.Mixin() labelMixinFields0 := labelMixin[0].Fields() _ = labelMixinFields0 @@ -504,6 +597,53 @@ func init() { notifierDescID := notifierMixinFields0[0].Descriptor() // notifier.DefaultID holds the default value on creation for the id field. notifier.DefaultID = notifierDescID.Default.(func() uuid.UUID) + templatefieldMixin := schema.TemplateField{}.Mixin() + templatefieldMixinFields0 := templatefieldMixin[0].Fields() + _ = templatefieldMixinFields0 + templatefieldMixinFields1 := templatefieldMixin[1].Fields() + _ = templatefieldMixinFields1 + templatefieldFields := schema.TemplateField{}.Fields() + _ = templatefieldFields + // templatefieldDescCreatedAt is the schema descriptor for created_at field. + templatefieldDescCreatedAt := templatefieldMixinFields0[1].Descriptor() + // templatefield.DefaultCreatedAt holds the default value on creation for the created_at field. + templatefield.DefaultCreatedAt = templatefieldDescCreatedAt.Default.(func() time.Time) + // templatefieldDescUpdatedAt is the schema descriptor for updated_at field. + templatefieldDescUpdatedAt := templatefieldMixinFields0[2].Descriptor() + // templatefield.DefaultUpdatedAt holds the default value on creation for the updated_at field. + templatefield.DefaultUpdatedAt = templatefieldDescUpdatedAt.Default.(func() time.Time) + // templatefield.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + templatefield.UpdateDefaultUpdatedAt = templatefieldDescUpdatedAt.UpdateDefault.(func() time.Time) + // templatefieldDescName is the schema descriptor for name field. + templatefieldDescName := templatefieldMixinFields1[0].Descriptor() + // templatefield.NameValidator is a validator for the "name" field. It is called by the builders before save. + templatefield.NameValidator = func() func(string) error { + validators := templatefieldDescName.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(name string) error { + for _, fn := range fns { + if err := fn(name); err != nil { + return err + } + } + return nil + } + }() + // templatefieldDescDescription is the schema descriptor for description field. + templatefieldDescDescription := templatefieldMixinFields1[1].Descriptor() + // templatefield.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + templatefield.DescriptionValidator = templatefieldDescDescription.Validators[0].(func(string) error) + // templatefieldDescTextValue is the schema descriptor for text_value field. + templatefieldDescTextValue := templatefieldFields[1].Descriptor() + // templatefield.TextValueValidator is a validator for the "text_value" field. It is called by the builders before save. + templatefield.TextValueValidator = templatefieldDescTextValue.Validators[0].(func(string) error) + // templatefieldDescID is the schema descriptor for id field. + templatefieldDescID := templatefieldMixinFields0[0].Descriptor() + // templatefield.DefaultID holds the default value on creation for the id field. + templatefield.DefaultID = templatefieldDescID.Default.(func() uuid.UUID) userMixin := schema.User{}.Mixin() userMixinFields0 := userMixin[0].Fields() _ = userMixinFields0 diff --git a/backend/internal/data/ent/schema/group.go b/backend/internal/data/ent/schema/group.go index bb93bf15..4deac1ae 100644 --- a/backend/internal/data/ent/schema/group.go +++ b/backend/internal/data/ent/schema/group.go @@ -48,6 +48,7 @@ func (Group) Edges() []ent.Edge { owned("labels", Label.Type), owned("invitation_tokens", GroupInvitationToken.Type), owned("notifiers", Notifier.Type), + owned("item_templates", ItemTemplate.Type), // $scaffold_edge } } diff --git a/backend/internal/data/ent/schema/item_template.go b/backend/internal/data/ent/schema/item_template.go new file mode 100644 index 00000000..bb86170a --- /dev/null +++ b/backend/internal/data/ent/schema/item_template.go @@ -0,0 +1,111 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema/mixins" +) + +// ItemTemplate holds the schema definition for the ItemTemplate entity. +type ItemTemplate struct { + ent.Schema +} + +func (ItemTemplate) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixins.BaseMixin{}, + mixins.DetailsMixin{}, + GroupMixin{ref: "item_templates"}, + } +} + +func (ItemTemplate) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("name"), + } +} + +// Fields of the ItemTemplate. +func (ItemTemplate) Fields() []ent.Field { + return []ent.Field{ + // Notes for the template (instructions, hints, etc.) + field.String("notes"). + MaxLen(1000). + Optional(), + + // ------------------------------------ + // Default values for item fields + field.Int("default_quantity"). + Default(1), + field.Bool("default_insured"). + Default(false), + + // ------------------------------------ + // Default item name/description (templates for item identity) + field.String("default_name"). + MaxLen(255). + Optional(). + Comment("Default name template for items (can use placeholders)"), + field.Text("default_description"). + MaxLen(1000). + Optional(). + Comment("Default description for items created from this template"), + + // ------------------------------------ + // Default item identification + field.String("default_manufacturer"). + MaxLen(255). + Optional(), + field.String("default_model_number"). + MaxLen(255). + Optional(). + Comment("Default model number for items created from this template"), + + // ------------------------------------ + // Default warranty settings + field.Bool("default_lifetime_warranty"). + Default(false), + field.Text("default_warranty_details"). + MaxLen(1000). + Optional(), + + // ------------------------------------ + // Template metadata + field.Bool("include_warranty_fields"). + Default(false). + Comment("Whether to include warranty fields in items created from this template"), + field.Bool("include_purchase_fields"). + Default(false). + Comment("Whether to include purchase fields in items created from this template"), + field.Bool("include_sold_fields"). + Default(false). + Comment("Whether to include sold fields in items created from this template"), + + // ------------------------------------ + // Default labels (stored as JSON array of UUIDs to allow reuse across templates) + field.JSON("default_label_ids", []uuid.UUID{}). + Optional(). + Comment("Default label IDs for items created from this template"), + } +} + +// Edges of the ItemTemplate. +func (ItemTemplate) Edges() []ent.Edge { + owned := func(s string, t any) ent.Edge { + return edge.To(s, t). + Annotations(entsql.Annotation{ + OnDelete: entsql.Cascade, + }) + } + + return []ent.Edge{ + owned("fields", TemplateField.Type), + // Default location for items created from this template + edge.To("location", Location.Type). + Unique(), + } +} diff --git a/backend/internal/data/ent/schema/template_field.go b/backend/internal/data/ent/schema/template_field.go new file mode 100644 index 00000000..8c82d43b --- /dev/null +++ b/backend/internal/data/ent/schema/template_field.go @@ -0,0 +1,41 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema/mixins" +) + +// TemplateField holds the schema definition for the TemplateField entity. +// Template fields define custom fields that will be added to items created from a template. +type TemplateField struct { + ent.Schema +} + +func (TemplateField) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixins.BaseMixin{}, + mixins.DetailsMixin{}, + } +} + +// Fields of the TemplateField. +func (TemplateField) Fields() []ent.Field { + return []ent.Field{ + field.Enum("type"). + Values("text"), + field.String("text_value"). + MaxLen(500). + Optional(), + } +} + +// Edges of the TemplateField. +func (TemplateField) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("item_template", ItemTemplate.Type). + Ref("fields"). + Unique(), + } +} diff --git a/backend/internal/data/ent/templatefield.go b/backend/internal/data/ent/templatefield.go new file mode 100644 index 00000000..3ba3a489 --- /dev/null +++ b/backend/internal/data/ent/templatefield.go @@ -0,0 +1,201 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// TemplateField is the model entity for the TemplateField schema. +type TemplateField struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Description holds the value of the "description" field. + Description string `json:"description,omitempty"` + // Type holds the value of the "type" field. + Type templatefield.Type `json:"type,omitempty"` + // TextValue holds the value of the "text_value" field. + TextValue string `json:"text_value,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the TemplateFieldQuery when eager-loading is set. + Edges TemplateFieldEdges `json:"edges"` + item_template_fields *uuid.UUID + selectValues sql.SelectValues +} + +// TemplateFieldEdges holds the relations/edges for other nodes in the graph. +type TemplateFieldEdges struct { + // ItemTemplate holds the value of the item_template edge. + ItemTemplate *ItemTemplate `json:"item_template,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// ItemTemplateOrErr returns the ItemTemplate value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TemplateFieldEdges) ItemTemplateOrErr() (*ItemTemplate, error) { + if e.ItemTemplate != nil { + return e.ItemTemplate, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: itemtemplate.Label} + } + return nil, &NotLoadedError{edge: "item_template"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*TemplateField) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case templatefield.FieldName, templatefield.FieldDescription, templatefield.FieldType, templatefield.FieldTextValue: + values[i] = new(sql.NullString) + case templatefield.FieldCreatedAt, templatefield.FieldUpdatedAt: + values[i] = new(sql.NullTime) + case templatefield.FieldID: + values[i] = new(uuid.UUID) + case templatefield.ForeignKeys[0]: // item_template_fields + values[i] = &sql.NullScanner{S: new(uuid.UUID)} + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the TemplateField fields. +func (_m *TemplateField) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case templatefield.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case templatefield.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case templatefield.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + case templatefield.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case templatefield.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = value.String + } + case templatefield.FieldType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type", values[i]) + } else if value.Valid { + _m.Type = templatefield.Type(value.String) + } + case templatefield.FieldTextValue: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field text_value", values[i]) + } else if value.Valid { + _m.TextValue = value.String + } + case templatefield.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field item_template_fields", values[i]) + } else if value.Valid { + _m.item_template_fields = new(uuid.UUID) + *_m.item_template_fields = *value.S.(*uuid.UUID) + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the TemplateField. +// This includes values selected through modifiers, order, etc. +func (_m *TemplateField) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryItemTemplate queries the "item_template" edge of the TemplateField entity. +func (_m *TemplateField) QueryItemTemplate() *ItemTemplateQuery { + return NewTemplateFieldClient(_m.config).QueryItemTemplate(_m) +} + +// Update returns a builder for updating this TemplateField. +// Note that you need to call TemplateField.Unwrap() before calling this method if this TemplateField +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *TemplateField) Update() *TemplateFieldUpdateOne { + return NewTemplateFieldClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the TemplateField entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *TemplateField) Unwrap() *TemplateField { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: TemplateField is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *TemplateField) String() string { + var builder strings.Builder + builder.WriteString("TemplateField(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("description=") + builder.WriteString(_m.Description) + builder.WriteString(", ") + builder.WriteString("type=") + builder.WriteString(fmt.Sprintf("%v", _m.Type)) + builder.WriteString(", ") + builder.WriteString("text_value=") + builder.WriteString(_m.TextValue) + builder.WriteByte(')') + return builder.String() +} + +// TemplateFields is a parsable slice of TemplateField. +type TemplateFields []*TemplateField diff --git a/backend/internal/data/ent/templatefield/templatefield.go b/backend/internal/data/ent/templatefield/templatefield.go new file mode 100644 index 00000000..6dbde586 --- /dev/null +++ b/backend/internal/data/ent/templatefield/templatefield.go @@ -0,0 +1,165 @@ +// Code generated by ent, DO NOT EDIT. + +package templatefield + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the templatefield type in the database. + Label = "template_field" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldType holds the string denoting the type field in the database. + FieldType = "type" + // FieldTextValue holds the string denoting the text_value field in the database. + FieldTextValue = "text_value" + // EdgeItemTemplate holds the string denoting the item_template edge name in mutations. + EdgeItemTemplate = "item_template" + // Table holds the table name of the templatefield in the database. + Table = "template_fields" + // ItemTemplateTable is the table that holds the item_template relation/edge. + ItemTemplateTable = "template_fields" + // ItemTemplateInverseTable is the table name for the ItemTemplate entity. + // It exists in this package in order to avoid circular dependency with the "itemtemplate" package. + ItemTemplateInverseTable = "item_templates" + // ItemTemplateColumn is the table column denoting the item_template relation/edge. + ItemTemplateColumn = "item_template_fields" +) + +// Columns holds all SQL columns for templatefield fields. +var Columns = []string{ + FieldID, + FieldCreatedAt, + FieldUpdatedAt, + FieldName, + FieldDescription, + FieldType, + FieldTextValue, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "template_fields" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "item_template_fields", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} + +var ( + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + DescriptionValidator func(string) error + // TextValueValidator is a validator for the "text_value" field. It is called by the builders before save. + TextValueValidator func(string) error + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Type defines the type for the "type" enum field. +type Type string + +// Type values. +const ( + TypeText Type = "text" +) + +func (_type Type) String() string { + return string(_type) +} + +// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. +func TypeValidator(_type Type) error { + switch _type { + case TypeText: + return nil + default: + return fmt.Errorf("templatefield: invalid enum value for type field: %q", _type) + } +} + +// OrderOption defines the ordering options for the TemplateField queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByType orders the results by the type field. +func ByType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldType, opts...).ToFunc() +} + +// ByTextValue orders the results by the text_value field. +func ByTextValue(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTextValue, opts...).ToFunc() +} + +// ByItemTemplateField orders the results by item_template field. +func ByItemTemplateField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newItemTemplateStep(), sql.OrderByField(field, opts...)) + } +} +func newItemTemplateStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ItemTemplateInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ItemTemplateTable, ItemTemplateColumn), + ) +} diff --git a/backend/internal/data/ent/templatefield/where.go b/backend/internal/data/ent/templatefield/where.go new file mode 100644 index 00000000..98021a2a --- /dev/null +++ b/backend/internal/data/ent/templatefield/where.go @@ -0,0 +1,435 @@ +// Code generated by ent, DO NOT EDIT. + +package templatefield + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldName, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldDescription, v)) +} + +// TextValue applies equality check predicate on the "text_value" field. It's identical to TextValueEQ. +func TextValue(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldTextValue, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContainsFold(FieldName, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.TemplateField { + return predicate.TemplateField(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContainsFold(FieldDescription, v)) +} + +// TypeEQ applies the EQ predicate on the "type" field. +func TypeEQ(v Type) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldType, v)) +} + +// TypeNEQ applies the NEQ predicate on the "type" field. +func TypeNEQ(v Type) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldType, v)) +} + +// TypeIn applies the In predicate on the "type" field. +func TypeIn(vs ...Type) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldType, vs...)) +} + +// TypeNotIn applies the NotIn predicate on the "type" field. +func TypeNotIn(vs ...Type) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldType, vs...)) +} + +// TextValueEQ applies the EQ predicate on the "text_value" field. +func TextValueEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEQ(FieldTextValue, v)) +} + +// TextValueNEQ applies the NEQ predicate on the "text_value" field. +func TextValueNEQ(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNEQ(FieldTextValue, v)) +} + +// TextValueIn applies the In predicate on the "text_value" field. +func TextValueIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldIn(FieldTextValue, vs...)) +} + +// TextValueNotIn applies the NotIn predicate on the "text_value" field. +func TextValueNotIn(vs ...string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotIn(FieldTextValue, vs...)) +} + +// TextValueGT applies the GT predicate on the "text_value" field. +func TextValueGT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGT(FieldTextValue, v)) +} + +// TextValueGTE applies the GTE predicate on the "text_value" field. +func TextValueGTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldGTE(FieldTextValue, v)) +} + +// TextValueLT applies the LT predicate on the "text_value" field. +func TextValueLT(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLT(FieldTextValue, v)) +} + +// TextValueLTE applies the LTE predicate on the "text_value" field. +func TextValueLTE(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldLTE(FieldTextValue, v)) +} + +// TextValueContains applies the Contains predicate on the "text_value" field. +func TextValueContains(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContains(FieldTextValue, v)) +} + +// TextValueHasPrefix applies the HasPrefix predicate on the "text_value" field. +func TextValueHasPrefix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasPrefix(FieldTextValue, v)) +} + +// TextValueHasSuffix applies the HasSuffix predicate on the "text_value" field. +func TextValueHasSuffix(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldHasSuffix(FieldTextValue, v)) +} + +// TextValueIsNil applies the IsNil predicate on the "text_value" field. +func TextValueIsNil() predicate.TemplateField { + return predicate.TemplateField(sql.FieldIsNull(FieldTextValue)) +} + +// TextValueNotNil applies the NotNil predicate on the "text_value" field. +func TextValueNotNil() predicate.TemplateField { + return predicate.TemplateField(sql.FieldNotNull(FieldTextValue)) +} + +// TextValueEqualFold applies the EqualFold predicate on the "text_value" field. +func TextValueEqualFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldEqualFold(FieldTextValue, v)) +} + +// TextValueContainsFold applies the ContainsFold predicate on the "text_value" field. +func TextValueContainsFold(v string) predicate.TemplateField { + return predicate.TemplateField(sql.FieldContainsFold(FieldTextValue, v)) +} + +// HasItemTemplate applies the HasEdge predicate on the "item_template" edge. +func HasItemTemplate() predicate.TemplateField { + return predicate.TemplateField(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ItemTemplateTable, ItemTemplateColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasItemTemplateWith applies the HasEdge predicate on the "item_template" edge with a given conditions (other predicates). +func HasItemTemplateWith(preds ...predicate.ItemTemplate) predicate.TemplateField { + return predicate.TemplateField(func(s *sql.Selector) { + step := newItemTemplateStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.TemplateField) predicate.TemplateField { + return predicate.TemplateField(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.TemplateField) predicate.TemplateField { + return predicate.TemplateField(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.TemplateField) predicate.TemplateField { + return predicate.TemplateField(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/templatefield_create.go b/backend/internal/data/ent/templatefield_create.go new file mode 100644 index 00000000..fa42ba87 --- /dev/null +++ b/backend/internal/data/ent/templatefield_create.go @@ -0,0 +1,370 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// TemplateFieldCreate is the builder for creating a TemplateField entity. +type TemplateFieldCreate struct { + config + mutation *TemplateFieldMutation + hooks []Hook +} + +// SetCreatedAt sets the "created_at" field. +func (_c *TemplateFieldCreate) SetCreatedAt(v time.Time) *TemplateFieldCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableCreatedAt(v *time.Time) *TemplateFieldCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *TemplateFieldCreate) SetUpdatedAt(v time.Time) *TemplateFieldCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableUpdatedAt(v *time.Time) *TemplateFieldCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetName sets the "name" field. +func (_c *TemplateFieldCreate) SetName(v string) *TemplateFieldCreate { + _c.mutation.SetName(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *TemplateFieldCreate) SetDescription(v string) *TemplateFieldCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableDescription(v *string) *TemplateFieldCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetType sets the "type" field. +func (_c *TemplateFieldCreate) SetType(v templatefield.Type) *TemplateFieldCreate { + _c.mutation.SetType(v) + return _c +} + +// SetTextValue sets the "text_value" field. +func (_c *TemplateFieldCreate) SetTextValue(v string) *TemplateFieldCreate { + _c.mutation.SetTextValue(v) + return _c +} + +// SetNillableTextValue sets the "text_value" field if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableTextValue(v *string) *TemplateFieldCreate { + if v != nil { + _c.SetTextValue(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *TemplateFieldCreate) SetID(v uuid.UUID) *TemplateFieldCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableID(v *uuid.UUID) *TemplateFieldCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID. +func (_c *TemplateFieldCreate) SetItemTemplateID(id uuid.UUID) *TemplateFieldCreate { + _c.mutation.SetItemTemplateID(id) + return _c +} + +// SetNillableItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID if the given value is not nil. +func (_c *TemplateFieldCreate) SetNillableItemTemplateID(id *uuid.UUID) *TemplateFieldCreate { + if id != nil { + _c = _c.SetItemTemplateID(*id) + } + return _c +} + +// SetItemTemplate sets the "item_template" edge to the ItemTemplate entity. +func (_c *TemplateFieldCreate) SetItemTemplate(v *ItemTemplate) *TemplateFieldCreate { + return _c.SetItemTemplateID(v.ID) +} + +// Mutation returns the TemplateFieldMutation object of the builder. +func (_c *TemplateFieldCreate) Mutation() *TemplateFieldMutation { + return _c.mutation +} + +// Save creates the TemplateField in the database. +func (_c *TemplateFieldCreate) Save(ctx context.Context) (*TemplateField, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *TemplateFieldCreate) SaveX(ctx context.Context) *TemplateField { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TemplateFieldCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TemplateFieldCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *TemplateFieldCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := templatefield.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := templatefield.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := templatefield.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *TemplateFieldCreate) check() error { + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "TemplateField.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "TemplateField.updated_at"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "TemplateField.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := templatefield.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TemplateField.name": %w`, err)} + } + } + if v, ok := _c.mutation.Description(); ok { + if err := templatefield.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "TemplateField.description": %w`, err)} + } + } + if _, ok := _c.mutation.GetType(); !ok { + return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "TemplateField.type"`)} + } + if v, ok := _c.mutation.GetType(); ok { + if err := templatefield.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "TemplateField.type": %w`, err)} + } + } + if v, ok := _c.mutation.TextValue(); ok { + if err := templatefield.TextValueValidator(v); err != nil { + return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "TemplateField.text_value": %w`, err)} + } + } + return nil +} + +func (_c *TemplateFieldCreate) sqlSave(ctx context.Context) (*TemplateField, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *TemplateFieldCreate) createSpec() (*TemplateField, *sqlgraph.CreateSpec) { + var ( + _node = &TemplateField{config: _c.config} + _spec = sqlgraph.NewCreateSpec(templatefield.Table, sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(templatefield.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(templatefield.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(templatefield.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(templatefield.FieldDescription, field.TypeString, value) + _node.Description = value + } + if value, ok := _c.mutation.GetType(); ok { + _spec.SetField(templatefield.FieldType, field.TypeEnum, value) + _node.Type = value + } + if value, ok := _c.mutation.TextValue(); ok { + _spec.SetField(templatefield.FieldTextValue, field.TypeString, value) + _node.TextValue = value + } + if nodes := _c.mutation.ItemTemplateIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: templatefield.ItemTemplateTable, + Columns: []string{templatefield.ItemTemplateColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.item_template_fields = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// TemplateFieldCreateBulk is the builder for creating many TemplateField entities in bulk. +type TemplateFieldCreateBulk struct { + config + err error + builders []*TemplateFieldCreate +} + +// Save creates the TemplateField entities in the database. +func (_c *TemplateFieldCreateBulk) Save(ctx context.Context) ([]*TemplateField, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*TemplateField, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*TemplateFieldMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *TemplateFieldCreateBulk) SaveX(ctx context.Context) []*TemplateField { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *TemplateFieldCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *TemplateFieldCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/templatefield_delete.go b/backend/internal/data/ent/templatefield_delete.go new file mode 100644 index 00000000..4e2df011 --- /dev/null +++ b/backend/internal/data/ent/templatefield_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// TemplateFieldDelete is the builder for deleting a TemplateField entity. +type TemplateFieldDelete struct { + config + hooks []Hook + mutation *TemplateFieldMutation +} + +// Where appends a list predicates to the TemplateFieldDelete builder. +func (_d *TemplateFieldDelete) Where(ps ...predicate.TemplateField) *TemplateFieldDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *TemplateFieldDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TemplateFieldDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *TemplateFieldDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(templatefield.Table, sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// TemplateFieldDeleteOne is the builder for deleting a single TemplateField entity. +type TemplateFieldDeleteOne struct { + _d *TemplateFieldDelete +} + +// Where appends a list predicates to the TemplateFieldDelete builder. +func (_d *TemplateFieldDeleteOne) Where(ps ...predicate.TemplateField) *TemplateFieldDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *TemplateFieldDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{templatefield.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *TemplateFieldDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/internal/data/ent/templatefield_query.go b/backend/internal/data/ent/templatefield_query.go new file mode 100644 index 00000000..7cf4aa2a --- /dev/null +++ b/backend/internal/data/ent/templatefield_query.go @@ -0,0 +1,615 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// TemplateFieldQuery is the builder for querying TemplateField entities. +type TemplateFieldQuery struct { + config + ctx *QueryContext + order []templatefield.OrderOption + inters []Interceptor + predicates []predicate.TemplateField + withItemTemplate *ItemTemplateQuery + withFKs bool + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the TemplateFieldQuery builder. +func (_q *TemplateFieldQuery) Where(ps ...predicate.TemplateField) *TemplateFieldQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *TemplateFieldQuery) Limit(limit int) *TemplateFieldQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *TemplateFieldQuery) Offset(offset int) *TemplateFieldQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *TemplateFieldQuery) Unique(unique bool) *TemplateFieldQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *TemplateFieldQuery) Order(o ...templatefield.OrderOption) *TemplateFieldQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryItemTemplate chains the current query on the "item_template" edge. +func (_q *TemplateFieldQuery) QueryItemTemplate() *ItemTemplateQuery { + query := (&ItemTemplateClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(templatefield.Table, templatefield.FieldID, selector), + sqlgraph.To(itemtemplate.Table, itemtemplate.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, templatefield.ItemTemplateTable, templatefield.ItemTemplateColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first TemplateField entity from the query. +// Returns a *NotFoundError when no TemplateField was found. +func (_q *TemplateFieldQuery) First(ctx context.Context) (*TemplateField, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{templatefield.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *TemplateFieldQuery) FirstX(ctx context.Context) *TemplateField { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first TemplateField ID from the query. +// Returns a *NotFoundError when no TemplateField ID was found. +func (_q *TemplateFieldQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{templatefield.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *TemplateFieldQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single TemplateField entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one TemplateField entity is found. +// Returns a *NotFoundError when no TemplateField entities are found. +func (_q *TemplateFieldQuery) Only(ctx context.Context) (*TemplateField, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{templatefield.Label} + default: + return nil, &NotSingularError{templatefield.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *TemplateFieldQuery) OnlyX(ctx context.Context) *TemplateField { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only TemplateField ID in the query. +// Returns a *NotSingularError when more than one TemplateField ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *TemplateFieldQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{templatefield.Label} + default: + err = &NotSingularError{templatefield.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *TemplateFieldQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of TemplateFields. +func (_q *TemplateFieldQuery) All(ctx context.Context) ([]*TemplateField, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*TemplateField, *TemplateFieldQuery]() + return withInterceptors[[]*TemplateField](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *TemplateFieldQuery) AllX(ctx context.Context) []*TemplateField { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of TemplateField IDs. +func (_q *TemplateFieldQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(templatefield.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *TemplateFieldQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *TemplateFieldQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*TemplateFieldQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *TemplateFieldQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *TemplateFieldQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *TemplateFieldQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the TemplateFieldQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *TemplateFieldQuery) Clone() *TemplateFieldQuery { + if _q == nil { + return nil + } + return &TemplateFieldQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]templatefield.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.TemplateField{}, _q.predicates...), + withItemTemplate: _q.withItemTemplate.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithItemTemplate tells the query-builder to eager-load the nodes that are connected to +// the "item_template" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TemplateFieldQuery) WithItemTemplate(opts ...func(*ItemTemplateQuery)) *TemplateFieldQuery { + query := (&ItemTemplateClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withItemTemplate = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.TemplateField.Query(). +// GroupBy(templatefield.FieldCreatedAt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *TemplateFieldQuery) GroupBy(field string, fields ...string) *TemplateFieldGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &TemplateFieldGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = templatefield.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// CreatedAt time.Time `json:"created_at,omitempty"` +// } +// +// client.TemplateField.Query(). +// Select(templatefield.FieldCreatedAt). +// Scan(ctx, &v) +func (_q *TemplateFieldQuery) Select(fields ...string) *TemplateFieldSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &TemplateFieldSelect{TemplateFieldQuery: _q} + sbuild.label = templatefield.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a TemplateFieldSelect configured with the given aggregations. +func (_q *TemplateFieldQuery) Aggregate(fns ...AggregateFunc) *TemplateFieldSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *TemplateFieldQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !templatefield.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *TemplateFieldQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TemplateField, error) { + var ( + nodes = []*TemplateField{} + withFKs = _q.withFKs + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withItemTemplate != nil, + } + ) + if _q.withItemTemplate != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, templatefield.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*TemplateField).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &TemplateField{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withItemTemplate; query != nil { + if err := _q.loadItemTemplate(ctx, query, nodes, nil, + func(n *TemplateField, e *ItemTemplate) { n.Edges.ItemTemplate = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *TemplateFieldQuery) loadItemTemplate(ctx context.Context, query *ItemTemplateQuery, nodes []*TemplateField, init func(*TemplateField), assign func(*TemplateField, *ItemTemplate)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*TemplateField) + for i := range nodes { + if nodes[i].item_template_fields == nil { + continue + } + fk := *nodes[i].item_template_fields + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(itemtemplate.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "item_template_fields" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *TemplateFieldQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *TemplateFieldQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(templatefield.Table, templatefield.Columns, sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, templatefield.FieldID) + for i := range fields { + if fields[i] != templatefield.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *TemplateFieldQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(templatefield.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = templatefield.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// TemplateFieldGroupBy is the group-by builder for TemplateField entities. +type TemplateFieldGroupBy struct { + selector + build *TemplateFieldQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *TemplateFieldGroupBy) Aggregate(fns ...AggregateFunc) *TemplateFieldGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *TemplateFieldGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TemplateFieldQuery, *TemplateFieldGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *TemplateFieldGroupBy) sqlScan(ctx context.Context, root *TemplateFieldQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// TemplateFieldSelect is the builder for selecting fields of TemplateField entities. +type TemplateFieldSelect struct { + *TemplateFieldQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *TemplateFieldSelect) Aggregate(fns ...AggregateFunc) *TemplateFieldSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *TemplateFieldSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*TemplateFieldQuery, *TemplateFieldSelect](ctx, _s.TemplateFieldQuery, _s, _s.inters, v) +} + +func (_s *TemplateFieldSelect) sqlScan(ctx context.Context, root *TemplateFieldQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/backend/internal/data/ent/templatefield_update.go b/backend/internal/data/ent/templatefield_update.go new file mode 100644 index 00000000..521659c0 --- /dev/null +++ b/backend/internal/data/ent/templatefield_update.go @@ -0,0 +1,550 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +// TemplateFieldUpdate is the builder for updating TemplateField entities. +type TemplateFieldUpdate struct { + config + hooks []Hook + mutation *TemplateFieldMutation +} + +// Where appends a list predicates to the TemplateFieldUpdate builder. +func (_u *TemplateFieldUpdate) Where(ps ...predicate.TemplateField) *TemplateFieldUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *TemplateFieldUpdate) SetUpdatedAt(v time.Time) *TemplateFieldUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetName sets the "name" field. +func (_u *TemplateFieldUpdate) SetName(v string) *TemplateFieldUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *TemplateFieldUpdate) SetNillableName(v *string) *TemplateFieldUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *TemplateFieldUpdate) SetDescription(v string) *TemplateFieldUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *TemplateFieldUpdate) SetNillableDescription(v *string) *TemplateFieldUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *TemplateFieldUpdate) ClearDescription() *TemplateFieldUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetType sets the "type" field. +func (_u *TemplateFieldUpdate) SetType(v templatefield.Type) *TemplateFieldUpdate { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *TemplateFieldUpdate) SetNillableType(v *templatefield.Type) *TemplateFieldUpdate { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetTextValue sets the "text_value" field. +func (_u *TemplateFieldUpdate) SetTextValue(v string) *TemplateFieldUpdate { + _u.mutation.SetTextValue(v) + return _u +} + +// SetNillableTextValue sets the "text_value" field if the given value is not nil. +func (_u *TemplateFieldUpdate) SetNillableTextValue(v *string) *TemplateFieldUpdate { + if v != nil { + _u.SetTextValue(*v) + } + return _u +} + +// ClearTextValue clears the value of the "text_value" field. +func (_u *TemplateFieldUpdate) ClearTextValue() *TemplateFieldUpdate { + _u.mutation.ClearTextValue() + return _u +} + +// SetItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID. +func (_u *TemplateFieldUpdate) SetItemTemplateID(id uuid.UUID) *TemplateFieldUpdate { + _u.mutation.SetItemTemplateID(id) + return _u +} + +// SetNillableItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID if the given value is not nil. +func (_u *TemplateFieldUpdate) SetNillableItemTemplateID(id *uuid.UUID) *TemplateFieldUpdate { + if id != nil { + _u = _u.SetItemTemplateID(*id) + } + return _u +} + +// SetItemTemplate sets the "item_template" edge to the ItemTemplate entity. +func (_u *TemplateFieldUpdate) SetItemTemplate(v *ItemTemplate) *TemplateFieldUpdate { + return _u.SetItemTemplateID(v.ID) +} + +// Mutation returns the TemplateFieldMutation object of the builder. +func (_u *TemplateFieldUpdate) Mutation() *TemplateFieldMutation { + return _u.mutation +} + +// ClearItemTemplate clears the "item_template" edge to the ItemTemplate entity. +func (_u *TemplateFieldUpdate) ClearItemTemplate() *TemplateFieldUpdate { + _u.mutation.ClearItemTemplate() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *TemplateFieldUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TemplateFieldUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *TemplateFieldUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TemplateFieldUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *TemplateFieldUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := templatefield.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TemplateFieldUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := templatefield.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TemplateField.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := templatefield.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "TemplateField.description": %w`, err)} + } + } + if v, ok := _u.mutation.GetType(); ok { + if err := templatefield.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "TemplateField.type": %w`, err)} + } + } + if v, ok := _u.mutation.TextValue(); ok { + if err := templatefield.TextValueValidator(v); err != nil { + return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "TemplateField.text_value": %w`, err)} + } + } + return nil +} + +func (_u *TemplateFieldUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(templatefield.Table, templatefield.Columns, sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(templatefield.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(templatefield.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(templatefield.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(templatefield.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(templatefield.FieldType, field.TypeEnum, value) + } + if value, ok := _u.mutation.TextValue(); ok { + _spec.SetField(templatefield.FieldTextValue, field.TypeString, value) + } + if _u.mutation.TextValueCleared() { + _spec.ClearField(templatefield.FieldTextValue, field.TypeString) + } + if _u.mutation.ItemTemplateCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: templatefield.ItemTemplateTable, + Columns: []string{templatefield.ItemTemplateColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ItemTemplateIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: templatefield.ItemTemplateTable, + Columns: []string{templatefield.ItemTemplateColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{templatefield.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// TemplateFieldUpdateOne is the builder for updating a single TemplateField entity. +type TemplateFieldUpdateOne struct { + config + fields []string + hooks []Hook + mutation *TemplateFieldMutation +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *TemplateFieldUpdateOne) SetUpdatedAt(v time.Time) *TemplateFieldUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetName sets the "name" field. +func (_u *TemplateFieldUpdateOne) SetName(v string) *TemplateFieldUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *TemplateFieldUpdateOne) SetNillableName(v *string) *TemplateFieldUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *TemplateFieldUpdateOne) SetDescription(v string) *TemplateFieldUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *TemplateFieldUpdateOne) SetNillableDescription(v *string) *TemplateFieldUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *TemplateFieldUpdateOne) ClearDescription() *TemplateFieldUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetType sets the "type" field. +func (_u *TemplateFieldUpdateOne) SetType(v templatefield.Type) *TemplateFieldUpdateOne { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *TemplateFieldUpdateOne) SetNillableType(v *templatefield.Type) *TemplateFieldUpdateOne { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetTextValue sets the "text_value" field. +func (_u *TemplateFieldUpdateOne) SetTextValue(v string) *TemplateFieldUpdateOne { + _u.mutation.SetTextValue(v) + return _u +} + +// SetNillableTextValue sets the "text_value" field if the given value is not nil. +func (_u *TemplateFieldUpdateOne) SetNillableTextValue(v *string) *TemplateFieldUpdateOne { + if v != nil { + _u.SetTextValue(*v) + } + return _u +} + +// ClearTextValue clears the value of the "text_value" field. +func (_u *TemplateFieldUpdateOne) ClearTextValue() *TemplateFieldUpdateOne { + _u.mutation.ClearTextValue() + return _u +} + +// SetItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID. +func (_u *TemplateFieldUpdateOne) SetItemTemplateID(id uuid.UUID) *TemplateFieldUpdateOne { + _u.mutation.SetItemTemplateID(id) + return _u +} + +// SetNillableItemTemplateID sets the "item_template" edge to the ItemTemplate entity by ID if the given value is not nil. +func (_u *TemplateFieldUpdateOne) SetNillableItemTemplateID(id *uuid.UUID) *TemplateFieldUpdateOne { + if id != nil { + _u = _u.SetItemTemplateID(*id) + } + return _u +} + +// SetItemTemplate sets the "item_template" edge to the ItemTemplate entity. +func (_u *TemplateFieldUpdateOne) SetItemTemplate(v *ItemTemplate) *TemplateFieldUpdateOne { + return _u.SetItemTemplateID(v.ID) +} + +// Mutation returns the TemplateFieldMutation object of the builder. +func (_u *TemplateFieldUpdateOne) Mutation() *TemplateFieldMutation { + return _u.mutation +} + +// ClearItemTemplate clears the "item_template" edge to the ItemTemplate entity. +func (_u *TemplateFieldUpdateOne) ClearItemTemplate() *TemplateFieldUpdateOne { + _u.mutation.ClearItemTemplate() + return _u +} + +// Where appends a list predicates to the TemplateFieldUpdate builder. +func (_u *TemplateFieldUpdateOne) Where(ps ...predicate.TemplateField) *TemplateFieldUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *TemplateFieldUpdateOne) Select(field string, fields ...string) *TemplateFieldUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated TemplateField entity. +func (_u *TemplateFieldUpdateOne) Save(ctx context.Context) (*TemplateField, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *TemplateFieldUpdateOne) SaveX(ctx context.Context) *TemplateField { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *TemplateFieldUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *TemplateFieldUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *TemplateFieldUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := templatefield.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *TemplateFieldUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := templatefield.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "TemplateField.name": %w`, err)} + } + } + if v, ok := _u.mutation.Description(); ok { + if err := templatefield.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "TemplateField.description": %w`, err)} + } + } + if v, ok := _u.mutation.GetType(); ok { + if err := templatefield.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "TemplateField.type": %w`, err)} + } + } + if v, ok := _u.mutation.TextValue(); ok { + if err := templatefield.TextValueValidator(v); err != nil { + return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "TemplateField.text_value": %w`, err)} + } + } + return nil +} + +func (_u *TemplateFieldUpdateOne) sqlSave(ctx context.Context) (_node *TemplateField, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(templatefield.Table, templatefield.Columns, sqlgraph.NewFieldSpec(templatefield.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TemplateField.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, templatefield.FieldID) + for _, f := range fields { + if !templatefield.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != templatefield.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(templatefield.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(templatefield.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(templatefield.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(templatefield.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(templatefield.FieldType, field.TypeEnum, value) + } + if value, ok := _u.mutation.TextValue(); ok { + _spec.SetField(templatefield.FieldTextValue, field.TypeString, value) + } + if _u.mutation.TextValueCleared() { + _spec.ClearField(templatefield.FieldTextValue, field.TypeString) + } + if _u.mutation.ItemTemplateCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: templatefield.ItemTemplateTable, + Columns: []string{templatefield.ItemTemplateColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ItemTemplateIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: templatefield.ItemTemplateTable, + Columns: []string{templatefield.ItemTemplateColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(itemtemplate.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &TemplateField{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{templatefield.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/internal/data/ent/tx.go b/backend/internal/data/ent/tx.go index 0642f2b8..f8561a0b 100644 --- a/backend/internal/data/ent/tx.go +++ b/backend/internal/data/ent/tx.go @@ -26,6 +26,8 @@ type Tx struct { Item *ItemClient // ItemField is the client for interacting with the ItemField builders. ItemField *ItemFieldClient + // ItemTemplate is the client for interacting with the ItemTemplate builders. + ItemTemplate *ItemTemplateClient // Label is the client for interacting with the Label builders. Label *LabelClient // Location is the client for interacting with the Location builders. @@ -34,6 +36,8 @@ type Tx struct { MaintenanceEntry *MaintenanceEntryClient // Notifier is the client for interacting with the Notifier builders. Notifier *NotifierClient + // TemplateField is the client for interacting with the TemplateField builders. + TemplateField *TemplateFieldClient // User is the client for interacting with the User builders. User *UserClient @@ -174,10 +178,12 @@ func (tx *Tx) init() { tx.GroupInvitationToken = NewGroupInvitationTokenClient(tx.config) tx.Item = NewItemClient(tx.config) tx.ItemField = NewItemFieldClient(tx.config) + tx.ItemTemplate = NewItemTemplateClient(tx.config) tx.Label = NewLabelClient(tx.config) tx.Location = NewLocationClient(tx.config) tx.MaintenanceEntry = NewMaintenanceEntryClient(tx.config) tx.Notifier = NewNotifierClient(tx.config) + tx.TemplateField = NewTemplateFieldClient(tx.config) tx.User = NewUserClient(tx.config) } diff --git a/backend/internal/data/migrations/postgres/20251128120201_recreate_item_templates.sql b/backend/internal/data/migrations/postgres/20251128120201_recreate_item_templates.sql new file mode 100644 index 00000000..6dd35a5f --- /dev/null +++ b/backend/internal/data/migrations/postgres/20251128120201_recreate_item_templates.sql @@ -0,0 +1,29 @@ +-- +goose Up +-- Create "item_templates" table +CREATE TABLE IF NOT EXISTS "item_templates" ( + "id" uuid NOT NULL, + "created_at" timestamptz NOT NULL, + "updated_at" timestamptz NOT NULL, + "name" character varying NOT NULL, + "description" character varying NULL, + "notes" character varying NULL, + "default_quantity" bigint NOT NULL DEFAULT 1, + "default_insured" boolean NOT NULL DEFAULT false, + "default_name" character varying NULL, + "default_description" character varying NULL, + "default_manufacturer" character varying NULL, + "default_model_number" character varying NULL, + "default_lifetime_warranty" boolean NOT NULL DEFAULT false, + "default_warranty_details" character varying NULL, + "include_warranty_fields" boolean NOT NULL DEFAULT false, + "include_purchase_fields" boolean NOT NULL DEFAULT false, + "include_sold_fields" boolean NOT NULL DEFAULT false, + "default_label_ids" jsonb NULL, + "item_template_location" uuid NULL, + "group_item_templates" uuid NOT NULL, + PRIMARY KEY ("id"), + CONSTRAINT "item_templates_groups_item_templates" FOREIGN KEY ("group_item_templates") REFERENCES "groups" ("id") ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT "item_templates_locations_location" FOREIGN KEY ("item_template_location") REFERENCES "locations" ("id") ON UPDATE NO ACTION ON DELETE SET NULL +); +-- Create "template_fields" table +CREATE TABLE IF NOT EXISTS "template_fields" ("id" uuid NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "name" character varying NOT NULL, "description" character varying NULL, "type" character varying NOT NULL, "text_value" character varying NULL, "item_template_fields" uuid NULL, PRIMARY KEY ("id"), CONSTRAINT "template_fields_item_templates_fields" FOREIGN KEY ("item_template_fields") REFERENCES "item_templates" ("id") ON UPDATE NO ACTION ON DELETE CASCADE); diff --git a/backend/internal/data/migrations/sqlite3/20251128120200_recreate_item_templates.sql b/backend/internal/data/migrations/sqlite3/20251128120200_recreate_item_templates.sql new file mode 100644 index 00000000..6a7adf3c --- /dev/null +++ b/backend/internal/data/migrations/sqlite3/20251128120200_recreate_item_templates.sql @@ -0,0 +1,46 @@ +-- +goose Up +create table if not exists item_templates +( + id uuid not null + primary key, + created_at datetime not null, + updated_at datetime not null, + name text not null, + description text, + notes text, + default_quantity integer default 1 not null, + default_insured bool default false not null, + default_name text, + default_description text, + default_manufacturer text, + default_model_number text, + default_lifetime_warranty bool default false not null, + default_warranty_details text, + include_warranty_fields bool default false not null, + include_purchase_fields bool default false not null, + include_sold_fields bool default false not null, + default_label_ids json, + item_template_location uuid + references locations(id) + on delete set null, + group_item_templates uuid not null + constraint item_templates_groups_item_templates + references groups + on delete cascade +); + +create table if not exists template_fields +( + id uuid not null + primary key, + created_at datetime not null, + updated_at datetime not null, + name text not null, + description text, + type text not null, + text_value text, + item_template_fields uuid + constraint template_fields_item_templates_fields + references item_templates + on delete cascade +); diff --git a/backend/internal/data/repo/repo_item_templates.go b/backend/internal/data/repo/repo_item_templates.go new file mode 100644 index 00000000..532c6fe5 --- /dev/null +++ b/backend/internal/data/repo/repo_item_templates.go @@ -0,0 +1,451 @@ +package repo + +import ( + "context" + "time" + + "github.com/google/uuid" + "github.com/rs/zerolog/log" + "github.com/sysadminsmedia/homebox/backend/internal/core/services/reporting/eventbus" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" +) + +type ItemTemplatesRepository struct { + db *ent.Client + bus *eventbus.EventBus +} + +type ( + TemplateField struct { + ID *uuid.UUID `json:"id,omitempty"` + Type string `json:"type"` + Name string `json:"name"` + TextValue string `json:"textValue"` + } + + TemplateLabelSummary struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + } + + TemplateLocationSummary struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + } + + ItemTemplateCreate struct { + Name string `json:"name" validate:"required,min=1,max=255"` + Description string `json:"description" validate:"max=1000"` + Notes string `json:"notes" validate:"max=1000"` + + // Default values for items + DefaultQuantity *int `json:"defaultQuantity,omitempty" extensions:"x-nullable"` + DefaultInsured bool `json:"defaultInsured"` + DefaultName *string `json:"defaultName,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultDescription *string `json:"defaultDescription,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` + DefaultManufacturer *string `json:"defaultManufacturer,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultModelNumber *string `json:"defaultModelNumber,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` + DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` + + // Default location and labels + DefaultLocationID *uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"` + DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"` + + // Metadata flags + IncludeWarrantyFields bool `json:"includeWarrantyFields"` + IncludePurchaseFields bool `json:"includePurchaseFields"` + IncludeSoldFields bool `json:"includeSoldFields"` + + // Custom fields + Fields []TemplateField `json:"fields"` + } + + ItemTemplateUpdate struct { + ID uuid.UUID `json:"id"` + Name string `json:"name" validate:"required,min=1,max=255"` + Description string `json:"description" validate:"max=1000"` + Notes string `json:"notes" validate:"max=1000"` + + // Default values for items + DefaultQuantity *int `json:"defaultQuantity,omitempty" extensions:"x-nullable"` + DefaultInsured bool `json:"defaultInsured"` + DefaultName *string `json:"defaultName,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultDescription *string `json:"defaultDescription,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` + DefaultManufacturer *string `json:"defaultManufacturer,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultModelNumber *string `json:"defaultModelNumber,omitempty" extensions:"x-nullable" validate:"omitempty,max=255"` + DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` + DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` + + // Default location and labels + DefaultLocationID *uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"` + DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"` + + // Metadata flags + IncludeWarrantyFields bool `json:"includeWarrantyFields"` + IncludePurchaseFields bool `json:"includePurchaseFields"` + IncludeSoldFields bool `json:"includeSoldFields"` + + // Custom fields + Fields []TemplateField `json:"fields"` + } + + ItemTemplateSummary struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + } + + ItemTemplateOut struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Notes string `json:"notes"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + + // Default values for items + DefaultQuantity int `json:"defaultQuantity"` + DefaultInsured bool `json:"defaultInsured"` + DefaultName string `json:"defaultName"` + DefaultDescription string `json:"defaultDescription"` + DefaultManufacturer string `json:"defaultManufacturer"` + DefaultModelNumber string `json:"defaultModelNumber"` + DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` + DefaultWarrantyDetails string `json:"defaultWarrantyDetails"` + + // Default location and labels + DefaultLocation *TemplateLocationSummary `json:"defaultLocation"` + DefaultLabels []TemplateLabelSummary `json:"defaultLabels"` + + // Metadata flags + IncludeWarrantyFields bool `json:"includeWarrantyFields"` + IncludePurchaseFields bool `json:"includePurchaseFields"` + IncludeSoldFields bool `json:"includeSoldFields"` + + // Custom fields + Fields []TemplateField `json:"fields"` + } +) + +func mapTemplateField(field *ent.TemplateField) TemplateField { + id := field.ID + return TemplateField{ + ID: &id, + Type: string(field.Type), + Name: field.Name, + TextValue: field.TextValue, + } +} + +func mapTemplateFieldSlice(fields []*ent.TemplateField) []TemplateField { + result := make([]TemplateField, len(fields)) + for i, field := range fields { + result[i] = mapTemplateField(field) + } + return result +} + +func mapTemplateSummary(template *ent.ItemTemplate) ItemTemplateSummary { + return ItemTemplateSummary{ + ID: template.ID, + Name: template.Name, + Description: template.Description, + CreatedAt: template.CreatedAt, + UpdatedAt: template.UpdatedAt, + } +} + +func (r *ItemTemplatesRepository) mapTemplateOut(ctx context.Context, template *ent.ItemTemplate) ItemTemplateOut { + fields := make([]TemplateField, 0) + if template.Edges.Fields != nil { + fields = mapTemplateFieldSlice(template.Edges.Fields) + } + + // Map location if present + var location *TemplateLocationSummary + if template.Edges.Location != nil { + location = &TemplateLocationSummary{ + ID: template.Edges.Location.ID, + Name: template.Edges.Location.Name, + } + } + + // Fetch labels from database using stored IDs + labels := make([]TemplateLabelSummary, 0) + if len(template.DefaultLabelIds) > 0 { + labelEntities, err := r.db.Label.Query(). + Where(label.IDIn(template.DefaultLabelIds...)). + All(ctx) + if err == nil { + for _, l := range labelEntities { + labels = append(labels, TemplateLabelSummary{ + ID: l.ID, + Name: l.Name, + }) + } + } + } + + return ItemTemplateOut{ + ID: template.ID, + Name: template.Name, + Description: template.Description, + Notes: template.Notes, + CreatedAt: template.CreatedAt, + UpdatedAt: template.UpdatedAt, + DefaultQuantity: template.DefaultQuantity, + DefaultInsured: template.DefaultInsured, + DefaultName: template.DefaultName, + DefaultDescription: template.DefaultDescription, + DefaultManufacturer: template.DefaultManufacturer, + DefaultModelNumber: template.DefaultModelNumber, + DefaultLifetimeWarranty: template.DefaultLifetimeWarranty, + DefaultWarrantyDetails: template.DefaultWarrantyDetails, + DefaultLocation: location, + DefaultLabels: labels, + IncludeWarrantyFields: template.IncludeWarrantyFields, + IncludePurchaseFields: template.IncludePurchaseFields, + IncludeSoldFields: template.IncludeSoldFields, + Fields: fields, + } +} + +func (r *ItemTemplatesRepository) publishMutationEvent(gid uuid.UUID) { + if r.bus != nil { + r.bus.Publish(eventbus.EventItemMutation, eventbus.GroupMutationEvent{GID: gid}) + } +} + +// GetAll returns all templates for a group +func (r *ItemTemplatesRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemTemplateSummary, error) { + templates, err := r.db.ItemTemplate.Query(). + Where(itemtemplate.HasGroupWith(group.ID(gid))). + Order(ent.Asc(itemtemplate.FieldName)). + All(ctx) + + if err != nil { + return nil, err + } + + result := make([]ItemTemplateSummary, len(templates)) + for i, template := range templates { + result[i] = mapTemplateSummary(template) + } + + return result, nil +} + +// GetOne returns a single template by ID, verified to belong to the specified group +func (r *ItemTemplatesRepository) GetOne(ctx context.Context, gid uuid.UUID, id uuid.UUID) (ItemTemplateOut, error) { + template, err := r.db.ItemTemplate.Query(). + Where( + itemtemplate.ID(id), + itemtemplate.HasGroupWith(group.ID(gid)), + ). + WithFields(). + WithLocation(). + Only(ctx) + + if err != nil { + return ItemTemplateOut{}, err + } + + return r.mapTemplateOut(ctx, template), nil +} + +// Create creates a new template +func (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, data ItemTemplateCreate) (ItemTemplateOut, error) { + q := r.db.ItemTemplate.Create(). + SetName(data.Name). + SetDescription(data.Description). + SetNotes(data.Notes). + SetNillableDefaultQuantity(data.DefaultQuantity). + SetDefaultInsured(data.DefaultInsured). + SetNillableDefaultName(data.DefaultName). + SetNillableDefaultDescription(data.DefaultDescription). + SetNillableDefaultManufacturer(data.DefaultManufacturer). + SetNillableDefaultModelNumber(data.DefaultModelNumber). + SetDefaultLifetimeWarranty(data.DefaultLifetimeWarranty). + SetNillableDefaultWarrantyDetails(data.DefaultWarrantyDetails). + SetIncludeWarrantyFields(data.IncludeWarrantyFields). + SetIncludePurchaseFields(data.IncludePurchaseFields). + SetIncludeSoldFields(data.IncludeSoldFields). + SetGroupID(gid). + SetNillableLocationID(data.DefaultLocationID) + + // Set default label IDs (stored as JSON) + if data.DefaultLabelIDs != nil && len(*data.DefaultLabelIDs) > 0 { + q.SetDefaultLabelIds(*data.DefaultLabelIDs) + } + + template, err := q.Save(ctx) + if err != nil { + return ItemTemplateOut{}, err + } + + // Create template fields + for _, field := range data.Fields { + _, err = r.db.TemplateField.Create(). + SetItemTemplateID(template.ID). + SetType(templatefield.Type(field.Type)). + SetName(field.Name). + SetTextValue(field.TextValue). + Save(ctx) + + if err != nil { + log.Err(err).Msg("failed to create template field") + return ItemTemplateOut{}, err + } + } + + r.publishMutationEvent(gid) + return r.GetOne(ctx, gid, template.ID) +} + +// Update updates an existing template +func (r *ItemTemplatesRepository) Update(ctx context.Context, gid uuid.UUID, data ItemTemplateUpdate) (ItemTemplateOut, error) { + // Verify template belongs to group + template, err := r.db.ItemTemplate.Query(). + Where( + itemtemplate.ID(data.ID), + itemtemplate.HasGroupWith(group.ID(gid)), + ). + Only(ctx) + + if err != nil { + return ItemTemplateOut{}, err + } + + // Update template + updateQ := template.Update(). + SetName(data.Name). + SetDescription(data.Description). + SetNotes(data.Notes). + SetNillableDefaultQuantity(data.DefaultQuantity). + SetDefaultInsured(data.DefaultInsured). + SetNillableDefaultName(data.DefaultName). + SetNillableDefaultDescription(data.DefaultDescription). + SetNillableDefaultManufacturer(data.DefaultManufacturer). + SetNillableDefaultModelNumber(data.DefaultModelNumber). + SetDefaultLifetimeWarranty(data.DefaultLifetimeWarranty). + SetNillableDefaultWarrantyDetails(data.DefaultWarrantyDetails). + SetIncludeWarrantyFields(data.IncludeWarrantyFields). + SetIncludePurchaseFields(data.IncludePurchaseFields). + SetIncludeSoldFields(data.IncludeSoldFields) + + // Update location + if data.DefaultLocationID != nil { + updateQ.SetLocationID(*data.DefaultLocationID) + } else { + updateQ.ClearLocation() + } + + // Update default label IDs (stored as JSON) + if data.DefaultLabelIDs != nil && len(*data.DefaultLabelIDs) > 0 { + updateQ.SetDefaultLabelIds(*data.DefaultLabelIDs) + } else { + updateQ.ClearDefaultLabelIds() + } + + _, err = updateQ.Save(ctx) + if err != nil { + return ItemTemplateOut{}, err + } + + // Get existing fields + existingFields, err := r.db.TemplateField.Query(). + Where(templatefield.HasItemTemplateWith(itemtemplate.ID(data.ID))). + All(ctx) + + if err != nil { + return ItemTemplateOut{}, err + } + + // Create a map of existing field IDs for quick lookup + existingFieldMap := make(map[uuid.UUID]bool) + for _, field := range existingFields { + existingFieldMap[field.ID] = true + } + + // Track which fields are being updated + updatedFieldIDs := make(map[uuid.UUID]bool) + + // Create or update fields + for _, field := range data.Fields { + if field.ID == nil || *field.ID == uuid.Nil { + // Create new field + _, err = r.db.TemplateField.Create(). + SetItemTemplateID(data.ID). + SetType(templatefield.Type(field.Type)). + SetName(field.Name). + SetTextValue(field.TextValue). + Save(ctx) + + if err != nil { + log.Err(err).Msg("failed to create template field") + return ItemTemplateOut{}, err + } + } else { + // Update existing field + updatedFieldIDs[*field.ID] = true + _, err = r.db.TemplateField.Update(). + Where( + templatefield.ID(*field.ID), + templatefield.HasItemTemplateWith(itemtemplate.ID(data.ID)), + ). + SetType(templatefield.Type(field.Type)). + SetName(field.Name). + SetTextValue(field.TextValue). + Save(ctx) + + if err != nil { + log.Err(err).Msg("failed to update template field") + return ItemTemplateOut{}, err + } + } + } + + // Delete fields that are no longer present + for _, field := range existingFields { + if !updatedFieldIDs[field.ID] { + err = r.db.TemplateField.DeleteOne(field).Exec(ctx) + if err != nil { + log.Err(err).Msg("failed to delete template field") + } + } + } + + r.publishMutationEvent(gid) + return r.GetOne(ctx, gid, template.ID) +} + +// Delete deletes a template +func (r *ItemTemplatesRepository) Delete(ctx context.Context, gid uuid.UUID, id uuid.UUID) error { + // Verify template belongs to group + _, err := r.db.ItemTemplate.Query(). + Where( + itemtemplate.ID(id), + itemtemplate.HasGroupWith(group.ID(gid)), + ). + Only(ctx) + + if err != nil { + return err + } + + // Delete template (fields will be cascade deleted) + err = r.db.ItemTemplate.DeleteOneID(id).Exec(ctx) + if err != nil { + return err + } + + r.publishMutationEvent(gid) + return nil +} diff --git a/backend/internal/data/repo/repo_item_templates_test.go b/backend/internal/data/repo/repo_item_templates_test.go new file mode 100644 index 00000000..dab5627d --- /dev/null +++ b/backend/internal/data/repo/repo_item_templates_test.go @@ -0,0 +1,337 @@ +package repo + +import ( + "context" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func templateFactory() ItemTemplateCreate { + qty := 1 + name := fk.Str(20) + desc := fk.Str(50) + mfr := fk.Str(15) + model := fk.Str(10) + warranty := "" + + return ItemTemplateCreate{ + Name: fk.Str(10), + Description: fk.Str(100), + Notes: fk.Str(50), + DefaultQuantity: &qty, + DefaultInsured: false, + DefaultName: &name, + DefaultDescription: &desc, + DefaultManufacturer: &mfr, + DefaultModelNumber: &model, + DefaultLifetimeWarranty: false, + DefaultWarrantyDetails: &warranty, + IncludeWarrantyFields: false, + IncludePurchaseFields: false, + IncludeSoldFields: false, + Fields: []TemplateField{}, + } +} + +func useTemplates(t *testing.T, count int) []ItemTemplateOut { + t.Helper() + + templates := make([]ItemTemplateOut, count) + for i := 0; i < count; i++ { + data := templateFactory() + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + templates[i] = template + } + + t.Cleanup(func() { + for _, template := range templates { + _ = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + } + }) + + return templates +} + +func TestItemTemplatesRepository_GetAll(t *testing.T) { + useTemplates(t, 5) + + all, err := tRepos.ItemTemplates.GetAll(context.Background(), tGroup.ID) + require.NoError(t, err) + assert.GreaterOrEqual(t, len(all), 5) +} + +func TestItemTemplatesRepository_GetOne(t *testing.T) { + templates := useTemplates(t, 1) + template := templates[0] + + found, err := tRepos.ItemTemplates.GetOne(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) + assert.Equal(t, template.ID, found.ID) + assert.Equal(t, template.Name, found.Name) + assert.Equal(t, template.Description, found.Description) +} + +func TestItemTemplatesRepository_Create(t *testing.T) { + data := templateFactory() + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + + assert.NotEqual(t, uuid.Nil, template.ID) + assert.Equal(t, data.Name, template.Name) + assert.Equal(t, data.Description, template.Description) + assert.Equal(t, *data.DefaultQuantity, template.DefaultQuantity) + assert.Equal(t, data.DefaultInsured, template.DefaultInsured) + assert.Equal(t, *data.DefaultName, template.DefaultName) + assert.Equal(t, *data.DefaultDescription, template.DefaultDescription) + assert.Equal(t, *data.DefaultManufacturer, template.DefaultManufacturer) + assert.Equal(t, *data.DefaultModelNumber, template.DefaultModelNumber) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} + +func TestItemTemplatesRepository_CreateWithFields(t *testing.T) { + data := templateFactory() + data.Fields = []TemplateField{ + {Name: "Field 1", Type: "text", TextValue: "Value 1"}, + {Name: "Field 2", Type: "text", TextValue: "Value 2"}, + } + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + + assert.Len(t, template.Fields, 2) + assert.Equal(t, "Field 1", template.Fields[0].Name) + assert.Equal(t, "Value 1", template.Fields[0].TextValue) + assert.Equal(t, "Field 2", template.Fields[1].Name) + assert.Equal(t, "Value 2", template.Fields[1].TextValue) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} + +func TestItemTemplatesRepository_Update(t *testing.T) { + templates := useTemplates(t, 1) + template := templates[0] + + qty := 5 + defaultName := "Default Item Name" + defaultDesc := "Default Item Description" + defaultMfr := "Updated Manufacturer" + defaultModel := "MODEL-123" + defaultWarranty := "Lifetime coverage" + + updateData := ItemTemplateUpdate{ + ID: template.ID, + Name: "Updated Name", + Description: "Updated Description", + Notes: "Updated Notes", + DefaultQuantity: &qty, + DefaultInsured: true, + DefaultName: &defaultName, + DefaultDescription: &defaultDesc, + DefaultManufacturer: &defaultMfr, + DefaultModelNumber: &defaultModel, + DefaultLifetimeWarranty: true, + DefaultWarrantyDetails: &defaultWarranty, + IncludeWarrantyFields: true, + IncludePurchaseFields: true, + IncludeSoldFields: false, + Fields: []TemplateField{}, + } + + updated, err := tRepos.ItemTemplates.Update(context.Background(), tGroup.ID, updateData) + require.NoError(t, err) + + assert.Equal(t, template.ID, updated.ID) + assert.Equal(t, "Updated Name", updated.Name) + assert.Equal(t, "Updated Description", updated.Description) + assert.Equal(t, "Updated Notes", updated.Notes) + assert.Equal(t, 5, updated.DefaultQuantity) + assert.True(t, updated.DefaultInsured) + assert.Equal(t, "Default Item Name", updated.DefaultName) + assert.Equal(t, "Default Item Description", updated.DefaultDescription) + assert.Equal(t, "Updated Manufacturer", updated.DefaultManufacturer) + assert.Equal(t, "MODEL-123", updated.DefaultModelNumber) + assert.True(t, updated.DefaultLifetimeWarranty) + assert.Equal(t, "Lifetime coverage", updated.DefaultWarrantyDetails) + assert.True(t, updated.IncludeWarrantyFields) + assert.True(t, updated.IncludePurchaseFields) + assert.False(t, updated.IncludeSoldFields) +} + +func TestItemTemplatesRepository_UpdateWithFields(t *testing.T) { + data := templateFactory() + data.Fields = []TemplateField{ + {Name: "Original Field", Type: "text", TextValue: "Original Value"}, + } + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + require.Len(t, template.Fields, 1) + + // Update with new fields + qty := template.DefaultQuantity + updateData := ItemTemplateUpdate{ + ID: template.ID, + Name: template.Name, + Description: template.Description, + DefaultQuantity: &qty, + Fields: []TemplateField{ + {ID: template.Fields[0].ID, Name: "Updated Field", Type: "text", TextValue: "Updated Value"}, + {Name: "New Field", Type: "text", TextValue: "New Value"}, + }, + } + + updated, err := tRepos.ItemTemplates.Update(context.Background(), tGroup.ID, updateData) + require.NoError(t, err) + + assert.Len(t, updated.Fields, 2) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} + +func TestItemTemplatesRepository_Delete(t *testing.T) { + data := templateFactory() + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) + + // Verify it's deleted + _, err = tRepos.ItemTemplates.GetOne(context.Background(), tGroup.ID, template.ID) + require.Error(t, err) +} + +func TestItemTemplatesRepository_DeleteCascadesFields(t *testing.T) { + data := templateFactory() + data.Fields = []TemplateField{ + {Name: "Field 1", Type: "text", TextValue: "Value 1"}, + {Name: "Field 2", Type: "text", TextValue: "Value 2"}, + } + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + require.Len(t, template.Fields, 2) + + // Delete template - fields should be cascade deleted + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) + + // Verify template is deleted + _, err = tRepos.ItemTemplates.GetOne(context.Background(), tGroup.ID, template.ID) + require.Error(t, err) +} + +func TestItemTemplatesRepository_CreateWithLocation(t *testing.T) { + // First create a location + loc, err := tRepos.Locations.Create(context.Background(), tGroup.ID, LocationCreate{ + Name: fk.Str(10), + Description: fk.Str(50), + }) + require.NoError(t, err) + + t.Cleanup(func() { + _ = tRepos.Locations.delete(context.Background(), loc.ID) + }) + + // Create template with location + data := templateFactory() + data.DefaultLocationID = &loc.ID + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + + assert.NotNil(t, template.DefaultLocation) + assert.Equal(t, loc.ID, template.DefaultLocation.ID) + assert.Equal(t, loc.Name, template.DefaultLocation.Name) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} + +func TestItemTemplatesRepository_CreateWithLabels(t *testing.T) { + // Create some labels + label1, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + Name: fk.Str(10), + Description: fk.Str(50), + }) + require.NoError(t, err) + + label2, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + Name: fk.Str(10), + Description: fk.Str(50), + }) + require.NoError(t, err) + + t.Cleanup(func() { + _ = tRepos.Labels.delete(context.Background(), label1.ID) + _ = tRepos.Labels.delete(context.Background(), label2.ID) + }) + + // Create template with labels + data := templateFactory() + labelIDs := []uuid.UUID{label1.ID, label2.ID} + data.DefaultLabelIDs = &labelIDs + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + + assert.Len(t, template.DefaultLabels, 2) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} + +func TestItemTemplatesRepository_UpdateRemoveLocation(t *testing.T) { + // First create a location + loc, err := tRepos.Locations.Create(context.Background(), tGroup.ID, LocationCreate{ + Name: fk.Str(10), + Description: fk.Str(50), + }) + require.NoError(t, err) + + t.Cleanup(func() { + _ = tRepos.Locations.delete(context.Background(), loc.ID) + }) + + // Create template with location + data := templateFactory() + data.DefaultLocationID = &loc.ID + + template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) + require.NoError(t, err) + require.NotNil(t, template.DefaultLocation) + + // Update to remove location + qty := template.DefaultQuantity + updateData := ItemTemplateUpdate{ + ID: template.ID, + Name: template.Name, + DefaultQuantity: &qty, + DefaultLocationID: nil, // Remove location + } + + updated, err := tRepos.ItemTemplates.Update(context.Background(), tGroup.ID, updateData) + require.NoError(t, err) + + assert.Nil(t, updated.DefaultLocation) + + // Cleanup + err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) + require.NoError(t, err) +} diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 9a014b83..c2749b0a 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -654,6 +654,90 @@ func (e *ItemsRepository) Create(ctx context.Context, gid uuid.UUID, data ItemCr return e.GetOne(ctx, result.ID) } +// ItemCreateFromTemplate contains all data needed to create an item from a template. +type ItemCreateFromTemplate struct { + Name string + Description string + Quantity int + LocationID uuid.UUID + LabelIDs []uuid.UUID + Insured bool + Manufacturer string + ModelNumber string + LifetimeWarranty bool + WarrantyDetails string + Fields []ItemField +} + +// CreateFromTemplate creates an item with all template data in a single transaction. +func (e *ItemsRepository) CreateFromTemplate(ctx context.Context, gid uuid.UUID, data ItemCreateFromTemplate) (ItemOut, error) { + tx, err := e.db.Tx(ctx) + if err != nil { + return ItemOut{}, err + } + committed := false + defer func() { + if !committed { + if err := tx.Rollback(); err != nil { + log.Warn().Err(err).Msg("failed to rollback transaction during template item creation") + } + } + }() + + // Get next asset ID within transaction + nextAssetID, err := e.GetHighestAssetIDTx(ctx, tx, gid) + if err != nil { + return ItemOut{}, err + } + nextAssetID++ + + // Create item with all template data + newItemID := uuid.New() + itemBuilder := tx.Item.Create(). + SetID(newItemID). + SetName(data.Name). + SetDescription(data.Description). + SetQuantity(data.Quantity). + SetLocationID(data.LocationID). + SetGroupID(gid). + SetAssetID(int(nextAssetID)). + SetInsured(data.Insured). + SetManufacturer(data.Manufacturer). + SetModelNumber(data.ModelNumber). + SetLifetimeWarranty(data.LifetimeWarranty). + SetWarrantyDetails(data.WarrantyDetails) + + if len(data.LabelIDs) > 0 { + itemBuilder.AddLabelIDs(data.LabelIDs...) + } + + _, err = itemBuilder.Save(ctx) + if err != nil { + return ItemOut{}, err + } + + // Create custom fields + for _, field := range data.Fields { + _, err = tx.ItemField.Create(). + SetItemID(newItemID). + SetType(itemfield.Type(field.Type)). + SetName(field.Name). + SetTextValue(field.TextValue). + Save(ctx) + if err != nil { + return ItemOut{}, fmt.Errorf("failed to create field %s: %w", field.Name, err) + } + } + + if err = tx.Commit(); err != nil { + return ItemOut{}, err + } + committed = true + + e.publishMutationEvent(gid) + return e.GetOne(ctx, newItemID) +} + func (e *ItemsRepository) Delete(ctx context.Context, id uuid.UUID) error { // Get the item with its group and attachments before deletion itm, err := e.db.Item.Query(). diff --git a/backend/internal/data/repo/repos_all.go b/backend/internal/data/repo/repos_all.go index a9670aaa..6109d743 100644 --- a/backend/internal/data/repo/repos_all.go +++ b/backend/internal/data/repo/repos_all.go @@ -9,28 +9,30 @@ import ( // AllRepos is a container for all the repository interfaces type AllRepos struct { - Users *UserRepository - AuthTokens *TokenRepository - Groups *GroupRepository - Locations *LocationRepository - Labels *LabelRepository - Items *ItemsRepository - Attachments *AttachmentRepo - MaintEntry *MaintenanceEntryRepository - Notifiers *NotifierRepository + Users *UserRepository + AuthTokens *TokenRepository + Groups *GroupRepository + Locations *LocationRepository + Labels *LabelRepository + Items *ItemsRepository + ItemTemplates *ItemTemplatesRepository + Attachments *AttachmentRepo + MaintEntry *MaintenanceEntryRepository + Notifiers *NotifierRepository } func New(db *ent.Client, bus *eventbus.EventBus, storage config.Storage, pubSubConn string, thumbnail config.Thumbnail) *AllRepos { attachments := &AttachmentRepo{db, storage, pubSubConn, thumbnail} return &AllRepos{ - Users: &UserRepository{db}, - AuthTokens: &TokenRepository{db}, - Groups: NewGroupRepository(db), - Locations: &LocationRepository{db, bus}, - Labels: &LabelRepository{db, bus}, - Items: &ItemsRepository{db, bus, attachments}, - Attachments: attachments, - MaintEntry: &MaintenanceEntryRepository{db}, - Notifiers: NewNotifierRepository(db), + Users: &UserRepository{db}, + AuthTokens: &TokenRepository{db}, + Groups: NewGroupRepository(db), + Locations: &LocationRepository{db, bus}, + Labels: &LabelRepository{db, bus}, + Items: &ItemsRepository{db, bus, attachments}, + ItemTemplates: &ItemTemplatesRepository{db, bus}, + Attachments: attachments, + MaintEntry: &MaintenanceEntryRepository{db}, + Notifiers: NewNotifierRepository(db), } } diff --git a/docs/en/api/openapi-2.0.json b/docs/en/api/openapi-2.0.json new file mode 100644 index 00000000..cd4721fa --- /dev/null +++ b/docs/en/api/openapi-2.0.json @@ -0,0 +1,5195 @@ +{ + "schemes": [ + "https", + "http" + ], + "swagger": "2.0", + "info": { + "description": "Track, Manage, and Organize your Things.", + "title": "Homebox API", + "contact": { + "name": "Homebox Team", + "url": "https://discord.homebox.software" + }, + "version": "1.0" + }, + "host": "demo.homebox.software", + "basePath": "/api", + "paths": { + "/v1/actions/create-missing-thumbnails": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "Creates thumbnails for items that are missing them", + "produces": [ + "application/json" + ], + "tags": [ + "Actions" + ], + "summary": "Create Missing Thumbnails", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ActionAmountResult" + } + } + } + } + }, + "/v1/actions/ensure-asset-ids": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "Ensures all items in the database have an asset ID", + "produces": [ + "application/json" + ], + "tags": [ + "Actions" + ], + "summary": "Ensure Asset IDs", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ActionAmountResult" + } + } + } + } + }, + "/v1/actions/ensure-import-refs": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "Ensures all items in the database have an import ref", + "produces": [ + "application/json" + ], + "tags": [ + "Actions" + ], + "summary": "Ensures Import Refs", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ActionAmountResult" + } + } + } + } + }, + "/v1/actions/set-primary-photos": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "Sets the first photo of each item as the primary photo", + "produces": [ + "application/json" + ], + "tags": [ + "Actions" + ], + "summary": "Set Primary Photos", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ActionAmountResult" + } + } + } + } + }, + "/v1/actions/zero-item-time-fields": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "Resets all item date fields to the beginning of the day", + "produces": [ + "application/json" + ], + "tags": [ + "Actions" + ], + "summary": "Zero Out Time Fields", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ActionAmountResult" + } + } + } + } + }, + "/v1/assets/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get Item by Asset ID", + "parameters": [ + { + "type": "string", + "description": "Asset ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.PaginationResult-repo_ItemSummary" + } + } + } + } + }, + "/v1/currency": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Base" + ], + "summary": "Currency", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/currencies.Currency" + } + } + } + } + }, + "/v1/groups": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Group" + ], + "summary": "Get Group", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.Group" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Group" + ], + "summary": "Update Group", + "parameters": [ + { + "description": "User Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.GroupUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.Group" + } + } + } + } + }, + "/v1/groups/invitations": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Group" + ], + "summary": "Create Group Invitation", + "parameters": [ + { + "description": "User Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.GroupInvitationCreate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GroupInvitation" + } + } + } + } + }, + "/v1/groups/statistics": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Statistics" + ], + "summary": "Get Group Statistics", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.GroupStatistics" + } + } + } + } + }, + "/v1/groups/statistics/labels": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Statistics" + ], + "summary": "Get Label Statistics", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TotalsByOrganizer" + } + } + } + } + } + }, + "/v1/groups/statistics/locations": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Statistics" + ], + "summary": "Get Location Statistics", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TotalsByOrganizer" + } + } + } + } + } + }, + "/v1/groups/statistics/purchase-price": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Statistics" + ], + "summary": "Get Purchase Price Statistics", + "parameters": [ + { + "type": "string", + "description": "start date", + "name": "start", + "in": "query" + }, + { + "type": "string", + "description": "end date", + "name": "end", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ValueOverTime" + } + } + } + } + }, + "/v1/items": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Query All Items", + "parameters": [ + { + "type": "string", + "description": "search string", + "name": "q", + "in": "query" + }, + { + "type": "integer", + "description": "page number", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "items per page", + "name": "pageSize", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi", + "description": "label Ids", + "name": "labels", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi", + "description": "location Ids", + "name": "locations", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "multi", + "description": "parent Ids", + "name": "parentIds", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.PaginationResult-repo_ItemSummary" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Create Item", + "parameters": [ + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemSummary" + } + } + } + } + }, + "/v1/items/export": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Items" + ], + "summary": "Export Items", + "responses": { + "200": { + "description": "text/csv", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/items/fields": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get All Custom Field Names", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + }, + "/v1/items/fields/values": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get All Custom Field Values", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + }, + "/v1/items/import": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Import Items", + "parameters": [ + { + "type": "file", + "description": "Image to upload", + "name": "csv", + "in": "formData", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/items/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Update Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Delete Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + }, + "patch": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Update Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemPatch" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, + "/v1/items/{id}/attachments": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items Attachments" + ], + "summary": "Create Item Attachment", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "File attachment", + "name": "file", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Type of file", + "name": "type", + "in": "formData" + }, + { + "type": "boolean", + "description": "Is this the primary attachment", + "name": "primary", + "in": "formData" + }, + { + "type": "string", + "description": "name of the file including extension", + "name": "name", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "$ref": "#/definitions/validate.ErrorResponse" + } + } + } + } + }, + "/v1/items/{id}/attachments/{attachment_id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/octet-stream" + ], + "tags": [ + "Items Attachments" + ], + "summary": "Get Item Attachment", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Attachment ID", + "name": "attachment_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.ItemAttachmentToken" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Items Attachments" + ], + "summary": "Update Item Attachment", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Attachment ID", + "name": "attachment_id", + "in": "path", + "required": true + }, + { + "description": "Attachment Update", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemAttachmentUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Items Attachments" + ], + "summary": "Delete Item Attachment", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Attachment ID", + "name": "attachment_id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/items/{id}/duplicate": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Duplicate Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Duplicate Options", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.DuplicateOptions" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, + "/v1/items/{id}/maintenance": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Maintenance" + ], + "summary": "Get Maintenance Log", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "enum": [ + "scheduled", + "completed", + "both" + ], + "type": "string", + "x-enum-varnames": [ + "MaintenanceFilterStatusScheduled", + "MaintenanceFilterStatusCompleted", + "MaintenanceFilterStatusBoth" + ], + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.MaintenanceEntryWithDetails" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Maintenance" + ], + "summary": "Create Maintenance Entry", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Entry Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.MaintenanceEntryCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.MaintenanceEntry" + } + } + } + } + }, + "/v1/items/{id}/path": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get the full path of an item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemPath" + } + } + } + } + } + }, + "/v1/labelmaker/assets/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get Asset label", + "parameters": [ + { + "type": "string", + "description": "Asset ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "boolean", + "description": "Print this label, defaults to false", + "name": "print", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/png", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/labelmaker/item/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Get Item label", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "boolean", + "description": "Print this label, defaults to false", + "name": "print", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/png", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/labelmaker/location/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Get Location label", + "parameters": [ + { + "type": "string", + "description": "Location ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "boolean", + "description": "Print this label, defaults to false", + "name": "print", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/png", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/labels": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Labels" + ], + "summary": "Get All Labels", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.LabelOut" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Labels" + ], + "summary": "Create Label", + "parameters": [ + { + "description": "Label Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.LabelCreate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LabelSummary" + } + } + } + } + }, + "/v1/labels/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Labels" + ], + "summary": "Get Label", + "parameters": [ + { + "type": "string", + "description": "Label ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LabelOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Labels" + ], + "summary": "Update Label", + "parameters": [ + { + "type": "string", + "description": "Label ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LabelOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Labels" + ], + "summary": "Delete Label", + "parameters": [ + { + "type": "string", + "description": "Label ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/locations": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Get All Locations", + "parameters": [ + { + "type": "boolean", + "description": "Filter locations with parents", + "name": "filterChildren", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.LocationOutCount" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Create Location", + "parameters": [ + { + "description": "Location Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.LocationCreate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LocationSummary" + } + } + } + } + }, + "/v1/locations/tree": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Get Locations Tree", + "parameters": [ + { + "type": "boolean", + "description": "include items in response tree", + "name": "withItems", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TreeItem" + } + } + } + } + } + }, + "/v1/locations/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Get Location", + "parameters": [ + { + "type": "string", + "description": "Location ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LocationOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Update Location", + "parameters": [ + { + "type": "string", + "description": "Location ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Location Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.LocationUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.LocationOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Locations" + ], + "summary": "Delete Location", + "parameters": [ + { + "type": "string", + "description": "Location ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/maintenance": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Maintenance" + ], + "summary": "Query All Maintenance", + "parameters": [ + { + "enum": [ + "scheduled", + "completed", + "both" + ], + "type": "string", + "x-enum-varnames": [ + "MaintenanceFilterStatusScheduled", + "MaintenanceFilterStatusCompleted", + "MaintenanceFilterStatusBoth" + ], + "name": "status", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.MaintenanceEntryWithDetails" + } + } + } + } + } + }, + "/v1/maintenance/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Maintenance" + ], + "summary": "Update Maintenance Entry", + "parameters": [ + { + "type": "string", + "description": "Maintenance ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Entry Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.MaintenanceEntryUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.MaintenanceEntry" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Maintenance" + ], + "summary": "Delete Maintenance Entry", + "parameters": [ + { + "type": "string", + "description": "Maintenance ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/notifiers": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Notifiers" + ], + "summary": "Get Notifiers", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.NotifierOut" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Notifiers" + ], + "summary": "Create Notifier", + "parameters": [ + { + "description": "Notifier Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.NotifierCreate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.NotifierOut" + } + } + } + } + }, + "/v1/notifiers/test": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Notifiers" + ], + "summary": "Test Notifier", + "parameters": [ + { + "type": "string", + "description": "URL", + "name": "url", + "in": "query", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/notifiers/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Notifiers" + ], + "summary": "Update Notifier", + "parameters": [ + { + "type": "string", + "description": "Notifier ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Notifier Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.NotifierUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.NotifierOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Notifiers" + ], + "summary": "Delete a Notifier", + "parameters": [ + { + "type": "string", + "description": "Notifier ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/products/search-from-barcode": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Search EAN from Barcode", + "parameters": [ + { + "type": "string", + "description": "barcode to be searched", + "name": "data", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.BarcodeProduct" + } + } + } + } + } + }, + "/v1/qrcode": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Create QR Code", + "parameters": [ + { + "type": "string", + "description": "data to be encoded into qrcode", + "name": "data", + "in": "query" + } + ], + "responses": { + "200": { + "description": "image/jpeg", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/reporting/bill-of-materials": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Reporting" + ], + "summary": "Export Bill of Materials", + "responses": { + "200": { + "description": "text/csv", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/status": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Base" + ], + "summary": "Application Info", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.APISummary" + } + } + } + } + }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemTemplateSummary" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "parameters": [ + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.ItemTemplateCreateItemRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, + "/v1/users/change-password": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "User" + ], + "summary": "Change Password", + "parameters": [ + { + "description": "Password Payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.ChangePassword" + } + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/users/login": { + "post": { + "consumes": [ + "application/x-www-form-urlencoded", + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Authentication" + ], + "summary": "User Login", + "parameters": [ + { + "description": "Login Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.LoginForm" + } + }, + { + "type": "string", + "description": "auth provider", + "name": "provider", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.TokenResponse" + } + } + } + } + }, + "/v1/users/login/oidc": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "type": "string", + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "State parameter", + "name": "state", + "in": "query", + "required": true + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/logout": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Authentication" + ], + "summary": "User Logout", + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/users/refresh": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "handleAuthRefresh returns a handler that will issue a new token from an existing token.\nThis does not validate that the user still exists within the database.", + "tags": [ + "Authentication" + ], + "summary": "User Token Refresh", + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/v1/users/register": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Register New User", + "parameters": [ + { + "description": "User Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/services.UserRegistration" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "schema": { + "type": "string" + } + } + } + } + }, + "/v1/users/self": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Get User Self", + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/v1.Wrapped" + }, + { + "type": "object", + "properties": { + "item": { + "$ref": "#/definitions/repo.UserOut" + } + } + } + ] + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Update Account", + "parameters": [ + { + "description": "User Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.UserUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/v1.Wrapped" + }, + { + "type": "object", + "properties": { + "item": { + "$ref": "#/definitions/repo.UserUpdate" + } + } + } + ] + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "Delete Account", + "responses": { + "204": { + "description": "No Content" + } + } + } + } + }, + "definitions": { + "attachment.Type": { + "type": "string", + "enum": [ + "attachment", + "photo", + "manual", + "warranty", + "attachment", + "receipt", + "thumbnail" + ], + "x-enum-varnames": [ + "DefaultType", + "TypePhoto", + "TypeManual", + "TypeWarranty", + "TypeAttachment", + "TypeReceipt", + "TypeThumbnail" + ] + }, + "authroles.Role": { + "type": "string", + "enum": [ + "user", + "admin", + "user", + "attachments" + ], + "x-enum-varnames": [ + "DefaultRole", + "RoleAdmin", + "RoleUser", + "RoleAttachments" + ] + }, + "currencies.Currency": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "decimals": { + "type": "integer" + }, + "local": { + "type": "string" + }, + "name": { + "type": "string" + }, + "symbol": { + "type": "string" + } + } + }, + "ent.Attachment": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the AttachmentQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.AttachmentEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "mime_type": { + "description": "MimeType holds the value of the \"mime_type\" field.", + "type": "string" + }, + "path": { + "description": "Path holds the value of the \"path\" field.", + "type": "string" + }, + "primary": { + "description": "Primary holds the value of the \"primary\" field.", + "type": "boolean" + }, + "title": { + "description": "Title holds the value of the \"title\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/attachment.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.AttachmentEdges": { + "type": "object", + "properties": { + "item": { + "description": "Item holds the value of the item edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Item" + } + ] + }, + "thumbnail": { + "description": "Thumbnail holds the value of the thumbnail edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Attachment" + } + ] + } + } + }, + "ent.AuthRoles": { + "type": "object", + "properties": { + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the AuthRolesQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.AuthRolesEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "integer" + }, + "role": { + "description": "Role holds the value of the \"role\" field.", + "allOf": [ + { + "$ref": "#/definitions/authroles.Role" + } + ] + } + } + }, + "ent.AuthRolesEdges": { + "type": "object", + "properties": { + "token": { + "description": "Token holds the value of the token edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.AuthTokens" + } + ] + } + } + }, + "ent.AuthTokens": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the AuthTokensQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.AuthTokensEdges" + } + ] + }, + "expires_at": { + "description": "ExpiresAt holds the value of the \"expires_at\" field.", + "type": "string" + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "token": { + "description": "Token holds the value of the \"token\" field.", + "type": "array", + "items": { + "type": "integer" + } + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.AuthTokensEdges": { + "type": "object", + "properties": { + "roles": { + "description": "Roles holds the value of the roles edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.AuthRoles" + } + ] + }, + "user": { + "description": "User holds the value of the user edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.User" + } + ] + } + } + }, + "ent.Group": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "currency": { + "description": "Currency holds the value of the \"currency\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the GroupQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.GroupEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.GroupEdges": { + "type": "object", + "properties": { + "invitation_tokens": { + "description": "InvitationTokens holds the value of the invitation_tokens edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.GroupInvitationToken" + } + }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ItemTemplate" + } + }, + "items": { + "description": "Items holds the value of the items edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Item" + } + }, + "labels": { + "description": "Labels holds the value of the labels edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Label" + } + }, + "locations": { + "description": "Locations holds the value of the locations edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Location" + } + }, + "notifiers": { + "description": "Notifiers holds the value of the notifiers edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Notifier" + } + }, + "users": { + "description": "Users holds the value of the users edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.User" + } + } + } + }, + "ent.GroupInvitationToken": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the GroupInvitationTokenQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.GroupInvitationTokenEdges" + } + ] + }, + "expires_at": { + "description": "ExpiresAt holds the value of the \"expires_at\" field.", + "type": "string" + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "token": { + "description": "Token holds the value of the \"token\" field.", + "type": "array", + "items": { + "type": "integer" + } + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + }, + "uses": { + "description": "Uses holds the value of the \"uses\" field.", + "type": "integer" + } + } + }, + "ent.GroupInvitationTokenEdges": { + "type": "object", + "properties": { + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + } + } + }, + "ent.Item": { + "type": "object", + "properties": { + "archived": { + "description": "Archived holds the value of the \"archived\" field.", + "type": "boolean" + }, + "asset_id": { + "description": "AssetID holds the value of the \"asset_id\" field.", + "type": "integer" + }, + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "import_ref": { + "description": "ImportRef holds the value of the \"import_ref\" field.", + "type": "string" + }, + "insured": { + "description": "Insured holds the value of the \"insured\" field.", + "type": "boolean" + }, + "lifetime_warranty": { + "description": "LifetimeWarranty holds the value of the \"lifetime_warranty\" field.", + "type": "boolean" + }, + "manufacturer": { + "description": "Manufacturer holds the value of the \"manufacturer\" field.", + "type": "string" + }, + "model_number": { + "description": "ModelNumber holds the value of the \"model_number\" field.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "purchase_from": { + "description": "PurchaseFrom holds the value of the \"purchase_from\" field.", + "type": "string" + }, + "purchase_price": { + "description": "PurchasePrice holds the value of the \"purchase_price\" field.", + "type": "number" + }, + "purchase_time": { + "description": "PurchaseTime holds the value of the \"purchase_time\" field.", + "type": "string" + }, + "quantity": { + "description": "Quantity holds the value of the \"quantity\" field.", + "type": "integer" + }, + "serial_number": { + "description": "SerialNumber holds the value of the \"serial_number\" field.", + "type": "string" + }, + "sold_notes": { + "description": "SoldNotes holds the value of the \"sold_notes\" field.", + "type": "string" + }, + "sold_price": { + "description": "SoldPrice holds the value of the \"sold_price\" field.", + "type": "number" + }, + "sold_time": { + "description": "SoldTime holds the value of the \"sold_time\" field.", + "type": "string" + }, + "sold_to": { + "description": "SoldTo holds the value of the \"sold_to\" field.", + "type": "string" + }, + "sync_child_items_locations": { + "description": "SyncChildItemsLocations holds the value of the \"sync_child_items_locations\" field.", + "type": "boolean" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + }, + "warranty_details": { + "description": "WarrantyDetails holds the value of the \"warranty_details\" field.", + "type": "string" + }, + "warranty_expires": { + "description": "WarrantyExpires holds the value of the \"warranty_expires\" field.", + "type": "string" + } + } + }, + "ent.ItemEdges": { + "type": "object", + "properties": { + "attachments": { + "description": "Attachments holds the value of the attachments edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Attachment" + } + }, + "children": { + "description": "Children holds the value of the children edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Item" + } + }, + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ItemField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "label": { + "description": "Label holds the value of the label edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Label" + } + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + }, + "maintenance_entries": { + "description": "MaintenanceEntries holds the value of the maintenance_entries edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.MaintenanceEntry" + } + }, + "parent": { + "description": "Parent holds the value of the parent edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Item" + } + ] + } + } + }, + "ent.ItemField": { + "type": "object", + "properties": { + "boolean_value": { + "description": "BooleanValue holds the value of the \"boolean_value\" field.", + "type": "boolean" + }, + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "number_value": { + "description": "NumberValue holds the value of the \"number_value\" field.", + "type": "integer" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "time_value": { + "description": "TimeValue holds the value of the \"time_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/itemfield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemFieldEdges": { + "type": "object", + "properties": { + "item": { + "description": "Item holds the value of the item edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Item" + } + ] + } + } + }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + } + } + }, + "ent.Label": { + "type": "object", + "properties": { + "color": { + "description": "Color holds the value of the \"color\" field.", + "type": "string" + }, + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the LabelQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.LabelEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.LabelEdges": { + "type": "object", + "properties": { + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "items": { + "description": "Items holds the value of the items edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Item" + } + } + } + }, + "ent.Location": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the LocationQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.LocationEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.LocationEdges": { + "type": "object", + "properties": { + "children": { + "description": "Children holds the value of the children edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Location" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "items": { + "description": "Items holds the value of the items edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Item" + } + }, + "parent": { + "description": "Parent holds the value of the parent edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + } + } + }, + "ent.MaintenanceEntry": { + "type": "object", + "properties": { + "cost": { + "description": "Cost holds the value of the \"cost\" field.", + "type": "number" + }, + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "date": { + "description": "Date holds the value of the \"date\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the MaintenanceEntryQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.MaintenanceEntryEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "item_id": { + "description": "ItemID holds the value of the \"item_id\" field.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "scheduled_date": { + "description": "ScheduledDate holds the value of the \"scheduled_date\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.MaintenanceEntryEdges": { + "type": "object", + "properties": { + "item": { + "description": "Item holds the value of the item edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Item" + } + ] + } + } + }, + "ent.Notifier": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the NotifierQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.NotifierEdges" + } + ] + }, + "group_id": { + "description": "GroupID holds the value of the \"group_id\" field.", + "type": "string" + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "is_active": { + "description": "IsActive holds the value of the \"is_active\" field.", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + }, + "user_id": { + "description": "UserID holds the value of the \"user_id\" field.", + "type": "string" + } + } + }, + "ent.NotifierEdges": { + "type": "object", + "properties": { + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "user": { + "description": "User holds the value of the user edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.User" + } + ] + } + } + }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplate" + } + ] + } + } + }, + "ent.User": { + "type": "object", + "properties": { + "activated_on": { + "description": "ActivatedOn holds the value of the \"activated_on\" field.", + "type": "string" + }, + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the UserQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.UserEdges" + } + ] + }, + "email": { + "description": "Email holds the value of the \"email\" field.", + "type": "string" + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "is_superuser": { + "description": "IsSuperuser holds the value of the \"is_superuser\" field.", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, + "role": { + "description": "Role holds the value of the \"role\" field.", + "allOf": [ + { + "$ref": "#/definitions/user.Role" + } + ] + }, + "superuser": { + "description": "Superuser holds the value of the \"superuser\" field.", + "type": "boolean" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.UserEdges": { + "type": "object", + "properties": { + "auth_tokens": { + "description": "AuthTokens holds the value of the auth_tokens edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.AuthTokens" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "notifiers": { + "description": "Notifiers holds the value of the notifiers edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.Notifier" + } + } + } + }, + "itemfield.Type": { + "type": "string", + "enum": [ + "text", + "number", + "boolean", + "time" + ], + "x-enum-varnames": [ + "TypeText", + "TypeNumber", + "TypeBoolean", + "TypeTime" + ] + }, + "repo.BarcodeProduct": { + "type": "object", + "properties": { + "barcode": { + "type": "string" + }, + "imageBase64": { + "type": "string" + }, + "imageURL": { + "type": "string" + }, + "item": { + "$ref": "#/definitions/repo.ItemCreate" + }, + "manufacturer": { + "type": "string" + }, + "modelNumber": { + "description": "Identifications", + "type": "string" + }, + "notes": { + "description": "Extras", + "type": "string" + }, + "search_engine_name": { + "type": "string" + } + } + }, + "repo.DuplicateOptions": { + "type": "object", + "properties": { + "copyAttachments": { + "type": "boolean" + }, + "copyCustomFields": { + "type": "boolean" + }, + "copyMaintenance": { + "type": "boolean" + }, + "copyPrefix": { + "type": "string" + } + } + }, + "repo.Group": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "currency": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.GroupStatistics": { + "type": "object", + "properties": { + "totalItemPrice": { + "type": "number" + }, + "totalItems": { + "type": "integer" + }, + "totalLabels": { + "type": "integer" + }, + "totalLocations": { + "type": "integer" + }, + "totalUsers": { + "type": "integer" + }, + "totalWithWarranty": { + "type": "integer" + } + } + }, + "repo.GroupUpdate": { + "type": "object", + "properties": { + "currency": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.ItemAttachment": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "id": { + "type": "string" + }, + "mimeType": { + "type": "string" + }, + "path": { + "type": "string" + }, + "primary": { + "type": "boolean" + }, + "thumbnail": { + "$ref": "#/definitions/ent.Attachment" + }, + "title": { + "type": "string" + }, + "type": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemAttachmentUpdate": { + "type": "object", + "properties": { + "primary": { + "type": "boolean" + }, + "title": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.ItemCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "description": "Edges", + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "parentId": { + "type": "string", + "x-nullable": true + }, + "quantity": { + "type": "integer" + } + } + }, + "repo.ItemField": { + "type": "object", + "properties": { + "booleanValue": { + "type": "boolean" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "numberValue": { + "type": "integer" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.ItemOut": { + "type": "object", + "properties": { + "archived": { + "type": "boolean" + }, + "assetId": { + "type": "string", + "example": "0" + }, + "attachments": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemAttachment" + } + }, + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemField" + } + }, + "id": { + "type": "string" + }, + "imageId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "insured": { + "type": "boolean" + }, + "labels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.LabelSummary" + } + }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, + "location": { + "description": "Edges", + "allOf": [ + { + "$ref": "#/definitions/repo.LocationSummary" + } + ], + "x-nullable": true, + "x-omitempty": true + }, + "manufacturer": { + "type": "string" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "notes": { + "description": "Extras", + "type": "string" + }, + "parent": { + "allOf": [ + { + "$ref": "#/definitions/repo.ItemSummary" + } + ], + "x-nullable": true, + "x-omitempty": true + }, + "purchaseFrom": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "purchaseTime": { + "description": "Purchase", + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "serialNumber": { + "type": "string" + }, + "soldNotes": { + "type": "string" + }, + "soldPrice": { + "type": "number" + }, + "soldTime": { + "description": "Sold", + "type": "string" + }, + "soldTo": { + "type": "string" + }, + "syncChildItemsLocations": { + "type": "boolean" + }, + "thumbnailId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "updatedAt": { + "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" + } + } + }, + "repo.ItemPatch": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true, + "x-omitempty": true + }, + "locationId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "quantity": { + "type": "integer", + "x-nullable": true, + "x-omitempty": true + } + } + }, + "repo.ItemPath": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/repo.ItemType" + } + } + }, + "repo.ItemSummary": { + "type": "object", + "properties": { + "archived": { + "type": "boolean" + }, + "assetId": { + "type": "string", + "example": "0" + }, + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "imageId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "insured": { + "type": "boolean" + }, + "labels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.LabelSummary" + } + }, + "location": { + "description": "Edges", + "allOf": [ + { + "$ref": "#/definitions/repo.LocationSummary" + } + ], + "x-nullable": true, + "x-omitempty": true + }, + "name": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "quantity": { + "type": "integer" + }, + "soldTime": { + "description": "Sale details", + "type": "string" + }, + "thumbnailId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000 + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string" + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255 + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255 + }, + "defaultName": { + "type": "string", + "maxLength": 255 + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000 + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/definitions/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000 + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string" + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255 + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255 + }, + "defaultName": { + "type": "string", + "maxLength": 255 + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000 + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemType": { + "type": "string", + "enum": [ + "location", + "item" + ], + "x-enum-varnames": [ + "ItemTypeLocation", + "ItemTypeItem" + ] + }, + "repo.ItemUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "archived": { + "type": "boolean" + }, + "assetId": { + "type": "string" + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemField" + } + }, + "id": { + "type": "string" + }, + "insured": { + "type": "boolean" + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, + "locationId": { + "description": "Edges", + "type": "string" + }, + "manufacturer": { + "type": "string" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "description": "Extras", + "type": "string" + }, + "parentId": { + "type": "string", + "x-nullable": true, + "x-omitempty": true + }, + "purchaseFrom": { + "type": "string", + "maxLength": 255 + }, + "purchasePrice": { + "type": "number", + "x-nullable": true, + "x-omitempty": true + }, + "purchaseTime": { + "description": "Purchase", + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "serialNumber": { + "description": "Identifications", + "type": "string" + }, + "soldNotes": { + "type": "string" + }, + "soldPrice": { + "type": "number", + "x-nullable": true, + "x-omitempty": true + }, + "soldTime": { + "description": "Sold", + "type": "string" + }, + "soldTo": { + "type": "string", + "maxLength": 255 + }, + "syncChildItemsLocations": { + "type": "boolean" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" + } + } + }, + "repo.LabelCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "color": { + "type": "string" + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + } + } + }, + "repo.LabelOut": { + "type": "object", + "properties": { + "color": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.LabelSummary": { + "type": "object", + "properties": { + "color": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.LocationCreate": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "parentId": { + "type": "string", + "x-nullable": true + } + } + }, + "repo.LocationOut": { + "type": "object", + "properties": { + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.LocationSummary" + } + }, + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "parent": { + "$ref": "#/definitions/repo.LocationSummary" + }, + "totalPrice": { + "type": "number" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.LocationOutCount": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "itemCount": { + "type": "integer" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.LocationSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.LocationUpdate": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "parentId": { + "type": "string", + "x-nullable": true + } + } + }, + "repo.MaintenanceEntry": { + "type": "object", + "properties": { + "completedDate": { + "type": "string" + }, + "cost": { + "type": "string", + "example": "0" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "scheduledDate": { + "type": "string" + } + } + }, + "repo.MaintenanceEntryCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "completedDate": { + "type": "string" + }, + "cost": { + "type": "string", + "example": "0" + }, + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "scheduledDate": { + "type": "string" + } + } + }, + "repo.MaintenanceEntryUpdate": { + "type": "object", + "properties": { + "completedDate": { + "type": "string" + }, + "cost": { + "type": "string", + "example": "0" + }, + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "scheduledDate": { + "type": "string" + } + } + }, + "repo.MaintenanceEntryWithDetails": { + "type": "object", + "properties": { + "completedDate": { + "type": "string" + }, + "cost": { + "type": "string", + "example": "0" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "itemID": { + "type": "string" + }, + "itemName": { + "type": "string" + }, + "name": { + "type": "string" + }, + "scheduledDate": { + "type": "string" + } + } + }, + "repo.MaintenanceFilterStatus": { + "type": "string", + "enum": [ + "scheduled", + "completed", + "both" + ], + "x-enum-varnames": [ + "MaintenanceFilterStatusScheduled", + "MaintenanceFilterStatusCompleted", + "MaintenanceFilterStatusBoth" + ] + }, + "repo.NotifierCreate": { + "type": "object", + "required": [ + "name", + "url" + ], + "properties": { + "isActive": { + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "url": { + "type": "string" + } + } + }, + "repo.NotifierOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "groupId": { + "type": "string" + }, + "id": { + "type": "string" + }, + "isActive": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + }, + "url": { + "type": "string" + }, + "userId": { + "type": "string" + } + } + }, + "repo.NotifierUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "isActive": { + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "url": { + "type": "string", + "x-nullable": true + } + } + }, + "repo.PaginationResult-repo_ItemSummary": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemSummary" + } + }, + "page": { + "type": "integer" + }, + "pageSize": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TotalsByOrganizer": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "total": { + "type": "number" + } + } + }, + "repo.TreeItem": { + "type": "object", + "properties": { + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TreeItem" + } + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.UserOut": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "groupId": { + "type": "string" + }, + "groupName": { + "type": "string" + }, + "id": { + "type": "string" + }, + "isOwner": { + "type": "boolean" + }, + "isSuperuser": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" + } + } + }, + "repo.UserUpdate": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.ValueOverTime": { + "type": "object", + "properties": { + "end": { + "type": "string" + }, + "entries": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ValueOverTimeEntry" + } + }, + "start": { + "type": "string" + }, + "valueAtEnd": { + "type": "number" + }, + "valueAtStart": { + "type": "number" + } + } + }, + "repo.ValueOverTimeEntry": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "name": { + "type": "string" + }, + "value": { + "type": "number" + } + } + }, + "services.Latest": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "version": { + "type": "string" + } + } + }, + "services.UserRegistration": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "name": { + "type": "string" + }, + "password": { + "type": "string" + }, + "token": { + "type": "string" + } + } + }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, + "user.Role": { + "type": "string", + "enum": [ + "user", + "user", + "owner" + ], + "x-enum-varnames": [ + "DefaultRole", + "RoleUser", + "RoleOwner" + ] + }, + "v1.APISummary": { + "type": "object", + "properties": { + "allowRegistration": { + "type": "boolean" + }, + "build": { + "$ref": "#/definitions/v1.Build" + }, + "demo": { + "type": "boolean" + }, + "health": { + "type": "boolean" + }, + "labelPrinting": { + "type": "boolean" + }, + "latest": { + "$ref": "#/definitions/services.Latest" + }, + "message": { + "type": "string" + }, + "oidc": { + "$ref": "#/definitions/v1.OIDCStatus" + }, + "title": { + "type": "string" + }, + "versions": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "v1.ActionAmountResult": { + "type": "object", + "properties": { + "completed": { + "type": "integer" + } + } + }, + "v1.Build": { + "type": "object", + "properties": { + "buildTime": { + "type": "string" + }, + "commit": { + "type": "string" + }, + "version": { + "type": "string" + } + } + }, + "v1.ChangePassword": { + "type": "object", + "properties": { + "current": { + "type": "string" + }, + "new": { + "type": "string" + } + } + }, + "v1.GroupInvitation": { + "type": "object", + "properties": { + "expiresAt": { + "type": "string" + }, + "token": { + "type": "string" + }, + "uses": { + "type": "integer" + } + } + }, + "v1.GroupInvitationCreate": { + "type": "object", + "required": [ + "uses" + ], + "properties": { + "expiresAt": { + "type": "string" + }, + "uses": { + "type": "integer", + "maximum": 100, + "minimum": 1 + } + } + }, + "v1.ItemAttachmentToken": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, + "v1.LoginForm": { + "type": "object", + "properties": { + "password": { + "type": "string", + "example": "admin" + }, + "stayLoggedIn": { + "type": "boolean" + }, + "username": { + "type": "string", + "example": "admin@admin.com" + } + } + }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, + "v1.TokenResponse": { + "type": "object", + "properties": { + "attachmentToken": { + "type": "string" + }, + "expiresAt": { + "type": "string" + }, + "token": { + "type": "string" + } + } + }, + "v1.Wrapped": { + "type": "object", + "properties": { + "item": {} + } + }, + "validate.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "type": "string" + }, + "fields": { + "type": "string" + } + } + } + }, + "securityDefinitions": { + "Bearer": { + "description": "\"Type 'Bearer TOKEN' to correctly set the API Key\"", + "type": "apiKey", + "name": "Authorization", + "in": "header" + } + } +} \ No newline at end of file diff --git a/docs/en/api/openapi-2.0.yaml b/docs/en/api/openapi-2.0.yaml new file mode 100644 index 00000000..8926c617 --- /dev/null +++ b/docs/en/api/openapi-2.0.yaml @@ -0,0 +1,3369 @@ +basePath: /api +definitions: + attachment.Type: + enum: + - attachment + - photo + - manual + - warranty + - attachment + - receipt + - thumbnail + type: string + x-enum-varnames: + - DefaultType + - TypePhoto + - TypeManual + - TypeWarranty + - TypeAttachment + - TypeReceipt + - TypeThumbnail + authroles.Role: + enum: + - user + - admin + - user + - attachments + type: string + x-enum-varnames: + - DefaultRole + - RoleAdmin + - RoleUser + - RoleAttachments + currencies.Currency: + properties: + code: + type: string + decimals: + type: integer + local: + type: string + name: + type: string + symbol: + type: string + type: object + ent.Attachment: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.AttachmentEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the AttachmentQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + mime_type: + description: MimeType holds the value of the "mime_type" field. + type: string + path: + description: Path holds the value of the "path" field. + type: string + primary: + description: Primary holds the value of the "primary" field. + type: boolean + title: + description: Title holds the value of the "title" field. + type: string + type: + allOf: + - $ref: '#/definitions/attachment.Type' + description: Type holds the value of the "type" field. + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.AttachmentEdges: + properties: + item: + allOf: + - $ref: '#/definitions/ent.Item' + description: Item holds the value of the item edge. + thumbnail: + allOf: + - $ref: '#/definitions/ent.Attachment' + description: Thumbnail holds the value of the thumbnail edge. + type: object + ent.AuthRoles: + properties: + edges: + allOf: + - $ref: '#/definitions/ent.AuthRolesEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the AuthRolesQuery when eager-loading is set. + id: + description: ID of the ent. + type: integer + role: + allOf: + - $ref: '#/definitions/authroles.Role' + description: Role holds the value of the "role" field. + type: object + ent.AuthRolesEdges: + properties: + token: + allOf: + - $ref: '#/definitions/ent.AuthTokens' + description: Token holds the value of the token edge. + type: object + ent.AuthTokens: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.AuthTokensEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the AuthTokensQuery when eager-loading is set. + expires_at: + description: ExpiresAt holds the value of the "expires_at" field. + type: string + id: + description: ID of the ent. + type: string + token: + description: Token holds the value of the "token" field. + items: + type: integer + type: array + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.AuthTokensEdges: + properties: + roles: + allOf: + - $ref: '#/definitions/ent.AuthRoles' + description: Roles holds the value of the roles edge. + user: + allOf: + - $ref: '#/definitions/ent.User' + description: User holds the value of the user edge. + type: object + ent.Group: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + currency: + description: Currency holds the value of the "currency" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.GroupEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the GroupQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.GroupEdges: + properties: + invitation_tokens: + description: InvitationTokens holds the value of the invitation_tokens edge. + items: + $ref: '#/definitions/ent.GroupInvitationToken' + type: array + item_templates: + description: ItemTemplates holds the value of the item_templates edge. + items: + $ref: '#/definitions/ent.ItemTemplate' + type: array + items: + description: Items holds the value of the items edge. + items: + $ref: '#/definitions/ent.Item' + type: array + labels: + description: Labels holds the value of the labels edge. + items: + $ref: '#/definitions/ent.Label' + type: array + locations: + description: Locations holds the value of the locations edge. + items: + $ref: '#/definitions/ent.Location' + type: array + notifiers: + description: Notifiers holds the value of the notifiers edge. + items: + $ref: '#/definitions/ent.Notifier' + type: array + users: + description: Users holds the value of the users edge. + items: + $ref: '#/definitions/ent.User' + type: array + type: object + ent.GroupInvitationToken: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.GroupInvitationTokenEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the GroupInvitationTokenQuery when eager-loading is set. + expires_at: + description: ExpiresAt holds the value of the "expires_at" field. + type: string + id: + description: ID of the ent. + type: string + token: + description: Token holds the value of the "token" field. + items: + type: integer + type: array + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + uses: + description: Uses holds the value of the "uses" field. + type: integer + type: object + ent.GroupInvitationTokenEdges: + properties: + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + type: object + ent.Item: + properties: + archived: + description: Archived holds the value of the "archived" field. + type: boolean + asset_id: + description: AssetID holds the value of the "asset_id" field. + type: integer + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ItemEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ItemQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + import_ref: + description: ImportRef holds the value of the "import_ref" field. + type: string + insured: + description: Insured holds the value of the "insured" field. + type: boolean + lifetime_warranty: + description: LifetimeWarranty holds the value of the "lifetime_warranty" field. + type: boolean + manufacturer: + description: Manufacturer holds the value of the "manufacturer" field. + type: string + model_number: + description: ModelNumber holds the value of the "model_number" field. + type: string + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + purchase_from: + description: PurchaseFrom holds the value of the "purchase_from" field. + type: string + purchase_price: + description: PurchasePrice holds the value of the "purchase_price" field. + type: number + purchase_time: + description: PurchaseTime holds the value of the "purchase_time" field. + type: string + quantity: + description: Quantity holds the value of the "quantity" field. + type: integer + serial_number: + description: SerialNumber holds the value of the "serial_number" field. + type: string + sold_notes: + description: SoldNotes holds the value of the "sold_notes" field. + type: string + sold_price: + description: SoldPrice holds the value of the "sold_price" field. + type: number + sold_time: + description: SoldTime holds the value of the "sold_time" field. + type: string + sold_to: + description: SoldTo holds the value of the "sold_to" field. + type: string + sync_child_items_locations: + description: SyncChildItemsLocations holds the value of the "sync_child_items_locations" + field. + type: boolean + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + warranty_details: + description: WarrantyDetails holds the value of the "warranty_details" field. + type: string + warranty_expires: + description: WarrantyExpires holds the value of the "warranty_expires" field. + type: string + type: object + ent.ItemEdges: + properties: + attachments: + description: Attachments holds the value of the attachments edge. + items: + $ref: '#/definitions/ent.Attachment' + type: array + children: + description: Children holds the value of the children edge. + items: + $ref: '#/definitions/ent.Item' + type: array + fields: + description: Fields holds the value of the fields edge. + items: + $ref: '#/definitions/ent.ItemField' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + label: + description: Label holds the value of the label edge. + items: + $ref: '#/definitions/ent.Label' + type: array + location: + allOf: + - $ref: '#/definitions/ent.Location' + description: Location holds the value of the location edge. + maintenance_entries: + description: MaintenanceEntries holds the value of the maintenance_entries + edge. + items: + $ref: '#/definitions/ent.MaintenanceEntry' + type: array + parent: + allOf: + - $ref: '#/definitions/ent.Item' + description: Parent holds the value of the parent edge. + type: object + ent.ItemField: + properties: + boolean_value: + description: BooleanValue holds the value of the "boolean_value" field. + type: boolean + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ItemFieldEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ItemFieldQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + number_value: + description: NumberValue holds the value of the "number_value" field. + type: integer + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + time_value: + description: TimeValue holds the value of the "time_value" field. + type: string + type: + allOf: + - $ref: '#/definitions/itemfield.Type' + description: Type holds the value of the "type" field. + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.ItemFieldEdges: + properties: + item: + allOf: + - $ref: '#/definitions/ent.Item' + description: Item holds the value of the item edge. + type: object + ent.ItemTemplate: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + default_description: + description: Default description for items created from this template + type: string + default_insured: + description: DefaultInsured holds the value of the "default_insured" field. + type: boolean + default_label_ids: + description: Default label IDs for items created from this template + items: + type: string + type: array + default_lifetime_warranty: + description: DefaultLifetimeWarranty holds the value of the "default_lifetime_warranty" + field. + type: boolean + default_manufacturer: + description: DefaultManufacturer holds the value of the "default_manufacturer" + field. + type: string + default_model_number: + description: Default model number for items created from this template + type: string + default_name: + description: Default name template for items (can use placeholders) + type: string + default_quantity: + description: DefaultQuantity holds the value of the "default_quantity" field. + type: integer + default_warranty_details: + description: DefaultWarrantyDetails holds the value of the "default_warranty_details" + field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ItemTemplateEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ItemTemplateQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + include_purchase_fields: + description: Whether to include purchase fields in items created from this + template + type: boolean + include_sold_fields: + description: Whether to include sold fields in items created from this template + type: boolean + include_warranty_fields: + description: Whether to include warranty fields in items created from this + template + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.ItemTemplateEdges: + properties: + fields: + description: Fields holds the value of the fields edge. + items: + $ref: '#/definitions/ent.TemplateField' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + location: + allOf: + - $ref: '#/definitions/ent.Location' + description: Location holds the value of the location edge. + type: object + ent.Label: + properties: + color: + description: Color holds the value of the "color" field. + type: string + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.LabelEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the LabelQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.LabelEdges: + properties: + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + items: + description: Items holds the value of the items edge. + items: + $ref: '#/definitions/ent.Item' + type: array + type: object + ent.Location: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.LocationEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the LocationQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.LocationEdges: + properties: + children: + description: Children holds the value of the children edge. + items: + $ref: '#/definitions/ent.Location' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + items: + description: Items holds the value of the items edge. + items: + $ref: '#/definitions/ent.Item' + type: array + parent: + allOf: + - $ref: '#/definitions/ent.Location' + description: Parent holds the value of the parent edge. + type: object + ent.MaintenanceEntry: + properties: + cost: + description: Cost holds the value of the "cost" field. + type: number + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + date: + description: Date holds the value of the "date" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.MaintenanceEntryEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the MaintenanceEntryQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + item_id: + description: ItemID holds the value of the "item_id" field. + type: string + name: + description: Name holds the value of the "name" field. + type: string + scheduled_date: + description: ScheduledDate holds the value of the "scheduled_date" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.MaintenanceEntryEdges: + properties: + item: + allOf: + - $ref: '#/definitions/ent.Item' + description: Item holds the value of the item edge. + type: object + ent.Notifier: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.NotifierEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the NotifierQuery when eager-loading is set. + group_id: + description: GroupID holds the value of the "group_id" field. + type: string + id: + description: ID of the ent. + type: string + is_active: + description: IsActive holds the value of the "is_active" field. + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + user_id: + description: UserID holds the value of the "user_id" field. + type: string + type: object + ent.NotifierEdges: + properties: + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + user: + allOf: + - $ref: '#/definitions/ent.User' + description: User holds the value of the user edge. + type: object + ent.TemplateField: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.TemplateFieldEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the TemplateFieldQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + type: + allOf: + - $ref: '#/definitions/templatefield.Type' + description: Type holds the value of the "type" field. + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.TemplateFieldEdges: + properties: + item_template: + allOf: + - $ref: '#/definitions/ent.ItemTemplate' + description: ItemTemplate holds the value of the item_template edge. + type: object + ent.User: + properties: + activated_on: + description: ActivatedOn holds the value of the "activated_on" field. + type: string + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.UserEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the UserQuery when eager-loading is set. + email: + description: Email holds the value of the "email" field. + type: string + id: + description: ID of the ent. + type: string + is_superuser: + description: IsSuperuser holds the value of the "is_superuser" field. + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + oidc_issuer: + description: OidcIssuer holds the value of the "oidc_issuer" field. + type: string + oidc_subject: + description: OidcSubject holds the value of the "oidc_subject" field. + type: string + role: + allOf: + - $ref: '#/definitions/user.Role' + description: Role holds the value of the "role" field. + superuser: + description: Superuser holds the value of the "superuser" field. + type: boolean + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.UserEdges: + properties: + auth_tokens: + description: AuthTokens holds the value of the auth_tokens edge. + items: + $ref: '#/definitions/ent.AuthTokens' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + notifiers: + description: Notifiers holds the value of the notifiers edge. + items: + $ref: '#/definitions/ent.Notifier' + type: array + type: object + itemfield.Type: + enum: + - text + - number + - boolean + - time + type: string + x-enum-varnames: + - TypeText + - TypeNumber + - TypeBoolean + - TypeTime + repo.BarcodeProduct: + properties: + barcode: + type: string + imageBase64: + type: string + imageURL: + type: string + item: + $ref: '#/definitions/repo.ItemCreate' + manufacturer: + type: string + modelNumber: + description: Identifications + type: string + notes: + description: Extras + type: string + search_engine_name: + type: string + type: object + repo.DuplicateOptions: + properties: + copyAttachments: + type: boolean + copyCustomFields: + type: boolean + copyMaintenance: + type: boolean + copyPrefix: + type: string + type: object + repo.Group: + properties: + createdAt: + type: string + currency: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.GroupStatistics: + properties: + totalItemPrice: + type: number + totalItems: + type: integer + totalLabels: + type: integer + totalLocations: + type: integer + totalUsers: + type: integer + totalWithWarranty: + type: integer + type: object + repo.GroupUpdate: + properties: + currency: + type: string + name: + type: string + type: object + repo.ItemAttachment: + properties: + createdAt: + type: string + id: + type: string + mimeType: + type: string + path: + type: string + primary: + type: boolean + thumbnail: + $ref: '#/definitions/ent.Attachment' + title: + type: string + type: + type: string + updatedAt: + type: string + type: object + repo.ItemAttachmentUpdate: + properties: + primary: + type: boolean + title: + type: string + type: + type: string + type: object + repo.ItemCreate: + properties: + description: + maxLength: 1000 + type: string + labelIds: + items: + type: string + type: array + locationId: + description: Edges + type: string + name: + maxLength: 255 + minLength: 1 + type: string + parentId: + type: string + x-nullable: true + quantity: + type: integer + required: + - name + type: object + repo.ItemField: + properties: + booleanValue: + type: boolean + id: + type: string + name: + type: string + numberValue: + type: integer + textValue: + type: string + type: + type: string + type: object + repo.ItemOut: + properties: + archived: + type: boolean + assetId: + example: "0" + type: string + attachments: + items: + $ref: '#/definitions/repo.ItemAttachment' + type: array + createdAt: + type: string + description: + type: string + fields: + items: + $ref: '#/definitions/repo.ItemField' + type: array + id: + type: string + imageId: + type: string + x-nullable: true + x-omitempty: true + insured: + type: boolean + labels: + items: + $ref: '#/definitions/repo.LabelSummary' + type: array + lifetimeWarranty: + description: Warranty + type: boolean + location: + allOf: + - $ref: '#/definitions/repo.LocationSummary' + description: Edges + x-nullable: true + x-omitempty: true + manufacturer: + type: string + modelNumber: + type: string + name: + type: string + notes: + description: Extras + type: string + parent: + allOf: + - $ref: '#/definitions/repo.ItemSummary' + x-nullable: true + x-omitempty: true + purchaseFrom: + type: string + purchasePrice: + type: number + purchaseTime: + description: Purchase + type: string + quantity: + type: integer + serialNumber: + type: string + soldNotes: + type: string + soldPrice: + type: number + soldTime: + description: Sold + type: string + soldTo: + type: string + syncChildItemsLocations: + type: boolean + thumbnailId: + type: string + x-nullable: true + x-omitempty: true + updatedAt: + type: string + warrantyDetails: + type: string + warrantyExpires: + type: string + type: object + repo.ItemPatch: + properties: + id: + type: string + labelIds: + items: + type: string + type: array + x-nullable: true + x-omitempty: true + locationId: + type: string + x-nullable: true + x-omitempty: true + quantity: + type: integer + x-nullable: true + x-omitempty: true + type: object + repo.ItemPath: + properties: + id: + type: string + name: + type: string + type: + $ref: '#/definitions/repo.ItemType' + type: object + repo.ItemSummary: + properties: + archived: + type: boolean + assetId: + example: "0" + type: string + createdAt: + type: string + description: + type: string + id: + type: string + imageId: + type: string + x-nullable: true + x-omitempty: true + insured: + type: boolean + labels: + items: + $ref: '#/definitions/repo.LabelSummary' + type: array + location: + allOf: + - $ref: '#/definitions/repo.LocationSummary' + description: Edges + x-nullable: true + x-omitempty: true + name: + type: string + purchasePrice: + type: number + quantity: + type: integer + soldTime: + description: Sale details + type: string + thumbnailId: + type: string + x-nullable: true + x-omitempty: true + updatedAt: + type: string + type: object + repo.ItemTemplateCreate: + properties: + defaultDescription: + maxLength: 1000 + type: string + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + defaultManufacturer: + maxLength: 255 + type: string + defaultModelNumber: + maxLength: 255 + type: string + defaultName: + maxLength: 255 + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + maxLength: 1000 + type: string + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object + repo.ItemTemplateOut: + properties: + createdAt: + type: string + defaultDescription: + type: string + defaultInsured: + type: boolean + defaultLabels: + items: + $ref: '#/definitions/repo.TemplateLabelSummary' + type: array + defaultLifetimeWarranty: + type: boolean + defaultLocation: + allOf: + - $ref: '#/definitions/repo.TemplateLocationSummary' + description: Default location and labels + defaultManufacturer: + type: string + defaultModelNumber: + type: string + defaultName: + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + type: string + description: + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + notes: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateSummary: + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateUpdate: + properties: + defaultDescription: + maxLength: 1000 + type: string + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + defaultManufacturer: + maxLength: 255 + type: string + defaultModelNumber: + maxLength: 255 + type: string + defaultName: + maxLength: 255 + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + maxLength: 1000 + type: string + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object + repo.ItemType: + enum: + - location + - item + type: string + x-enum-varnames: + - ItemTypeLocation + - ItemTypeItem + repo.ItemUpdate: + properties: + archived: + type: boolean + assetId: + type: string + description: + maxLength: 1000 + type: string + fields: + items: + $ref: '#/definitions/repo.ItemField' + type: array + id: + type: string + insured: + type: boolean + labelIds: + items: + type: string + type: array + lifetimeWarranty: + description: Warranty + type: boolean + locationId: + description: Edges + type: string + manufacturer: + type: string + modelNumber: + type: string + name: + maxLength: 255 + minLength: 1 + type: string + notes: + description: Extras + type: string + parentId: + type: string + x-nullable: true + x-omitempty: true + purchaseFrom: + maxLength: 255 + type: string + purchasePrice: + type: number + x-nullable: true + x-omitempty: true + purchaseTime: + description: Purchase + type: string + quantity: + type: integer + serialNumber: + description: Identifications + type: string + soldNotes: + type: string + soldPrice: + type: number + x-nullable: true + x-omitempty: true + soldTime: + description: Sold + type: string + soldTo: + maxLength: 255 + type: string + syncChildItemsLocations: + type: boolean + warrantyDetails: + type: string + warrantyExpires: + type: string + required: + - name + type: object + repo.LabelCreate: + properties: + color: + type: string + description: + maxLength: 1000 + type: string + name: + maxLength: 255 + minLength: 1 + type: string + required: + - name + type: object + repo.LabelOut: + properties: + color: + type: string + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.LabelSummary: + properties: + color: + type: string + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.LocationCreate: + properties: + description: + type: string + name: + type: string + parentId: + type: string + x-nullable: true + type: object + repo.LocationOut: + properties: + children: + items: + $ref: '#/definitions/repo.LocationSummary' + type: array + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + parent: + $ref: '#/definitions/repo.LocationSummary' + totalPrice: + type: number + updatedAt: + type: string + type: object + repo.LocationOutCount: + properties: + createdAt: + type: string + description: + type: string + id: + type: string + itemCount: + type: integer + name: + type: string + updatedAt: + type: string + type: object + repo.LocationSummary: + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.LocationUpdate: + properties: + description: + type: string + id: + type: string + name: + type: string + parentId: + type: string + x-nullable: true + type: object + repo.MaintenanceEntry: + properties: + completedDate: + type: string + cost: + example: "0" + type: string + description: + type: string + id: + type: string + name: + type: string + scheduledDate: + type: string + type: object + repo.MaintenanceEntryCreate: + properties: + completedDate: + type: string + cost: + example: "0" + type: string + description: + type: string + name: + type: string + scheduledDate: + type: string + required: + - name + type: object + repo.MaintenanceEntryUpdate: + properties: + completedDate: + type: string + cost: + example: "0" + type: string + description: + type: string + name: + type: string + scheduledDate: + type: string + type: object + repo.MaintenanceEntryWithDetails: + properties: + completedDate: + type: string + cost: + example: "0" + type: string + description: + type: string + id: + type: string + itemID: + type: string + itemName: + type: string + name: + type: string + scheduledDate: + type: string + type: object + repo.MaintenanceFilterStatus: + enum: + - scheduled + - completed + - both + type: string + x-enum-varnames: + - MaintenanceFilterStatusScheduled + - MaintenanceFilterStatusCompleted + - MaintenanceFilterStatusBoth + repo.NotifierCreate: + properties: + isActive: + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + url: + type: string + required: + - name + - url + type: object + repo.NotifierOut: + properties: + createdAt: + type: string + groupId: + type: string + id: + type: string + isActive: + type: boolean + name: + type: string + updatedAt: + type: string + url: + type: string + userId: + type: string + type: object + repo.NotifierUpdate: + properties: + isActive: + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + url: + type: string + x-nullable: true + required: + - name + type: object + repo.PaginationResult-repo_ItemSummary: + properties: + items: + items: + $ref: '#/definitions/repo.ItemSummary' + type: array + page: + type: integer + pageSize: + type: integer + total: + type: integer + type: object + repo.TemplateField: + properties: + id: + type: string + name: + type: string + textValue: + type: string + type: + type: string + type: object + repo.TemplateLabelSummary: + properties: + id: + type: string + name: + type: string + type: object + repo.TemplateLocationSummary: + properties: + id: + type: string + name: + type: string + type: object + repo.TotalsByOrganizer: + properties: + id: + type: string + name: + type: string + total: + type: number + type: object + repo.TreeItem: + properties: + children: + items: + $ref: '#/definitions/repo.TreeItem' + type: array + id: + type: string + name: + type: string + type: + type: string + type: object + repo.UserOut: + properties: + email: + type: string + groupId: + type: string + groupName: + type: string + id: + type: string + isOwner: + type: boolean + isSuperuser: + type: boolean + name: + type: string + oidcIssuer: + type: string + oidcSubject: + type: string + type: object + repo.UserUpdate: + properties: + email: + type: string + name: + type: string + type: object + repo.ValueOverTime: + properties: + end: + type: string + entries: + items: + $ref: '#/definitions/repo.ValueOverTimeEntry' + type: array + start: + type: string + valueAtEnd: + type: number + valueAtStart: + type: number + type: object + repo.ValueOverTimeEntry: + properties: + date: + type: string + name: + type: string + value: + type: number + type: object + services.Latest: + properties: + date: + type: string + version: + type: string + type: object + services.UserRegistration: + properties: + email: + type: string + name: + type: string + password: + type: string + token: + type: string + type: object + templatefield.Type: + enum: + - text + type: string + x-enum-varnames: + - TypeText + user.Role: + enum: + - user + - user + - owner + type: string + x-enum-varnames: + - DefaultRole + - RoleUser + - RoleOwner + v1.APISummary: + properties: + allowRegistration: + type: boolean + build: + $ref: '#/definitions/v1.Build' + demo: + type: boolean + health: + type: boolean + labelPrinting: + type: boolean + latest: + $ref: '#/definitions/services.Latest' + message: + type: string + oidc: + $ref: '#/definitions/v1.OIDCStatus' + title: + type: string + versions: + items: + type: string + type: array + type: object + v1.ActionAmountResult: + properties: + completed: + type: integer + type: object + v1.Build: + properties: + buildTime: + type: string + commit: + type: string + version: + type: string + type: object + v1.ChangePassword: + properties: + current: + type: string + new: + type: string + type: object + v1.GroupInvitation: + properties: + expiresAt: + type: string + token: + type: string + uses: + type: integer + type: object + v1.GroupInvitationCreate: + properties: + expiresAt: + type: string + uses: + maximum: 100 + minimum: 1 + type: integer + required: + - uses + type: object + v1.ItemAttachmentToken: + properties: + token: + type: string + type: object + v1.ItemTemplateCreateItemRequest: + properties: + description: + maxLength: 1000 + type: string + labelIds: + items: + type: string + type: array + locationId: + type: string + name: + maxLength: 255 + minLength: 1 + type: string + quantity: + type: integer + required: + - locationId + - name + type: object + v1.LoginForm: + properties: + password: + example: admin + type: string + stayLoggedIn: + type: boolean + username: + example: admin@admin.com + type: string + type: object + v1.OIDCStatus: + properties: + allowLocal: + type: boolean + autoRedirect: + type: boolean + buttonText: + type: string + enabled: + type: boolean + type: object + v1.TokenResponse: + properties: + attachmentToken: + type: string + expiresAt: + type: string + token: + type: string + type: object + v1.Wrapped: + properties: + item: {} + type: object + validate.ErrorResponse: + properties: + error: + type: string + fields: + type: string + type: object +host: demo.homebox.software +info: + contact: + name: Homebox Team + url: https://discord.homebox.software + description: Track, Manage, and Organize your Things. + title: Homebox API + version: "1.0" +paths: + /v1/actions/create-missing-thumbnails: + post: + description: Creates thumbnails for items that are missing them + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ActionAmountResult' + security: + - Bearer: [] + summary: Create Missing Thumbnails + tags: + - Actions + /v1/actions/ensure-asset-ids: + post: + description: Ensures all items in the database have an asset ID + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ActionAmountResult' + security: + - Bearer: [] + summary: Ensure Asset IDs + tags: + - Actions + /v1/actions/ensure-import-refs: + post: + description: Ensures all items in the database have an import ref + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ActionAmountResult' + security: + - Bearer: [] + summary: Ensures Import Refs + tags: + - Actions + /v1/actions/set-primary-photos: + post: + description: Sets the first photo of each item as the primary photo + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ActionAmountResult' + security: + - Bearer: [] + summary: Set Primary Photos + tags: + - Actions + /v1/actions/zero-item-time-fields: + post: + description: Resets all item date fields to the beginning of the day + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ActionAmountResult' + security: + - Bearer: [] + summary: Zero Out Time Fields + tags: + - Actions + /v1/assets/{id}: + get: + parameters: + - description: Asset ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.PaginationResult-repo_ItemSummary' + security: + - Bearer: [] + summary: Get Item by Asset ID + tags: + - Items + /v1/currency: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/currencies.Currency' + summary: Currency + tags: + - Base + /v1/groups: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.Group' + security: + - Bearer: [] + summary: Get Group + tags: + - Group + put: + parameters: + - description: User Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.GroupUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.Group' + security: + - Bearer: [] + summary: Update Group + tags: + - Group + /v1/groups/invitations: + post: + parameters: + - description: User Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.GroupInvitationCreate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GroupInvitation' + security: + - Bearer: [] + summary: Create Group Invitation + tags: + - Group + /v1/groups/statistics: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.GroupStatistics' + security: + - Bearer: [] + summary: Get Group Statistics + tags: + - Statistics + /v1/groups/statistics/labels: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.TotalsByOrganizer' + type: array + security: + - Bearer: [] + summary: Get Label Statistics + tags: + - Statistics + /v1/groups/statistics/locations: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.TotalsByOrganizer' + type: array + security: + - Bearer: [] + summary: Get Location Statistics + tags: + - Statistics + /v1/groups/statistics/purchase-price: + get: + parameters: + - description: start date + in: query + name: start + type: string + - description: end date + in: query + name: end + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ValueOverTime' + security: + - Bearer: [] + summary: Get Purchase Price Statistics + tags: + - Statistics + /v1/items: + get: + parameters: + - description: search string + in: query + name: q + type: string + - description: page number + in: query + name: page + type: integer + - description: items per page + in: query + name: pageSize + type: integer + - collectionFormat: multi + description: label Ids + in: query + items: + type: string + name: labels + type: array + - collectionFormat: multi + description: location Ids + in: query + items: + type: string + name: locations + type: array + - collectionFormat: multi + description: parent Ids + in: query + items: + type: string + name: parentIds + type: array + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.PaginationResult-repo_ItemSummary' + security: + - Bearer: [] + summary: Query All Items + tags: + - Items + post: + parameters: + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemCreate' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemSummary' + security: + - Bearer: [] + summary: Create Item + tags: + - Items + /v1/items/{id}: + delete: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Item + tags: + - Items + get: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Get Item + tags: + - Items + patch: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemPatch' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Update Item + tags: + - Items + put: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Update Item + tags: + - Items + /v1/items/{id}/attachments: + post: + consumes: + - multipart/form-data + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: File attachment + in: formData + name: file + required: true + type: file + - description: Type of file + in: formData + name: type + type: string + - description: Is this the primary attachment + in: formData + name: primary + type: boolean + - description: name of the file including extension + in: formData + name: name + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + "422": + description: Unprocessable Entity + schema: + $ref: '#/definitions/validate.ErrorResponse' + security: + - Bearer: [] + summary: Create Item Attachment + tags: + - Items Attachments + /v1/items/{id}/attachments/{attachment_id}: + delete: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Attachment ID + in: path + name: attachment_id + required: true + type: string + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Item Attachment + tags: + - Items Attachments + get: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Attachment ID + in: path + name: attachment_id + required: true + type: string + produces: + - application/octet-stream + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.ItemAttachmentToken' + security: + - Bearer: [] + summary: Get Item Attachment + tags: + - Items Attachments + put: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Attachment ID + in: path + name: attachment_id + required: true + type: string + - description: Attachment Update + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemAttachmentUpdate' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Update Item Attachment + tags: + - Items Attachments + /v1/items/{id}/duplicate: + post: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Duplicate Options + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.DuplicateOptions' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Duplicate Item + tags: + - Items + /v1/items/{id}/maintenance: + get: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - enum: + - scheduled + - completed + - both + in: query + name: status + type: string + x-enum-varnames: + - MaintenanceFilterStatusScheduled + - MaintenanceFilterStatusCompleted + - MaintenanceFilterStatusBoth + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.MaintenanceEntryWithDetails' + type: array + security: + - Bearer: [] + summary: Get Maintenance Log + tags: + - Item Maintenance + post: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Entry Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.MaintenanceEntryCreate' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.MaintenanceEntry' + security: + - Bearer: [] + summary: Create Maintenance Entry + tags: + - Item Maintenance + /v1/items/{id}/path: + get: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.ItemPath' + type: array + security: + - Bearer: [] + summary: Get the full path of an item + tags: + - Items + /v1/items/export: + get: + responses: + "200": + description: text/csv + schema: + type: string + security: + - Bearer: [] + summary: Export Items + tags: + - Items + /v1/items/fields: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + type: string + type: array + security: + - Bearer: [] + summary: Get All Custom Field Names + tags: + - Items + /v1/items/fields/values: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + type: string + type: array + security: + - Bearer: [] + summary: Get All Custom Field Values + tags: + - Items + /v1/items/import: + post: + consumes: + - multipart/form-data + parameters: + - description: Image to upload + in: formData + name: csv + required: true + type: file + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Import Items + tags: + - Items + /v1/labelmaker/assets/{id}: + get: + parameters: + - description: Asset ID + in: path + name: id + required: true + type: string + - description: Print this label, defaults to false + in: query + name: print + type: boolean + produces: + - application/json + responses: + "200": + description: image/png + schema: + type: string + security: + - Bearer: [] + summary: Get Asset label + tags: + - Items + /v1/labelmaker/item/{id}: + get: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Print this label, defaults to false + in: query + name: print + type: boolean + produces: + - application/json + responses: + "200": + description: image/png + schema: + type: string + security: + - Bearer: [] + summary: Get Item label + tags: + - Items + /v1/labelmaker/location/{id}: + get: + parameters: + - description: Location ID + in: path + name: id + required: true + type: string + - description: Print this label, defaults to false + in: query + name: print + type: boolean + produces: + - application/json + responses: + "200": + description: image/png + schema: + type: string + security: + - Bearer: [] + summary: Get Location label + tags: + - Locations + /v1/labels: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.LabelOut' + type: array + security: + - Bearer: [] + summary: Get All Labels + tags: + - Labels + post: + parameters: + - description: Label Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.LabelCreate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LabelSummary' + security: + - Bearer: [] + summary: Create Label + tags: + - Labels + /v1/labels/{id}: + delete: + parameters: + - description: Label ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Label + tags: + - Labels + get: + parameters: + - description: Label ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LabelOut' + security: + - Bearer: [] + summary: Get Label + tags: + - Labels + put: + parameters: + - description: Label ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LabelOut' + security: + - Bearer: [] + summary: Update Label + tags: + - Labels + /v1/locations: + get: + parameters: + - description: Filter locations with parents + in: query + name: filterChildren + type: boolean + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.LocationOutCount' + type: array + security: + - Bearer: [] + summary: Get All Locations + tags: + - Locations + post: + parameters: + - description: Location Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.LocationCreate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LocationSummary' + security: + - Bearer: [] + summary: Create Location + tags: + - Locations + /v1/locations/{id}: + delete: + parameters: + - description: Location ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Location + tags: + - Locations + get: + parameters: + - description: Location ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LocationOut' + security: + - Bearer: [] + summary: Get Location + tags: + - Locations + put: + parameters: + - description: Location ID + in: path + name: id + required: true + type: string + - description: Location Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.LocationUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.LocationOut' + security: + - Bearer: [] + summary: Update Location + tags: + - Locations + /v1/locations/tree: + get: + parameters: + - description: include items in response tree + in: query + name: withItems + type: boolean + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.TreeItem' + type: array + security: + - Bearer: [] + summary: Get Locations Tree + tags: + - Locations + /v1/maintenance: + get: + parameters: + - enum: + - scheduled + - completed + - both + in: query + name: status + type: string + x-enum-varnames: + - MaintenanceFilterStatusScheduled + - MaintenanceFilterStatusCompleted + - MaintenanceFilterStatusBoth + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.MaintenanceEntryWithDetails' + type: array + security: + - Bearer: [] + summary: Query All Maintenance + tags: + - Maintenance + /v1/maintenance/{id}: + delete: + parameters: + - description: Maintenance ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Maintenance Entry + tags: + - Maintenance + put: + parameters: + - description: Maintenance ID + in: path + name: id + required: true + type: string + - description: Entry Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.MaintenanceEntryUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.MaintenanceEntry' + security: + - Bearer: [] + summary: Update Maintenance Entry + tags: + - Maintenance + /v1/notifiers: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.NotifierOut' + type: array + security: + - Bearer: [] + summary: Get Notifiers + tags: + - Notifiers + post: + parameters: + - description: Notifier Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.NotifierCreate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.NotifierOut' + security: + - Bearer: [] + summary: Create Notifier + tags: + - Notifiers + /v1/notifiers/{id}: + delete: + parameters: + - description: Notifier ID + in: path + name: id + required: true + type: string + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete a Notifier + tags: + - Notifiers + put: + parameters: + - description: Notifier ID + in: path + name: id + required: true + type: string + - description: Notifier Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.NotifierUpdate' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.NotifierOut' + security: + - Bearer: [] + summary: Update Notifier + tags: + - Notifiers + /v1/notifiers/test: + post: + parameters: + - description: URL + in: query + name: url + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Test Notifier + tags: + - Notifiers + /v1/products/search-from-barcode: + get: + parameters: + - description: barcode to be searched + in: query + name: data + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.BarcodeProduct' + type: array + security: + - Bearer: [] + summary: Search EAN from Barcode + tags: + - Items + /v1/qrcode: + get: + parameters: + - description: data to be encoded into qrcode + in: query + name: data + type: string + produces: + - application/json + responses: + "200": + description: image/jpeg + schema: + type: string + security: + - Bearer: [] + summary: Create QR Code + tags: + - Items + /v1/reporting/bill-of-materials: + get: + produces: + - application/json + responses: + "200": + description: text/csv + schema: + type: string + security: + - Bearer: [] + summary: Export Bill of Materials + tags: + - Reporting + /v1/status: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.APISummary' + summary: Application Info + tags: + - Base + /v1/templates: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.ItemTemplateSummary' + type: array + security: + - Bearer: [] + summary: Get All Item Templates + tags: + - Item Templates + post: + parameters: + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateCreate' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Create Item Template + tags: + - Item Templates + /v1/templates/{id}: + delete: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Item Template + tags: + - Item Templates + get: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Get Item Template + tags: + - Item Templates + put: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Update Item Template + tags: + - Item Templates + /v1/templates/{id}/create-item: + post: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.ItemTemplateCreateItemRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Create Item from Template + tags: + - Item Templates + /v1/users/change-password: + put: + parameters: + - description: Password Payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.ChangePassword' + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Change Password + tags: + - User + /v1/users/login: + post: + consumes: + - application/x-www-form-urlencoded + - application/json + parameters: + - description: Login Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.LoginForm' + - description: auth provider + in: query + name: provider + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.TokenResponse' + summary: User Login + tags: + - Authentication + /v1/users/login/oidc: + get: + produces: + - application/json + responses: + "302": + description: Found + summary: OIDC Login Initiation + tags: + - Authentication + /v1/users/login/oidc/callback: + get: + parameters: + - description: Authorization code + in: query + name: code + required: true + type: string + - description: State parameter + in: query + name: state + required: true + type: string + responses: + "302": + description: Found + summary: OIDC Callback Handler + tags: + - Authentication + /v1/users/logout: + post: + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: User Logout + tags: + - Authentication + /v1/users/refresh: + get: + description: |- + handleAuthRefresh returns a handler that will issue a new token from an existing token. + This does not validate that the user still exists within the database. + responses: + "200": + description: OK + security: + - Bearer: [] + summary: User Token Refresh + tags: + - Authentication + /v1/users/register: + post: + parameters: + - description: User Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/services.UserRegistration' + produces: + - application/json + responses: + "204": + description: No Content + "403": + description: Local login is not enabled + schema: + type: string + summary: Register New User + tags: + - User + /v1/users/self: + delete: + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Account + tags: + - User + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/v1.Wrapped' + - properties: + item: + $ref: '#/definitions/repo.UserOut' + type: object + security: + - Bearer: [] + summary: Get User Self + tags: + - User + put: + parameters: + - description: User Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.UserUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/v1.Wrapped' + - properties: + item: + $ref: '#/definitions/repo.UserUpdate' + type: object + security: + - Bearer: [] + summary: Update Account + tags: + - User +schemes: +- https +- http +securityDefinitions: + Bearer: + description: '"Type ''Bearer TOKEN'' to correctly set the API Key"' + in: header + name: Authorization + type: apiKey +swagger: "2.0" diff --git a/docs/en/api/openapi-3.0.json b/docs/en/api/openapi-3.0.json index 2ae3681d..a80a6124 100644 --- a/docs/en/api/openapi-3.0.json +++ b/docs/en/api/openapi-3.0.json @@ -2122,6 +2122,223 @@ } } }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.ItemTemplateSummary" + } + } + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateCreate" + } + } + }, + "description": "Template Data", + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateUpdate" + } + } + }, + "description": "Template Data", + "required": true + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemTemplateOut" + } + } + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "description": "Template ID", + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1.ItemTemplateCreateItemRequest" + } + } + }, + "description": "Item Data", + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/repo.ItemOut" + } + } + } + } + } + } + }, "/v1/users/change-password": { "put": { "security": [ @@ -2197,6 +2414,52 @@ } } }, + "/v1/users/login/oidc": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "State parameter", + "name": "state", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, "/v1/users/logout": { "post": { "security": [ @@ -2254,6 +2517,16 @@ "responses": { "204": { "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } } } } @@ -2640,6 +2913,13 @@ "$ref": "#/components/schemas/ent.GroupInvitationToken" } }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/components/schemas/ent.ItemTemplate" + } + }, "items": { "description": "Items holds the value of the items edge.", "type": "array", @@ -2977,6 +3257,122 @@ } } }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/components/schemas/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.Location" + } + ] + } + } + }, "ent.Label": { "type": "object", "properties": { @@ -3226,6 +3622,64 @@ } } }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/components/schemas/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/components/schemas/ent.ItemTemplate" + } + ] + } + } + }, "ent.User": { "type": "object", "properties": { @@ -3261,6 +3715,14 @@ "description": "Name holds the value of the \"name\" field.", "type": "string" }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, "role": { "description": "Role holds the value of the \"role\" field.", "allOf": [ @@ -3761,6 +4223,280 @@ } } }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/components/schemas/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/components/schemas/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, "repo.ItemType": { "type": "string", "enum": [ @@ -4256,6 +4992,45 @@ } } }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "repo.TotalsByOrganizer": { "type": "object", "properties": { @@ -4313,6 +5088,12 @@ }, "name": { "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" } } }, @@ -4392,6 +5173,15 @@ } } }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, "user.Role": { "type": "string", "enum": [ @@ -4429,6 +5219,9 @@ "message": { "type": "string" }, + "oidc": { + "$ref": "#/components/schemas/v1.OIDCStatus" + }, "title": { "type": "string" }, @@ -4511,6 +5304,36 @@ } } }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, "v1.LoginForm": { "type": "object", "properties": { @@ -4527,6 +5350,23 @@ } } }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, "v1.TokenResponse": { "type": "object", "properties": { diff --git a/docs/en/api/openapi-3.0.yaml b/docs/en/api/openapi-3.0.yaml index bc56d4a2..0a6d2042 100644 --- a/docs/en/api/openapi-3.0.yaml +++ b/docs/en/api/openapi-3.0.yaml @@ -1257,6 +1257,134 @@ paths: application/json: schema: $ref: "#/components/schemas/v1.APISummary" + /v1/templates: + get: + security: + - Bearer: [] + tags: + - Item Templates + summary: Get All Item Templates + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/repo.ItemTemplateSummary" + post: + security: + - Bearer: [] + tags: + - Item Templates + summary: Create Item Template + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateCreate" + description: Template Data + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + "/v1/templates/{id}": + get: + security: + - Bearer: [] + tags: + - Item Templates + summary: Get Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + put: + security: + - Bearer: [] + tags: + - Item Templates + summary: Update Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateUpdate" + description: Template Data + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemTemplateOut" + delete: + security: + - Bearer: [] + tags: + - Item Templates + summary: Delete Item Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + responses: + "204": + description: No Content + "/v1/templates/{id}/create-item": + post: + security: + - Bearer: [] + tags: + - Item Templates + summary: Create Item from Template + parameters: + - description: Template ID + name: id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/v1.ItemTemplateCreateItemRequest" + description: Item Data + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: "#/components/schemas/repo.ItemOut" /v1/users/change-password: put: security: @@ -1302,6 +1430,35 @@ paths: application/json: schema: $ref: "#/components/schemas/v1.TokenResponse" + /v1/users/login/oidc: + get: + tags: + - Authentication + summary: OIDC Login Initiation + responses: + "302": + description: Found + /v1/users/login/oidc/callback: + get: + tags: + - Authentication + summary: OIDC Callback Handler + parameters: + - description: Authorization code + name: code + in: query + required: true + schema: + type: string + - description: State parameter + name: state + in: query + required: true + schema: + type: string + responses: + "302": + description: Found /v1/users/logout: post: security: @@ -1342,6 +1499,12 @@ paths: responses: "204": description: No Content + "403": + description: Local login is not enabled + content: + application/json: + schema: + type: string /v1/users/self: get: security: @@ -1590,6 +1753,11 @@ components: type: array items: $ref: "#/components/schemas/ent.GroupInvitationToken" + item_templates: + description: ItemTemplates holds the value of the item_templates edge. + type: array + items: + $ref: "#/components/schemas/ent.ItemTemplate" items: description: Items holds the value of the items edge. type: array @@ -1826,6 +1994,93 @@ components: description: Item holds the value of the item edge. allOf: - $ref: "#/components/schemas/ent.Item" + ent.ItemTemplate: + type: object + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + default_description: + description: Default description for items created from this template + type: string + default_insured: + description: DefaultInsured holds the value of the "default_insured" field. + type: boolean + default_label_ids: + description: Default label IDs for items created from this template + type: array + items: + type: string + default_lifetime_warranty: + description: DefaultLifetimeWarranty holds the value of the + "default_lifetime_warranty" field. + type: boolean + default_manufacturer: + description: DefaultManufacturer holds the value of the "default_manufacturer" + field. + type: string + default_model_number: + description: Default model number for items created from this template + type: string + default_name: + description: Default name template for items (can use placeholders) + type: string + default_quantity: + description: DefaultQuantity holds the value of the "default_quantity" field. + type: integer + default_warranty_details: + description: DefaultWarrantyDetails holds the value of the + "default_warranty_details" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + description: >- + Edges holds the relations/edges for other nodes in the graph. + + The values are being populated by the ItemTemplateQuery when eager-loading is set. + allOf: + - $ref: "#/components/schemas/ent.ItemTemplateEdges" + id: + description: ID of the ent. + type: string + include_purchase_fields: + description: Whether to include purchase fields in items created from this + template + type: boolean + include_sold_fields: + description: Whether to include sold fields in items created from this template + type: boolean + include_warranty_fields: + description: Whether to include warranty fields in items created from this + template + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + ent.ItemTemplateEdges: + type: object + properties: + fields: + description: Fields holds the value of the fields edge. + type: array + items: + $ref: "#/components/schemas/ent.TemplateField" + group: + description: Group holds the value of the group edge. + allOf: + - $ref: "#/components/schemas/ent.Group" + location: + description: Location holds the value of the location edge. + allOf: + - $ref: "#/components/schemas/ent.Location" ent.Label: type: object properties: @@ -1998,6 +2253,45 @@ components: description: User holds the value of the user edge. allOf: - $ref: "#/components/schemas/ent.User" + ent.TemplateField: + type: object + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + description: >- + Edges holds the relations/edges for other nodes in the graph. + + The values are being populated by the TemplateFieldQuery when eager-loading is set. + allOf: + - $ref: "#/components/schemas/ent.TemplateFieldEdges" + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + type: + description: Type holds the value of the "type" field. + allOf: + - $ref: "#/components/schemas/templatefield.Type" + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + ent.TemplateFieldEdges: + type: object + properties: + item_template: + description: ItemTemplate holds the value of the item_template edge. + allOf: + - $ref: "#/components/schemas/ent.ItemTemplate" ent.User: type: object properties: @@ -2026,6 +2320,12 @@ components: name: description: Name holds the value of the "name" field. type: string + oidc_issuer: + description: OidcIssuer holds the value of the "oidc_issuer" field. + type: string + oidc_subject: + description: OidcSubject holds the value of the "oidc_subject" field. + type: string role: description: Role holds the value of the "role" field. allOf: @@ -2361,6 +2661,201 @@ components: nullable: true updatedAt: type: string + repo.ItemTemplateCreate: + type: object + required: + - name + properties: + defaultDescription: + type: string + maxLength: 1000 + nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + type: array + items: + type: string + nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + nullable: true + defaultManufacturer: + type: string + maxLength: 255 + nullable: true + defaultModelNumber: + type: string + maxLength: 255 + nullable: true + defaultName: + type: string + maxLength: 255 + nullable: true + defaultQuantity: + description: Default values for items + type: integer + nullable: true + defaultWarrantyDetails: + type: string + maxLength: 1000 + nullable: true + description: + type: string + maxLength: 1000 + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + maxLength: 255 + minLength: 1 + notes: + type: string + maxLength: 1000 + repo.ItemTemplateOut: + type: object + properties: + createdAt: + type: string + defaultDescription: + type: string + defaultInsured: + type: boolean + defaultLabels: + type: array + items: + $ref: "#/components/schemas/repo.TemplateLabelSummary" + defaultLifetimeWarranty: + type: boolean + defaultLocation: + description: Default location and labels + allOf: + - $ref: "#/components/schemas/repo.TemplateLocationSummary" + defaultManufacturer: + type: string + defaultModelNumber: + type: string + defaultName: + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + type: string + description: + type: string + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + notes: + type: string + updatedAt: + type: string + repo.ItemTemplateSummary: + type: object + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + repo.ItemTemplateUpdate: + type: object + required: + - name + properties: + defaultDescription: + type: string + maxLength: 1000 + nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + type: array + items: + type: string + nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + nullable: true + defaultManufacturer: + type: string + maxLength: 255 + nullable: true + defaultModelNumber: + type: string + maxLength: 255 + nullable: true + defaultName: + type: string + maxLength: 255 + nullable: true + defaultQuantity: + description: Default values for items + type: integer + nullable: true + defaultWarrantyDetails: + type: string + maxLength: 1000 + nullable: true + description: + type: string + maxLength: 1000 + fields: + description: Custom fields + type: array + items: + $ref: "#/components/schemas/repo.TemplateField" + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + maxLength: 255 + minLength: 1 + notes: + type: string + maxLength: 1000 repo.ItemType: type: string enum: @@ -2698,6 +3193,31 @@ components: type: integer total: type: integer + repo.TemplateField: + type: object + properties: + id: + type: string + name: + type: string + textValue: + type: string + type: + type: string + repo.TemplateLabelSummary: + type: object + properties: + id: + type: string + name: + type: string + repo.TemplateLocationSummary: + type: object + properties: + id: + type: string + name: + type: string repo.TotalsByOrganizer: type: object properties: @@ -2737,6 +3257,10 @@ components: type: boolean name: type: string + oidcIssuer: + type: string + oidcSubject: + type: string repo.UserUpdate: type: object properties: @@ -2786,6 +3310,12 @@ components: type: string token: type: string + templatefield.Type: + type: string + enum: + - text + x-enum-varnames: + - TypeText user.Role: type: string enum: @@ -2813,6 +3343,8 @@ components: $ref: "#/components/schemas/services.Latest" message: type: string + oidc: + $ref: "#/components/schemas/v1.OIDCStatus" title: type: string versions: @@ -2865,6 +3397,27 @@ components: properties: token: type: string + v1.ItemTemplateCreateItemRequest: + type: object + required: + - locationId + - name + properties: + description: + type: string + maxLength: 1000 + labelIds: + type: array + items: + type: string + locationId: + type: string + name: + type: string + maxLength: 255 + minLength: 1 + quantity: + type: integer v1.LoginForm: type: object properties: @@ -2876,6 +3429,17 @@ components: username: type: string example: admin@admin.com + v1.OIDCStatus: + type: object + properties: + allowLocal: + type: boolean + autoRedirect: + type: boolean + buttonText: + type: string + enabled: + type: boolean v1.TokenResponse: type: object properties: diff --git a/docs/en/api/swagger-2.0.json b/docs/en/api/swagger-2.0.json index 3fd96322..61b8612a 100644 --- a/docs/en/api/swagger-2.0.json +++ b/docs/en/api/swagger-2.0.json @@ -1961,6 +1961,209 @@ } } }, + "/v1/templates": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get All Item Templates", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.ItemTemplateSummary" + } + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item Template", + "parameters": [ + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateCreate" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + } + }, + "/v1/templates/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Get Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Update Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Template Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemTemplateUpdate" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemTemplateOut" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Delete Item Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/v1/templates/{id}/create-item": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Item Templates" + ], + "summary": "Create Item from Template", + "parameters": [ + { + "type": "string", + "description": "Template ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.ItemTemplateCreateItemRequest" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } + } + }, "/v1/users/change-password": { "put": { "security": [ @@ -2030,6 +2233,51 @@ } } }, + "/v1/users/login/oidc": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "Authentication" + ], + "summary": "OIDC Login Initiation", + "responses": { + "302": { + "description": "Found" + } + } + } + }, + "/v1/users/login/oidc/callback": { + "get": { + "tags": [ + "Authentication" + ], + "summary": "OIDC Callback Handler", + "parameters": [ + { + "type": "string", + "description": "Authorization code", + "name": "code", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "State parameter", + "name": "state", + "in": "query", + "required": true + } + ], + "responses": { + "302": { + "description": "Found" + } + } + } + }, "/v1/users/logout": { "post": { "security": [ @@ -2090,6 +2338,12 @@ "responses": { "204": { "description": "No Content" + }, + "403": { + "description": "Local login is not enabled", + "schema": { + "type": "string" + } } } } @@ -2460,6 +2714,13 @@ "$ref": "#/definitions/ent.GroupInvitationToken" } }, + "item_templates": { + "description": "ItemTemplates holds the value of the item_templates edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.ItemTemplate" + } + }, "items": { "description": "Items holds the value of the items edge.", "type": "array", @@ -2797,6 +3058,122 @@ } } }, + "ent.ItemTemplate": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "default_description": { + "description": "Default description for items created from this template", + "type": "string" + }, + "default_insured": { + "description": "DefaultInsured holds the value of the \"default_insured\" field.", + "type": "boolean" + }, + "default_label_ids": { + "description": "Default label IDs for items created from this template", + "type": "array", + "items": { + "type": "string" + } + }, + "default_lifetime_warranty": { + "description": "DefaultLifetimeWarranty holds the value of the \"default_lifetime_warranty\" field.", + "type": "boolean" + }, + "default_manufacturer": { + "description": "DefaultManufacturer holds the value of the \"default_manufacturer\" field.", + "type": "string" + }, + "default_model_number": { + "description": "Default model number for items created from this template", + "type": "string" + }, + "default_name": { + "description": "Default name template for items (can use placeholders)", + "type": "string" + }, + "default_quantity": { + "description": "DefaultQuantity holds the value of the \"default_quantity\" field.", + "type": "integer" + }, + "default_warranty_details": { + "description": "DefaultWarrantyDetails holds the value of the \"default_warranty_details\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the ItemTemplateQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplateEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "include_purchase_fields": { + "description": "Whether to include purchase fields in items created from this template", + "type": "boolean" + }, + "include_sold_fields": { + "description": "Whether to include sold fields in items created from this template", + "type": "boolean" + }, + "include_warranty_fields": { + "description": "Whether to include warranty fields in items created from this template", + "type": "boolean" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "notes": { + "description": "Notes holds the value of the \"notes\" field.", + "type": "string" + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.ItemTemplateEdges": { + "type": "object", + "properties": { + "fields": { + "description": "Fields holds the value of the fields edge.", + "type": "array", + "items": { + "$ref": "#/definitions/ent.TemplateField" + } + }, + "group": { + "description": "Group holds the value of the group edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Group" + } + ] + }, + "location": { + "description": "Location holds the value of the location edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.Location" + } + ] + } + } + }, "ent.Label": { "type": "object", "properties": { @@ -3046,6 +3423,64 @@ } } }, + "ent.TemplateField": { + "type": "object", + "properties": { + "created_at": { + "description": "CreatedAt holds the value of the \"created_at\" field.", + "type": "string" + }, + "description": { + "description": "Description holds the value of the \"description\" field.", + "type": "string" + }, + "edges": { + "description": "Edges holds the relations/edges for other nodes in the graph.\nThe values are being populated by the TemplateFieldQuery when eager-loading is set.", + "allOf": [ + { + "$ref": "#/definitions/ent.TemplateFieldEdges" + } + ] + }, + "id": { + "description": "ID of the ent.", + "type": "string" + }, + "name": { + "description": "Name holds the value of the \"name\" field.", + "type": "string" + }, + "text_value": { + "description": "TextValue holds the value of the \"text_value\" field.", + "type": "string" + }, + "type": { + "description": "Type holds the value of the \"type\" field.", + "allOf": [ + { + "$ref": "#/definitions/templatefield.Type" + } + ] + }, + "updated_at": { + "description": "UpdatedAt holds the value of the \"updated_at\" field.", + "type": "string" + } + } + }, + "ent.TemplateFieldEdges": { + "type": "object", + "properties": { + "item_template": { + "description": "ItemTemplate holds the value of the item_template edge.", + "allOf": [ + { + "$ref": "#/definitions/ent.ItemTemplate" + } + ] + } + } + }, "ent.User": { "type": "object", "properties": { @@ -3081,6 +3516,14 @@ "description": "Name holds the value of the \"name\" field.", "type": "string" }, + "oidc_issuer": { + "description": "OidcIssuer holds the value of the \"oidc_issuer\" field.", + "type": "string" + }, + "oidc_subject": { + "description": "OidcSubject holds the value of the \"oidc_subject\" field.", + "type": "string" + }, "role": { "description": "Role holds the value of the \"role\" field.", "allOf": [ @@ -3581,6 +4024,280 @@ } } }, + "repo.ItemTemplateCreate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, + "repo.ItemTemplateOut": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "defaultDescription": { + "type": "string" + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabels": { + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateLabelSummary" + } + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocation": { + "description": "Default location and labels", + "allOf": [ + { + "$ref": "#/definitions/repo.TemplateLocationSummary" + } + ] + }, + "defaultManufacturer": { + "type": "string" + }, + "defaultModelNumber": { + "type": "string" + }, + "defaultName": { + "type": "string" + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer" + }, + "defaultWarrantyDetails": { + "type": "string" + }, + "description": { + "type": "string" + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string" + }, + "notes": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateSummary": { + "type": "object", + "properties": { + "createdAt": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "updatedAt": { + "type": "string" + } + } + }, + "repo.ItemTemplateUpdate": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "defaultDescription": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "defaultInsured": { + "type": "boolean" + }, + "defaultLabelIds": { + "type": "array", + "items": { + "type": "string" + }, + "x-nullable": true + }, + "defaultLifetimeWarranty": { + "type": "boolean" + }, + "defaultLocationId": { + "description": "Default location and labels", + "type": "string", + "x-nullable": true + }, + "defaultManufacturer": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultModelNumber": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultName": { + "type": "string", + "maxLength": 255, + "x-nullable": true + }, + "defaultQuantity": { + "description": "Default values for items", + "type": "integer", + "x-nullable": true + }, + "defaultWarrantyDetails": { + "type": "string", + "maxLength": 1000, + "x-nullable": true + }, + "description": { + "type": "string", + "maxLength": 1000 + }, + "fields": { + "description": "Custom fields", + "type": "array", + "items": { + "$ref": "#/definitions/repo.TemplateField" + } + }, + "id": { + "type": "string" + }, + "includePurchaseFields": { + "type": "boolean" + }, + "includeSoldFields": { + "type": "boolean" + }, + "includeWarrantyFields": { + "description": "Metadata flags", + "type": "boolean" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "notes": { + "type": "string", + "maxLength": 1000 + } + } + }, "repo.ItemType": { "type": "string", "enum": [ @@ -4076,6 +4793,45 @@ } } }, + "repo.TemplateField": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "textValue": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "repo.TemplateLabelSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "repo.TemplateLocationSummary": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "repo.TotalsByOrganizer": { "type": "object", "properties": { @@ -4133,6 +4889,12 @@ }, "name": { "type": "string" + }, + "oidcIssuer": { + "type": "string" + }, + "oidcSubject": { + "type": "string" } } }, @@ -4212,6 +4974,15 @@ } } }, + "templatefield.Type": { + "type": "string", + "enum": [ + "text" + ], + "x-enum-varnames": [ + "TypeText" + ] + }, "user.Role": { "type": "string", "enum": [ @@ -4249,6 +5020,9 @@ "message": { "type": "string" }, + "oidc": { + "$ref": "#/definitions/v1.OIDCStatus" + }, "title": { "type": "string" }, @@ -4331,6 +5105,36 @@ } } }, + "v1.ItemTemplateCreateItemRequest": { + "type": "object", + "required": [ + "locationId", + "name" + ], + "properties": { + "description": { + "type": "string", + "maxLength": 1000 + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "locationId": { + "type": "string" + }, + "name": { + "type": "string", + "maxLength": 255, + "minLength": 1 + }, + "quantity": { + "type": "integer" + } + } + }, "v1.LoginForm": { "type": "object", "properties": { @@ -4347,6 +5151,23 @@ } } }, + "v1.OIDCStatus": { + "type": "object", + "properties": { + "allowLocal": { + "type": "boolean" + }, + "autoRedirect": { + "type": "boolean" + }, + "buttonText": { + "type": "string" + }, + "enabled": { + "type": "boolean" + } + } + }, "v1.TokenResponse": { "type": "object", "properties": { diff --git a/docs/en/api/swagger-2.0.yaml b/docs/en/api/swagger-2.0.yaml index 1fc5f05e..d18a8f45 100644 --- a/docs/en/api/swagger-2.0.yaml +++ b/docs/en/api/swagger-2.0.yaml @@ -179,6 +179,11 @@ definitions: items: $ref: '#/definitions/ent.GroupInvitationToken' type: array + item_templates: + description: ItemTemplates holds the value of the item_templates edge. + items: + $ref: '#/definitions/ent.ItemTemplate' + type: array items: description: Items holds the value of the items edge. items: @@ -414,6 +419,92 @@ definitions: - $ref: '#/definitions/ent.Item' description: Item holds the value of the item edge. type: object + ent.ItemTemplate: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + default_description: + description: Default description for items created from this template + type: string + default_insured: + description: DefaultInsured holds the value of the "default_insured" field. + type: boolean + default_label_ids: + description: Default label IDs for items created from this template + items: + type: string + type: array + default_lifetime_warranty: + description: DefaultLifetimeWarranty holds the value of the "default_lifetime_warranty" + field. + type: boolean + default_manufacturer: + description: DefaultManufacturer holds the value of the "default_manufacturer" + field. + type: string + default_model_number: + description: Default model number for items created from this template + type: string + default_name: + description: Default name template for items (can use placeholders) + type: string + default_quantity: + description: DefaultQuantity holds the value of the "default_quantity" field. + type: integer + default_warranty_details: + description: DefaultWarrantyDetails holds the value of the "default_warranty_details" + field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.ItemTemplateEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the ItemTemplateQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + include_purchase_fields: + description: Whether to include purchase fields in items created from this + template + type: boolean + include_sold_fields: + description: Whether to include sold fields in items created from this template + type: boolean + include_warranty_fields: + description: Whether to include warranty fields in items created from this + template + type: boolean + name: + description: Name holds the value of the "name" field. + type: string + notes: + description: Notes holds the value of the "notes" field. + type: string + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.ItemTemplateEdges: + properties: + fields: + description: Fields holds the value of the fields edge. + items: + $ref: '#/definitions/ent.TemplateField' + type: array + group: + allOf: + - $ref: '#/definitions/ent.Group' + description: Group holds the value of the group edge. + location: + allOf: + - $ref: '#/definitions/ent.Location' + description: Location holds the value of the location edge. + type: object ent.Label: properties: color: @@ -582,6 +673,44 @@ definitions: - $ref: '#/definitions/ent.User' description: User holds the value of the user edge. type: object + ent.TemplateField: + properties: + created_at: + description: CreatedAt holds the value of the "created_at" field. + type: string + description: + description: Description holds the value of the "description" field. + type: string + edges: + allOf: + - $ref: '#/definitions/ent.TemplateFieldEdges' + description: |- + Edges holds the relations/edges for other nodes in the graph. + The values are being populated by the TemplateFieldQuery when eager-loading is set. + id: + description: ID of the ent. + type: string + name: + description: Name holds the value of the "name" field. + type: string + text_value: + description: TextValue holds the value of the "text_value" field. + type: string + type: + allOf: + - $ref: '#/definitions/templatefield.Type' + description: Type holds the value of the "type" field. + updated_at: + description: UpdatedAt holds the value of the "updated_at" field. + type: string + type: object + ent.TemplateFieldEdges: + properties: + item_template: + allOf: + - $ref: '#/definitions/ent.ItemTemplate' + description: ItemTemplate holds the value of the item_template edge. + type: object ent.User: properties: activated_on: @@ -608,6 +737,12 @@ definitions: name: description: Name holds the value of the "name" field. type: string + oidc_issuer: + description: OidcIssuer holds the value of the "oidc_issuer" field. + type: string + oidc_subject: + description: OidcSubject holds the value of the "oidc_subject" field. + type: string role: allOf: - $ref: '#/definitions/user.Role' @@ -944,6 +1079,201 @@ definitions: updatedAt: type: string type: object + repo.ItemTemplateCreate: + properties: + defaultDescription: + maxLength: 1000 + type: string + x-nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + x-nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + x-nullable: true + defaultManufacturer: + maxLength: 255 + type: string + x-nullable: true + defaultModelNumber: + maxLength: 255 + type: string + x-nullable: true + defaultName: + maxLength: 255 + type: string + x-nullable: true + defaultQuantity: + description: Default values for items + type: integer + x-nullable: true + defaultWarrantyDetails: + maxLength: 1000 + type: string + x-nullable: true + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object + repo.ItemTemplateOut: + properties: + createdAt: + type: string + defaultDescription: + type: string + defaultInsured: + type: boolean + defaultLabels: + items: + $ref: '#/definitions/repo.TemplateLabelSummary' + type: array + defaultLifetimeWarranty: + type: boolean + defaultLocation: + allOf: + - $ref: '#/definitions/repo.TemplateLocationSummary' + description: Default location and labels + defaultManufacturer: + type: string + defaultModelNumber: + type: string + defaultName: + type: string + defaultQuantity: + description: Default values for items + type: integer + defaultWarrantyDetails: + type: string + description: + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + type: string + notes: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateSummary: + properties: + createdAt: + type: string + description: + type: string + id: + type: string + name: + type: string + updatedAt: + type: string + type: object + repo.ItemTemplateUpdate: + properties: + defaultDescription: + maxLength: 1000 + type: string + x-nullable: true + defaultInsured: + type: boolean + defaultLabelIds: + items: + type: string + type: array + x-nullable: true + defaultLifetimeWarranty: + type: boolean + defaultLocationId: + description: Default location and labels + type: string + x-nullable: true + defaultManufacturer: + maxLength: 255 + type: string + x-nullable: true + defaultModelNumber: + maxLength: 255 + type: string + x-nullable: true + defaultName: + maxLength: 255 + type: string + x-nullable: true + defaultQuantity: + description: Default values for items + type: integer + x-nullable: true + defaultWarrantyDetails: + maxLength: 1000 + type: string + x-nullable: true + description: + maxLength: 1000 + type: string + fields: + description: Custom fields + items: + $ref: '#/definitions/repo.TemplateField' + type: array + id: + type: string + includePurchaseFields: + type: boolean + includeSoldFields: + type: boolean + includeWarrantyFields: + description: Metadata flags + type: boolean + name: + maxLength: 255 + minLength: 1 + type: string + notes: + maxLength: 1000 + type: string + required: + - name + type: object repo.ItemType: enum: - location @@ -1281,6 +1611,31 @@ definitions: total: type: integer type: object + repo.TemplateField: + properties: + id: + type: string + name: + type: string + textValue: + type: string + type: + type: string + type: object + repo.TemplateLabelSummary: + properties: + id: + type: string + name: + type: string + type: object + repo.TemplateLocationSummary: + properties: + id: + type: string + name: + type: string + type: object repo.TotalsByOrganizer: properties: id: @@ -1319,6 +1674,10 @@ definitions: type: boolean name: type: string + oidcIssuer: + type: string + oidcSubject: + type: string type: object repo.UserUpdate: properties: @@ -1369,6 +1728,12 @@ definitions: token: type: string type: object + templatefield.Type: + enum: + - text + type: string + x-enum-varnames: + - TypeText user.Role: enum: - user @@ -1395,6 +1760,8 @@ definitions: $ref: '#/definitions/services.Latest' message: type: string + oidc: + $ref: '#/definitions/v1.OIDCStatus' title: type: string versions: @@ -1448,6 +1815,27 @@ definitions: token: type: string type: object + v1.ItemTemplateCreateItemRequest: + properties: + description: + maxLength: 1000 + type: string + labelIds: + items: + type: string + type: array + locationId: + type: string + name: + maxLength: 255 + minLength: 1 + type: string + quantity: + type: integer + required: + - locationId + - name + type: object v1.LoginForm: properties: password: @@ -1459,6 +1847,17 @@ definitions: example: admin@admin.com type: string type: object + v1.OIDCStatus: + properties: + allowLocal: + type: boolean + autoRedirect: + type: boolean + buttonText: + type: string + enabled: + type: boolean + type: object v1.TokenResponse: properties: attachmentToken: @@ -2679,6 +3078,130 @@ paths: summary: Application Info tags: - Base + /v1/templates: + get: + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/repo.ItemTemplateSummary' + type: array + security: + - Bearer: [] + summary: Get All Item Templates + tags: + - Item Templates + post: + parameters: + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateCreate' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Create Item Template + tags: + - Item Templates + /v1/templates/{id}: + delete: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + security: + - Bearer: [] + summary: Delete Item Template + tags: + - Item Templates + get: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Get Item Template + tags: + - Item Templates + put: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Template Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemTemplateUpdate' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemTemplateOut' + security: + - Bearer: [] + summary: Update Item Template + tags: + - Item Templates + /v1/templates/{id}/create-item: + post: + parameters: + - description: Template ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/v1.ItemTemplateCreateItemRequest' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Create Item from Template + tags: + - Item Templates /v1/users/change-password: put: parameters: @@ -2722,6 +3245,35 @@ paths: summary: User Login tags: - Authentication + /v1/users/login/oidc: + get: + produces: + - application/json + responses: + "302": + description: Found + summary: OIDC Login Initiation + tags: + - Authentication + /v1/users/login/oidc/callback: + get: + parameters: + - description: Authorization code + in: query + name: code + required: true + type: string + - description: State parameter + in: query + name: state + required: true + type: string + responses: + "302": + description: Found + summary: OIDC Callback Handler + tags: + - Authentication /v1/users/logout: post: responses: @@ -2759,6 +3311,10 @@ paths: responses: "204": description: No Content + "403": + description: Local login is not enabled + schema: + type: string summary: Register New User tags: - User diff --git a/frontend/components/Item/CreateModal.vue b/frontend/components/Item/CreateModal.vue index 5910e8c0..6f578b16 100644 --- a/frontend/components/Item/CreateModal.vue +++ b/frontend/components/Item/CreateModal.vue @@ -1,8 +1,18 @@