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>
868 lines
25 KiB
Go
Generated
868 lines
25 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/group"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/item"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/location"
|
|
"github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate"
|
|
)
|
|
|
|
// LocationUpdate is the builder for updating Location entities.
|
|
type LocationUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *LocationMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the LocationUpdate builder.
|
|
func (_u *LocationUpdate) Where(ps ...predicate.Location) *LocationUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *LocationUpdate) SetUpdatedAt(v time.Time) *LocationUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *LocationUpdate) SetName(v string) *LocationUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *LocationUpdate) SetNillableName(v *string) *LocationUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *LocationUpdate) SetDescription(v string) *LocationUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *LocationUpdate) SetNillableDescription(v *string) *LocationUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *LocationUpdate) ClearDescription() *LocationUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
func (_u *LocationUpdate) SetGroupID(id uuid.UUID) *LocationUpdate {
|
|
_u.mutation.SetGroupID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
func (_u *LocationUpdate) SetGroup(v *Group) *LocationUpdate {
|
|
return _u.SetGroupID(v.ID)
|
|
}
|
|
|
|
// SetParentID sets the "parent" edge to the Location entity by ID.
|
|
func (_u *LocationUpdate) SetParentID(id uuid.UUID) *LocationUpdate {
|
|
_u.mutation.SetParentID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil.
|
|
func (_u *LocationUpdate) SetNillableParentID(id *uuid.UUID) *LocationUpdate {
|
|
if id != nil {
|
|
_u = _u.SetParentID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetParent sets the "parent" edge to the Location entity.
|
|
func (_u *LocationUpdate) SetParent(v *Location) *LocationUpdate {
|
|
return _u.SetParentID(v.ID)
|
|
}
|
|
|
|
// AddChildIDs adds the "children" edge to the Location entity by IDs.
|
|
func (_u *LocationUpdate) AddChildIDs(ids ...uuid.UUID) *LocationUpdate {
|
|
_u.mutation.AddChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddChildren adds the "children" edges to the Location entity.
|
|
func (_u *LocationUpdate) AddChildren(v ...*Location) *LocationUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddChildIDs(ids...)
|
|
}
|
|
|
|
// AddItemIDs adds the "items" edge to the Item entity by IDs.
|
|
func (_u *LocationUpdate) AddItemIDs(ids ...uuid.UUID) *LocationUpdate {
|
|
_u.mutation.AddItemIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddItems adds the "items" edges to the Item entity.
|
|
func (_u *LocationUpdate) AddItems(v ...*Item) *LocationUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddItemIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the LocationMutation object of the builder.
|
|
func (_u *LocationUpdate) Mutation() *LocationMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
func (_u *LocationUpdate) ClearGroup() *LocationUpdate {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// ClearParent clears the "parent" edge to the Location entity.
|
|
func (_u *LocationUpdate) ClearParent() *LocationUpdate {
|
|
_u.mutation.ClearParent()
|
|
return _u
|
|
}
|
|
|
|
// ClearChildren clears all "children" edges to the Location entity.
|
|
func (_u *LocationUpdate) ClearChildren() *LocationUpdate {
|
|
_u.mutation.ClearChildren()
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildIDs removes the "children" edge to Location entities by IDs.
|
|
func (_u *LocationUpdate) RemoveChildIDs(ids ...uuid.UUID) *LocationUpdate {
|
|
_u.mutation.RemoveChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildren removes "children" edges to Location entities.
|
|
func (_u *LocationUpdate) RemoveChildren(v ...*Location) *LocationUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveChildIDs(ids...)
|
|
}
|
|
|
|
// ClearItems clears all "items" edges to the Item entity.
|
|
func (_u *LocationUpdate) ClearItems() *LocationUpdate {
|
|
_u.mutation.ClearItems()
|
|
return _u
|
|
}
|
|
|
|
// RemoveItemIDs removes the "items" edge to Item entities by IDs.
|
|
func (_u *LocationUpdate) RemoveItemIDs(ids ...uuid.UUID) *LocationUpdate {
|
|
_u.mutation.RemoveItemIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveItems removes "items" edges to Item entities.
|
|
func (_u *LocationUpdate) RemoveItems(v ...*Item) *LocationUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveItemIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *LocationUpdate) 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 *LocationUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *LocationUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *LocationUpdate) 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 *LocationUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := location.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *LocationUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := location.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Location.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := location.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "Location.group"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *LocationUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.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(location.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(location.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(location.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(location.FieldDescription, field.TypeString)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.GroupTable,
|
|
Columns: []string{location.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: location.GroupTable,
|
|
Columns: []string{location.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.ParentCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.ParentTable,
|
|
Columns: []string{location.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.ParentTable,
|
|
Columns: []string{location.ParentColumn},
|
|
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 _u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
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 _u.mutation.ItemsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedItemsIDs(); len(nodes) > 0 && !_u.mutation.ItemsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
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{location.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// LocationUpdateOne is the builder for updating a single Location entity.
|
|
type LocationUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *LocationMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *LocationUpdateOne) SetUpdatedAt(v time.Time) *LocationUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *LocationUpdateOne) SetName(v string) *LocationUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *LocationUpdateOne) SetNillableName(v *string) *LocationUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *LocationUpdateOne) SetDescription(v string) *LocationUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *LocationUpdateOne) SetNillableDescription(v *string) *LocationUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *LocationUpdateOne) ClearDescription() *LocationUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
func (_u *LocationUpdateOne) SetGroupID(id uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.SetGroupID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
func (_u *LocationUpdateOne) SetGroup(v *Group) *LocationUpdateOne {
|
|
return _u.SetGroupID(v.ID)
|
|
}
|
|
|
|
// SetParentID sets the "parent" edge to the Location entity by ID.
|
|
func (_u *LocationUpdateOne) SetParentID(id uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.SetParentID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil.
|
|
func (_u *LocationUpdateOne) SetNillableParentID(id *uuid.UUID) *LocationUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetParentID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetParent sets the "parent" edge to the Location entity.
|
|
func (_u *LocationUpdateOne) SetParent(v *Location) *LocationUpdateOne {
|
|
return _u.SetParentID(v.ID)
|
|
}
|
|
|
|
// AddChildIDs adds the "children" edge to the Location entity by IDs.
|
|
func (_u *LocationUpdateOne) AddChildIDs(ids ...uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.AddChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddChildren adds the "children" edges to the Location entity.
|
|
func (_u *LocationUpdateOne) AddChildren(v ...*Location) *LocationUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddChildIDs(ids...)
|
|
}
|
|
|
|
// AddItemIDs adds the "items" edge to the Item entity by IDs.
|
|
func (_u *LocationUpdateOne) AddItemIDs(ids ...uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.AddItemIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddItems adds the "items" edges to the Item entity.
|
|
func (_u *LocationUpdateOne) AddItems(v ...*Item) *LocationUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddItemIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the LocationMutation object of the builder.
|
|
func (_u *LocationUpdateOne) Mutation() *LocationMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
func (_u *LocationUpdateOne) ClearGroup() *LocationUpdateOne {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// ClearParent clears the "parent" edge to the Location entity.
|
|
func (_u *LocationUpdateOne) ClearParent() *LocationUpdateOne {
|
|
_u.mutation.ClearParent()
|
|
return _u
|
|
}
|
|
|
|
// ClearChildren clears all "children" edges to the Location entity.
|
|
func (_u *LocationUpdateOne) ClearChildren() *LocationUpdateOne {
|
|
_u.mutation.ClearChildren()
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildIDs removes the "children" edge to Location entities by IDs.
|
|
func (_u *LocationUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.RemoveChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildren removes "children" edges to Location entities.
|
|
func (_u *LocationUpdateOne) RemoveChildren(v ...*Location) *LocationUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveChildIDs(ids...)
|
|
}
|
|
|
|
// ClearItems clears all "items" edges to the Item entity.
|
|
func (_u *LocationUpdateOne) ClearItems() *LocationUpdateOne {
|
|
_u.mutation.ClearItems()
|
|
return _u
|
|
}
|
|
|
|
// RemoveItemIDs removes the "items" edge to Item entities by IDs.
|
|
func (_u *LocationUpdateOne) RemoveItemIDs(ids ...uuid.UUID) *LocationUpdateOne {
|
|
_u.mutation.RemoveItemIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveItems removes "items" edges to Item entities.
|
|
func (_u *LocationUpdateOne) RemoveItems(v ...*Item) *LocationUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveItemIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the LocationUpdate builder.
|
|
func (_u *LocationUpdateOne) Where(ps ...predicate.Location) *LocationUpdateOne {
|
|
_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 *LocationUpdateOne) Select(field string, fields ...string) *LocationUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Location entity.
|
|
func (_u *LocationUpdateOne) Save(ctx context.Context) (*Location, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *LocationUpdateOne) SaveX(ctx context.Context) *Location {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *LocationUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *LocationUpdateOne) 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 *LocationUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := location.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *LocationUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := location.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Location.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := location.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)}
|
|
}
|
|
}
|
|
if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
|
|
return errors.New(`ent: clearing a required unique edge "Location.group"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Location.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, location.FieldID)
|
|
for _, f := range fields {
|
|
if !location.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != location.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(location.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(location.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(location.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(location.FieldDescription, field.TypeString)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.GroupTable,
|
|
Columns: []string{location.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: location.GroupTable,
|
|
Columns: []string{location.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.ParentCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.ParentTable,
|
|
Columns: []string{location.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: location.ParentTable,
|
|
Columns: []string{location.ParentColumn},
|
|
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 _u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ChildrenTable,
|
|
Columns: []string{location.ChildrenColumn},
|
|
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 _u.mutation.ItemsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedItemsIDs(); len(nodes) > 0 && !_u.mutation.ItemsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
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.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ItemsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: location.ItemsTable,
|
|
Columns: []string{location.ItemsColumn},
|
|
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 = &Location{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{location.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|