Files
homebox/backend/internal/data/ent/item_create.go
Jeff Rescignano f36756d98e Add support for SSO / OpenID Connect (OIDC) (#996)
* ent re-generation

* add oidc integration

* document oidc integration

* go fmt

* address backend linter findings

* run prettier on index.vue

* State cookie domain can mismatch when Hostname override is used (breaks CSRF check). Add SameSite.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Delete state cookie with matching domain and MaxAge; add SameSite.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Fix endpoint path in comments and error to include /api/v1.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Also use request context when verifying the ID token.

* Do not return raw auth errors to clients (user-enumeration risk).

* consistently set cookie the same way across function

* remove baseURL after declaration

* only enable OIDC routes if OIDC is enabled

* swagger doc for failure

* Only block when provider=local; move the check after parsing provider

* fix extended session comment

* reduce pii logging

* futher reduce pii logging

* remove unused DiscoveryDocument

* remove unused offline_access from default oidc scopes

* remove offline access from AuthCodeURL

* support host from X-Forwarded-Host

* set sane default claim names if unset

* error strings should not be capitalized

* Revert "run prettier on index.vue"

This reverts commit aa22330a23.

* Add timeout to provider discovery

* Split scopes robustly

* refactor hostname calculation

* address frontend prettier findings

* add property oidc on type APISummary

* LoginOIDC: Normalize inputs, only create if not found

* add oidc email verification

* oidc handleCallback: clear state cookie before each return

* add support for oidc nonce parameter

* Harden first-login race: handle concurrent creates gracefully and fix log key.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* support email verified claim as bool or string

* fail fast on empty email

* PKCE verifier

* fix: add timing delay to attachment test to resolve CI race condition

The attachment test was failing intermittently in CI due to a race condition
between attachment creation and retrieval. Adding a small 100ms delay after
attachment creation ensures the file system and database operations complete
before the test attempts to verify the attachment exists.

* Revert "fix: add timing delay to attachment test to resolve CI race condition"

This reverts commit 4aa8b2a0d829753e8d2dd1ba76f4b1e04e28c45e.

* oidc error state, use ref

* rename oidc.force to oidc.authRedirect

* remove hardcoded oidc error timeout

* feat: sub/iss based identity matching and userinfo endpoint collection

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Matthew Kilgore <matthew@kilgore.dev>
2025-12-06 10:16:05 -05:00

1008 lines
29 KiB
Go
Generated

// 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/attachment"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/group"
"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/label"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/location"
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry"
)
// ItemCreate is the builder for creating a Item entity.
type ItemCreate struct {
config
mutation *ItemMutation
hooks []Hook
}
// SetCreatedAt sets the "created_at" field.
func (_c *ItemCreate) SetCreatedAt(v time.Time) *ItemCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ItemCreate) SetNillableCreatedAt(v *time.Time) *ItemCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *ItemCreate) SetUpdatedAt(v time.Time) *ItemCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *ItemCreate) SetNillableUpdatedAt(v *time.Time) *ItemCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetName sets the "name" field.
func (_c *ItemCreate) SetName(v string) *ItemCreate {
_c.mutation.SetName(v)
return _c
}
// SetDescription sets the "description" field.
func (_c *ItemCreate) SetDescription(v string) *ItemCreate {
_c.mutation.SetDescription(v)
return _c
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_c *ItemCreate) SetNillableDescription(v *string) *ItemCreate {
if v != nil {
_c.SetDescription(*v)
}
return _c
}
// SetImportRef sets the "import_ref" field.
func (_c *ItemCreate) SetImportRef(v string) *ItemCreate {
_c.mutation.SetImportRef(v)
return _c
}
// SetNillableImportRef sets the "import_ref" field if the given value is not nil.
func (_c *ItemCreate) SetNillableImportRef(v *string) *ItemCreate {
if v != nil {
_c.SetImportRef(*v)
}
return _c
}
// SetNotes sets the "notes" field.
func (_c *ItemCreate) SetNotes(v string) *ItemCreate {
_c.mutation.SetNotes(v)
return _c
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_c *ItemCreate) SetNillableNotes(v *string) *ItemCreate {
if v != nil {
_c.SetNotes(*v)
}
return _c
}
// SetQuantity sets the "quantity" field.
func (_c *ItemCreate) SetQuantity(v int) *ItemCreate {
_c.mutation.SetQuantity(v)
return _c
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_c *ItemCreate) SetNillableQuantity(v *int) *ItemCreate {
if v != nil {
_c.SetQuantity(*v)
}
return _c
}
// SetInsured sets the "insured" field.
func (_c *ItemCreate) SetInsured(v bool) *ItemCreate {
_c.mutation.SetInsured(v)
return _c
}
// SetNillableInsured sets the "insured" field if the given value is not nil.
func (_c *ItemCreate) SetNillableInsured(v *bool) *ItemCreate {
if v != nil {
_c.SetInsured(*v)
}
return _c
}
// SetArchived sets the "archived" field.
func (_c *ItemCreate) SetArchived(v bool) *ItemCreate {
_c.mutation.SetArchived(v)
return _c
}
// SetNillableArchived sets the "archived" field if the given value is not nil.
func (_c *ItemCreate) SetNillableArchived(v *bool) *ItemCreate {
if v != nil {
_c.SetArchived(*v)
}
return _c
}
// SetAssetID sets the "asset_id" field.
func (_c *ItemCreate) SetAssetID(v int) *ItemCreate {
_c.mutation.SetAssetID(v)
return _c
}
// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
func (_c *ItemCreate) SetNillableAssetID(v *int) *ItemCreate {
if v != nil {
_c.SetAssetID(*v)
}
return _c
}
// SetSyncChildItemsLocations sets the "sync_child_items_locations" field.
func (_c *ItemCreate) SetSyncChildItemsLocations(v bool) *ItemCreate {
_c.mutation.SetSyncChildItemsLocations(v)
return _c
}
// SetNillableSyncChildItemsLocations sets the "sync_child_items_locations" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSyncChildItemsLocations(v *bool) *ItemCreate {
if v != nil {
_c.SetSyncChildItemsLocations(*v)
}
return _c
}
// SetSerialNumber sets the "serial_number" field.
func (_c *ItemCreate) SetSerialNumber(v string) *ItemCreate {
_c.mutation.SetSerialNumber(v)
return _c
}
// SetNillableSerialNumber sets the "serial_number" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSerialNumber(v *string) *ItemCreate {
if v != nil {
_c.SetSerialNumber(*v)
}
return _c
}
// SetModelNumber sets the "model_number" field.
func (_c *ItemCreate) SetModelNumber(v string) *ItemCreate {
_c.mutation.SetModelNumber(v)
return _c
}
// SetNillableModelNumber sets the "model_number" field if the given value is not nil.
func (_c *ItemCreate) SetNillableModelNumber(v *string) *ItemCreate {
if v != nil {
_c.SetModelNumber(*v)
}
return _c
}
// SetManufacturer sets the "manufacturer" field.
func (_c *ItemCreate) SetManufacturer(v string) *ItemCreate {
_c.mutation.SetManufacturer(v)
return _c
}
// SetNillableManufacturer sets the "manufacturer" field if the given value is not nil.
func (_c *ItemCreate) SetNillableManufacturer(v *string) *ItemCreate {
if v != nil {
_c.SetManufacturer(*v)
}
return _c
}
// SetLifetimeWarranty sets the "lifetime_warranty" field.
func (_c *ItemCreate) SetLifetimeWarranty(v bool) *ItemCreate {
_c.mutation.SetLifetimeWarranty(v)
return _c
}
// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil.
func (_c *ItemCreate) SetNillableLifetimeWarranty(v *bool) *ItemCreate {
if v != nil {
_c.SetLifetimeWarranty(*v)
}
return _c
}
// SetWarrantyExpires sets the "warranty_expires" field.
func (_c *ItemCreate) SetWarrantyExpires(v time.Time) *ItemCreate {
_c.mutation.SetWarrantyExpires(v)
return _c
}
// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil.
func (_c *ItemCreate) SetNillableWarrantyExpires(v *time.Time) *ItemCreate {
if v != nil {
_c.SetWarrantyExpires(*v)
}
return _c
}
// SetWarrantyDetails sets the "warranty_details" field.
func (_c *ItemCreate) SetWarrantyDetails(v string) *ItemCreate {
_c.mutation.SetWarrantyDetails(v)
return _c
}
// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil.
func (_c *ItemCreate) SetNillableWarrantyDetails(v *string) *ItemCreate {
if v != nil {
_c.SetWarrantyDetails(*v)
}
return _c
}
// SetPurchaseTime sets the "purchase_time" field.
func (_c *ItemCreate) SetPurchaseTime(v time.Time) *ItemCreate {
_c.mutation.SetPurchaseTime(v)
return _c
}
// SetNillablePurchaseTime sets the "purchase_time" field if the given value is not nil.
func (_c *ItemCreate) SetNillablePurchaseTime(v *time.Time) *ItemCreate {
if v != nil {
_c.SetPurchaseTime(*v)
}
return _c
}
// SetPurchaseFrom sets the "purchase_from" field.
func (_c *ItemCreate) SetPurchaseFrom(v string) *ItemCreate {
_c.mutation.SetPurchaseFrom(v)
return _c
}
// SetNillablePurchaseFrom sets the "purchase_from" field if the given value is not nil.
func (_c *ItemCreate) SetNillablePurchaseFrom(v *string) *ItemCreate {
if v != nil {
_c.SetPurchaseFrom(*v)
}
return _c
}
// SetPurchasePrice sets the "purchase_price" field.
func (_c *ItemCreate) SetPurchasePrice(v float64) *ItemCreate {
_c.mutation.SetPurchasePrice(v)
return _c
}
// SetNillablePurchasePrice sets the "purchase_price" field if the given value is not nil.
func (_c *ItemCreate) SetNillablePurchasePrice(v *float64) *ItemCreate {
if v != nil {
_c.SetPurchasePrice(*v)
}
return _c
}
// SetSoldTime sets the "sold_time" field.
func (_c *ItemCreate) SetSoldTime(v time.Time) *ItemCreate {
_c.mutation.SetSoldTime(v)
return _c
}
// SetNillableSoldTime sets the "sold_time" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSoldTime(v *time.Time) *ItemCreate {
if v != nil {
_c.SetSoldTime(*v)
}
return _c
}
// SetSoldTo sets the "sold_to" field.
func (_c *ItemCreate) SetSoldTo(v string) *ItemCreate {
_c.mutation.SetSoldTo(v)
return _c
}
// SetNillableSoldTo sets the "sold_to" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSoldTo(v *string) *ItemCreate {
if v != nil {
_c.SetSoldTo(*v)
}
return _c
}
// SetSoldPrice sets the "sold_price" field.
func (_c *ItemCreate) SetSoldPrice(v float64) *ItemCreate {
_c.mutation.SetSoldPrice(v)
return _c
}
// SetNillableSoldPrice sets the "sold_price" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSoldPrice(v *float64) *ItemCreate {
if v != nil {
_c.SetSoldPrice(*v)
}
return _c
}
// SetSoldNotes sets the "sold_notes" field.
func (_c *ItemCreate) SetSoldNotes(v string) *ItemCreate {
_c.mutation.SetSoldNotes(v)
return _c
}
// SetNillableSoldNotes sets the "sold_notes" field if the given value is not nil.
func (_c *ItemCreate) SetNillableSoldNotes(v *string) *ItemCreate {
if v != nil {
_c.SetSoldNotes(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *ItemCreate) SetID(v uuid.UUID) *ItemCreate {
_c.mutation.SetID(v)
return _c
}
// SetNillableID sets the "id" field if the given value is not nil.
func (_c *ItemCreate) SetNillableID(v *uuid.UUID) *ItemCreate {
if v != nil {
_c.SetID(*v)
}
return _c
}
// SetGroupID sets the "group" edge to the Group entity by ID.
func (_c *ItemCreate) SetGroupID(id uuid.UUID) *ItemCreate {
_c.mutation.SetGroupID(id)
return _c
}
// SetGroup sets the "group" edge to the Group entity.
func (_c *ItemCreate) SetGroup(v *Group) *ItemCreate {
return _c.SetGroupID(v.ID)
}
// SetParentID sets the "parent" edge to the Item entity by ID.
func (_c *ItemCreate) SetParentID(id uuid.UUID) *ItemCreate {
_c.mutation.SetParentID(id)
return _c
}
// SetNillableParentID sets the "parent" edge to the Item entity by ID if the given value is not nil.
func (_c *ItemCreate) SetNillableParentID(id *uuid.UUID) *ItemCreate {
if id != nil {
_c = _c.SetParentID(*id)
}
return _c
}
// SetParent sets the "parent" edge to the Item entity.
func (_c *ItemCreate) SetParent(v *Item) *ItemCreate {
return _c.SetParentID(v.ID)
}
// AddChildIDs adds the "children" edge to the Item entity by IDs.
func (_c *ItemCreate) AddChildIDs(ids ...uuid.UUID) *ItemCreate {
_c.mutation.AddChildIDs(ids...)
return _c
}
// AddChildren adds the "children" edges to the Item entity.
func (_c *ItemCreate) AddChildren(v ...*Item) *ItemCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddChildIDs(ids...)
}
// AddLabelIDs adds the "label" edge to the Label entity by IDs.
func (_c *ItemCreate) AddLabelIDs(ids ...uuid.UUID) *ItemCreate {
_c.mutation.AddLabelIDs(ids...)
return _c
}
// AddLabel adds the "label" edges to the Label entity.
func (_c *ItemCreate) AddLabel(v ...*Label) *ItemCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddLabelIDs(ids...)
}
// SetLocationID sets the "location" edge to the Location entity by ID.
func (_c *ItemCreate) SetLocationID(id uuid.UUID) *ItemCreate {
_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 *ItemCreate) SetNillableLocationID(id *uuid.UUID) *ItemCreate {
if id != nil {
_c = _c.SetLocationID(*id)
}
return _c
}
// SetLocation sets the "location" edge to the Location entity.
func (_c *ItemCreate) SetLocation(v *Location) *ItemCreate {
return _c.SetLocationID(v.ID)
}
// AddFieldIDs adds the "fields" edge to the ItemField entity by IDs.
func (_c *ItemCreate) AddFieldIDs(ids ...uuid.UUID) *ItemCreate {
_c.mutation.AddFieldIDs(ids...)
return _c
}
// AddFields adds the "fields" edges to the ItemField entity.
func (_c *ItemCreate) AddFields(v ...*ItemField) *ItemCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddFieldIDs(ids...)
}
// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
func (_c *ItemCreate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemCreate {
_c.mutation.AddMaintenanceEntryIDs(ids...)
return _c
}
// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
func (_c *ItemCreate) AddMaintenanceEntries(v ...*MaintenanceEntry) *ItemCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddMaintenanceEntryIDs(ids...)
}
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
func (_c *ItemCreate) AddAttachmentIDs(ids ...uuid.UUID) *ItemCreate {
_c.mutation.AddAttachmentIDs(ids...)
return _c
}
// AddAttachments adds the "attachments" edges to the Attachment entity.
func (_c *ItemCreate) AddAttachments(v ...*Attachment) *ItemCreate {
ids := make([]uuid.UUID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddAttachmentIDs(ids...)
}
// Mutation returns the ItemMutation object of the builder.
func (_c *ItemCreate) Mutation() *ItemMutation {
return _c.mutation
}
// Save creates the Item in the database.
func (_c *ItemCreate) Save(ctx context.Context) (*Item, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ItemCreate) SaveX(ctx context.Context) *Item {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ItemCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ItemCreate) 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 *ItemCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := item.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := item.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Quantity(); !ok {
v := item.DefaultQuantity
_c.mutation.SetQuantity(v)
}
if _, ok := _c.mutation.Insured(); !ok {
v := item.DefaultInsured
_c.mutation.SetInsured(v)
}
if _, ok := _c.mutation.Archived(); !ok {
v := item.DefaultArchived
_c.mutation.SetArchived(v)
}
if _, ok := _c.mutation.AssetID(); !ok {
v := item.DefaultAssetID
_c.mutation.SetAssetID(v)
}
if _, ok := _c.mutation.SyncChildItemsLocations(); !ok {
v := item.DefaultSyncChildItemsLocations
_c.mutation.SetSyncChildItemsLocations(v)
}
if _, ok := _c.mutation.LifetimeWarranty(); !ok {
v := item.DefaultLifetimeWarranty
_c.mutation.SetLifetimeWarranty(v)
}
if _, ok := _c.mutation.PurchasePrice(); !ok {
v := item.DefaultPurchasePrice
_c.mutation.SetPurchasePrice(v)
}
if _, ok := _c.mutation.SoldPrice(); !ok {
v := item.DefaultSoldPrice
_c.mutation.SetSoldPrice(v)
}
if _, ok := _c.mutation.ID(); !ok {
v := item.DefaultID()
_c.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ItemCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Item.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Item.updated_at"`)}
}
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Item.name"`)}
}
if v, ok := _c.mutation.Name(); ok {
if err := item.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Item.name": %w`, err)}
}
}
if v, ok := _c.mutation.Description(); ok {
if err := item.DescriptionValidator(v); err != nil {
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Item.description": %w`, err)}
}
}
if v, ok := _c.mutation.ImportRef(); ok {
if err := item.ImportRefValidator(v); err != nil {
return &ValidationError{Name: "import_ref", err: fmt.Errorf(`ent: validator failed for field "Item.import_ref": %w`, err)}
}
}
if v, ok := _c.mutation.Notes(); ok {
if err := item.NotesValidator(v); err != nil {
return &ValidationError{Name: "notes", err: fmt.Errorf(`ent: validator failed for field "Item.notes": %w`, err)}
}
}
if _, ok := _c.mutation.Quantity(); !ok {
return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "Item.quantity"`)}
}
if _, ok := _c.mutation.Insured(); !ok {
return &ValidationError{Name: "insured", err: errors.New(`ent: missing required field "Item.insured"`)}
}
if _, ok := _c.mutation.Archived(); !ok {
return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Item.archived"`)}
}
if _, ok := _c.mutation.AssetID(); !ok {
return &ValidationError{Name: "asset_id", err: errors.New(`ent: missing required field "Item.asset_id"`)}
}
if _, ok := _c.mutation.SyncChildItemsLocations(); !ok {
return &ValidationError{Name: "sync_child_items_locations", err: errors.New(`ent: missing required field "Item.sync_child_items_locations"`)}
}
if v, ok := _c.mutation.SerialNumber(); ok {
if err := item.SerialNumberValidator(v); err != nil {
return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)}
}
}
if v, ok := _c.mutation.ModelNumber(); ok {
if err := item.ModelNumberValidator(v); err != nil {
return &ValidationError{Name: "model_number", err: fmt.Errorf(`ent: validator failed for field "Item.model_number": %w`, err)}
}
}
if v, ok := _c.mutation.Manufacturer(); ok {
if err := item.ManufacturerValidator(v); err != nil {
return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)}
}
}
if _, ok := _c.mutation.LifetimeWarranty(); !ok {
return &ValidationError{Name: "lifetime_warranty", err: errors.New(`ent: missing required field "Item.lifetime_warranty"`)}
}
if v, ok := _c.mutation.WarrantyDetails(); ok {
if err := item.WarrantyDetailsValidator(v); err != nil {
return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)}
}
}
if _, ok := _c.mutation.PurchasePrice(); !ok {
return &ValidationError{Name: "purchase_price", err: errors.New(`ent: missing required field "Item.purchase_price"`)}
}
if _, ok := _c.mutation.SoldPrice(); !ok {
return &ValidationError{Name: "sold_price", err: errors.New(`ent: missing required field "Item.sold_price"`)}
}
if v, ok := _c.mutation.SoldNotes(); ok {
if err := item.SoldNotesValidator(v); err != nil {
return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)}
}
}
if len(_c.mutation.GroupIDs()) == 0 {
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Item.group"`)}
}
return nil
}
func (_c *ItemCreate) sqlSave(ctx context.Context) (*Item, 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 *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) {
var (
_node = &Item{config: _c.config}
_spec = sqlgraph.NewCreateSpec(item.Table, sqlgraph.NewFieldSpec(item.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(item.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(item.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(item.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.Description(); ok {
_spec.SetField(item.FieldDescription, field.TypeString, value)
_node.Description = value
}
if value, ok := _c.mutation.ImportRef(); ok {
_spec.SetField(item.FieldImportRef, field.TypeString, value)
_node.ImportRef = value
}
if value, ok := _c.mutation.Notes(); ok {
_spec.SetField(item.FieldNotes, field.TypeString, value)
_node.Notes = value
}
if value, ok := _c.mutation.Quantity(); ok {
_spec.SetField(item.FieldQuantity, field.TypeInt, value)
_node.Quantity = value
}
if value, ok := _c.mutation.Insured(); ok {
_spec.SetField(item.FieldInsured, field.TypeBool, value)
_node.Insured = value
}
if value, ok := _c.mutation.Archived(); ok {
_spec.SetField(item.FieldArchived, field.TypeBool, value)
_node.Archived = value
}
if value, ok := _c.mutation.AssetID(); ok {
_spec.SetField(item.FieldAssetID, field.TypeInt, value)
_node.AssetID = value
}
if value, ok := _c.mutation.SyncChildItemsLocations(); ok {
_spec.SetField(item.FieldSyncChildItemsLocations, field.TypeBool, value)
_node.SyncChildItemsLocations = value
}
if value, ok := _c.mutation.SerialNumber(); ok {
_spec.SetField(item.FieldSerialNumber, field.TypeString, value)
_node.SerialNumber = value
}
if value, ok := _c.mutation.ModelNumber(); ok {
_spec.SetField(item.FieldModelNumber, field.TypeString, value)
_node.ModelNumber = value
}
if value, ok := _c.mutation.Manufacturer(); ok {
_spec.SetField(item.FieldManufacturer, field.TypeString, value)
_node.Manufacturer = value
}
if value, ok := _c.mutation.LifetimeWarranty(); ok {
_spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value)
_node.LifetimeWarranty = value
}
if value, ok := _c.mutation.WarrantyExpires(); ok {
_spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value)
_node.WarrantyExpires = value
}
if value, ok := _c.mutation.WarrantyDetails(); ok {
_spec.SetField(item.FieldWarrantyDetails, field.TypeString, value)
_node.WarrantyDetails = value
}
if value, ok := _c.mutation.PurchaseTime(); ok {
_spec.SetField(item.FieldPurchaseTime, field.TypeTime, value)
_node.PurchaseTime = value
}
if value, ok := _c.mutation.PurchaseFrom(); ok {
_spec.SetField(item.FieldPurchaseFrom, field.TypeString, value)
_node.PurchaseFrom = value
}
if value, ok := _c.mutation.PurchasePrice(); ok {
_spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value)
_node.PurchasePrice = value
}
if value, ok := _c.mutation.SoldTime(); ok {
_spec.SetField(item.FieldSoldTime, field.TypeTime, value)
_node.SoldTime = value
}
if value, ok := _c.mutation.SoldTo(); ok {
_spec.SetField(item.FieldSoldTo, field.TypeString, value)
_node.SoldTo = value
}
if value, ok := _c.mutation.SoldPrice(); ok {
_spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value)
_node.SoldPrice = value
}
if value, ok := _c.mutation.SoldNotes(); ok {
_spec.SetField(item.FieldSoldNotes, field.TypeString, value)
_node.SoldNotes = value
}
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: item.GroupTable,
Columns: []string{item.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_items = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: item.ParentTable,
Columns: []string{item.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.item_children = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.ChildrenTable,
Columns: []string{item.ChildrenColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(item.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.LabelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: item.LabelTable,
Columns: item.LabelPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(label.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: true,
Table: item.LocationTable,
Columns: []string{item.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.location_items = &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: item.FieldsTable,
Columns: []string{item.FieldsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(itemfield.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.MaintenanceEntriesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.MaintenanceEntriesTable,
Columns: []string{item.MaintenanceEntriesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(maintenanceentry.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.AttachmentsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: item.AttachmentsTable,
Columns: []string{item.AttachmentsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// ItemCreateBulk is the builder for creating many Item entities in bulk.
type ItemCreateBulk struct {
config
err error
builders []*ItemCreate
}
// Save creates the Item entities in the database.
func (_c *ItemCreateBulk) Save(ctx context.Context) ([]*Item, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Item, 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.(*ItemMutation)
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 *ItemCreateBulk) SaveX(ctx context.Context) []*Item {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ItemCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ItemCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}