mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
* 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>
691 lines
20 KiB
Go
Generated
691 lines
20 KiB
Go
Generated
// 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/item"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
)
|
|
|
|
// ItemFieldUpdate is the builder for updating ItemField entities.
|
|
type ItemFieldUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ItemFieldMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ItemFieldUpdate builder.
|
|
func (_u *ItemFieldUpdate) Where(ps ...predicate.ItemField) *ItemFieldUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ItemFieldUpdate) SetUpdatedAt(v time.Time) *ItemFieldUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ItemFieldUpdate) SetName(v string) *ItemFieldUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableName(v *string) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *ItemFieldUpdate) SetDescription(v string) *ItemFieldUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableDescription(v *string) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *ItemFieldUpdate) ClearDescription() *ItemFieldUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *ItemFieldUpdate) SetType(v itemfield.Type) *ItemFieldUpdate {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableType(v *itemfield.Type) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTextValue sets the "text_value" field.
|
|
func (_u *ItemFieldUpdate) SetTextValue(v string) *ItemFieldUpdate {
|
|
_u.mutation.SetTextValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTextValue sets the "text_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableTextValue(v *string) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetTextValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTextValue clears the value of the "text_value" field.
|
|
func (_u *ItemFieldUpdate) ClearTextValue() *ItemFieldUpdate {
|
|
_u.mutation.ClearTextValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNumberValue sets the "number_value" field.
|
|
func (_u *ItemFieldUpdate) SetNumberValue(v int) *ItemFieldUpdate {
|
|
_u.mutation.ResetNumberValue()
|
|
_u.mutation.SetNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNumberValue sets the "number_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableNumberValue(v *int) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetNumberValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNumberValue adds value to the "number_value" field.
|
|
func (_u *ItemFieldUpdate) AddNumberValue(v int) *ItemFieldUpdate {
|
|
_u.mutation.AddNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNumberValue clears the value of the "number_value" field.
|
|
func (_u *ItemFieldUpdate) ClearNumberValue() *ItemFieldUpdate {
|
|
_u.mutation.ClearNumberValue()
|
|
return _u
|
|
}
|
|
|
|
// SetBooleanValue sets the "boolean_value" field.
|
|
func (_u *ItemFieldUpdate) SetBooleanValue(v bool) *ItemFieldUpdate {
|
|
_u.mutation.SetBooleanValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableBooleanValue(v *bool) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetBooleanValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTimeValue sets the "time_value" field.
|
|
func (_u *ItemFieldUpdate) SetTimeValue(v time.Time) *ItemFieldUpdate {
|
|
_u.mutation.SetTimeValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTimeValue sets the "time_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableTimeValue(v *time.Time) *ItemFieldUpdate {
|
|
if v != nil {
|
|
_u.SetTimeValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (_u *ItemFieldUpdate) SetItemID(id uuid.UUID) *ItemFieldUpdate {
|
|
_u.mutation.SetItemID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil.
|
|
func (_u *ItemFieldUpdate) SetNillableItemID(id *uuid.UUID) *ItemFieldUpdate {
|
|
if id != nil {
|
|
_u = _u.SetItemID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *ItemFieldUpdate) SetItem(v *Item) *ItemFieldUpdate {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the ItemFieldMutation object of the builder.
|
|
func (_u *ItemFieldUpdate) Mutation() *ItemFieldMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *ItemFieldUpdate) ClearItem() *ItemFieldUpdate {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *ItemFieldUpdate) 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 *ItemFieldUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *ItemFieldUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ItemFieldUpdate) 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 *ItemFieldUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := itemfield.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ItemFieldUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := itemfield.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemField.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := itemfield.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemField.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := itemfield.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ItemField.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TextValue(); ok {
|
|
if err := itemfield.TextValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "ItemField.text_value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ItemFieldUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.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(itemfield.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(itemfield.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(itemfield.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(itemfield.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(itemfield.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.TextValue(); ok {
|
|
_spec.SetField(itemfield.FieldTextValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextValueCleared() {
|
|
_spec.ClearField(itemfield.FieldTextValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NumberValue(); ok {
|
|
_spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNumberValue(); ok {
|
|
_spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NumberValueCleared() {
|
|
_spec.ClearField(itemfield.FieldNumberValue, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.BooleanValue(); ok {
|
|
_spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.TimeValue(); ok {
|
|
_spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: itemfield.ItemTable,
|
|
Columns: []string{itemfield.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: itemfield.ItemTable,
|
|
Columns: []string{itemfield.ItemColumn},
|
|
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.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{itemfield.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// ItemFieldUpdateOne is the builder for updating a single ItemField entity.
|
|
type ItemFieldUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ItemFieldMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *ItemFieldUpdateOne) SetUpdatedAt(v time.Time) *ItemFieldUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ItemFieldUpdateOne) SetName(v string) *ItemFieldUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableName(v *string) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *ItemFieldUpdateOne) SetDescription(v string) *ItemFieldUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableDescription(v *string) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *ItemFieldUpdateOne) ClearDescription() *ItemFieldUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *ItemFieldUpdateOne) SetType(v itemfield.Type) *ItemFieldUpdateOne {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableType(v *itemfield.Type) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTextValue sets the "text_value" field.
|
|
func (_u *ItemFieldUpdateOne) SetTextValue(v string) *ItemFieldUpdateOne {
|
|
_u.mutation.SetTextValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTextValue sets the "text_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableTextValue(v *string) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetTextValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTextValue clears the value of the "text_value" field.
|
|
func (_u *ItemFieldUpdateOne) ClearTextValue() *ItemFieldUpdateOne {
|
|
_u.mutation.ClearTextValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNumberValue sets the "number_value" field.
|
|
func (_u *ItemFieldUpdateOne) SetNumberValue(v int) *ItemFieldUpdateOne {
|
|
_u.mutation.ResetNumberValue()
|
|
_u.mutation.SetNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNumberValue sets the "number_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableNumberValue(v *int) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetNumberValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNumberValue adds value to the "number_value" field.
|
|
func (_u *ItemFieldUpdateOne) AddNumberValue(v int) *ItemFieldUpdateOne {
|
|
_u.mutation.AddNumberValue(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNumberValue clears the value of the "number_value" field.
|
|
func (_u *ItemFieldUpdateOne) ClearNumberValue() *ItemFieldUpdateOne {
|
|
_u.mutation.ClearNumberValue()
|
|
return _u
|
|
}
|
|
|
|
// SetBooleanValue sets the "boolean_value" field.
|
|
func (_u *ItemFieldUpdateOne) SetBooleanValue(v bool) *ItemFieldUpdateOne {
|
|
_u.mutation.SetBooleanValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBooleanValue sets the "boolean_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableBooleanValue(v *bool) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetBooleanValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTimeValue sets the "time_value" field.
|
|
func (_u *ItemFieldUpdateOne) SetTimeValue(v time.Time) *ItemFieldUpdateOne {
|
|
_u.mutation.SetTimeValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTimeValue sets the "time_value" field if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableTimeValue(v *time.Time) *ItemFieldUpdateOne {
|
|
if v != nil {
|
|
_u.SetTimeValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemID sets the "item" edge to the Item entity by ID.
|
|
func (_u *ItemFieldUpdateOne) SetItemID(id uuid.UUID) *ItemFieldUpdateOne {
|
|
_u.mutation.SetItemID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemID sets the "item" edge to the Item entity by ID if the given value is not nil.
|
|
func (_u *ItemFieldUpdateOne) SetNillableItemID(id *uuid.UUID) *ItemFieldUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetItemID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItem sets the "item" edge to the Item entity.
|
|
func (_u *ItemFieldUpdateOne) SetItem(v *Item) *ItemFieldUpdateOne {
|
|
return _u.SetItemID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the ItemFieldMutation object of the builder.
|
|
func (_u *ItemFieldUpdateOne) Mutation() *ItemFieldMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearItem clears the "item" edge to the Item entity.
|
|
func (_u *ItemFieldUpdateOne) ClearItem() *ItemFieldUpdateOne {
|
|
_u.mutation.ClearItem()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the ItemFieldUpdate builder.
|
|
func (_u *ItemFieldUpdateOne) Where(ps ...predicate.ItemField) *ItemFieldUpdateOne {
|
|
_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 *ItemFieldUpdateOne) Select(field string, fields ...string) *ItemFieldUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated ItemField entity.
|
|
func (_u *ItemFieldUpdateOne) Save(ctx context.Context) (*ItemField, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ItemFieldUpdateOne) SaveX(ctx context.Context) *ItemField {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *ItemFieldUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ItemFieldUpdateOne) 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 *ItemFieldUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := itemfield.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *ItemFieldUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := itemfield.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ItemField.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := itemfield.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ItemField.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := itemfield.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ItemField.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TextValue(); ok {
|
|
if err := itemfield.TextValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "text_value", err: fmt.Errorf(`ent: validator failed for field "ItemField.text_value": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ItemField.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, itemfield.FieldID)
|
|
for _, f := range fields {
|
|
if !itemfield.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != itemfield.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(itemfield.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(itemfield.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(itemfield.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(itemfield.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(itemfield.FieldType, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.TextValue(); ok {
|
|
_spec.SetField(itemfield.FieldTextValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextValueCleared() {
|
|
_spec.ClearField(itemfield.FieldTextValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NumberValue(); ok {
|
|
_spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNumberValue(); ok {
|
|
_spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NumberValueCleared() {
|
|
_spec.ClearField(itemfield.FieldNumberValue, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.BooleanValue(); ok {
|
|
_spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.TimeValue(); ok {
|
|
_spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.ItemCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: itemfield.ItemTable,
|
|
Columns: []string{itemfield.ItemColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: itemfield.ItemTable,
|
|
Columns: []string{itemfield.ItemColumn},
|
|
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.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &ItemField{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{itemfield.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|