mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-30 20:45:40 +00:00
407 lines
12 KiB
Go
407 lines
12 KiB
Go
|
// 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/hay-kot/homebox/backend/internal/data/ent/actiontoken"
|
||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||
|
)
|
||
|
|
||
|
// ActionTokenUpdate is the builder for updating ActionToken entities.
|
||
|
type ActionTokenUpdate struct {
|
||
|
config
|
||
|
hooks []Hook
|
||
|
mutation *ActionTokenMutation
|
||
|
}
|
||
|
|
||
|
// Where appends a list predicates to the ActionTokenUpdate builder.
|
||
|
func (atu *ActionTokenUpdate) Where(ps ...predicate.ActionToken) *ActionTokenUpdate {
|
||
|
atu.mutation.Where(ps...)
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetUserID sets the "user_id" field.
|
||
|
func (atu *ActionTokenUpdate) SetUserID(u uuid.UUID) *ActionTokenUpdate {
|
||
|
atu.mutation.SetUserID(u)
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||
|
func (atu *ActionTokenUpdate) SetNillableUserID(u *uuid.UUID) *ActionTokenUpdate {
|
||
|
if u != nil {
|
||
|
atu.SetUserID(*u)
|
||
|
}
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (atu *ActionTokenUpdate) SetUpdatedAt(t time.Time) *ActionTokenUpdate {
|
||
|
atu.mutation.SetUpdatedAt(t)
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetAction sets the "action" field.
|
||
|
func (atu *ActionTokenUpdate) SetAction(a actiontoken.Action) *ActionTokenUpdate {
|
||
|
atu.mutation.SetAction(a)
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetNillableAction sets the "action" field if the given value is not nil.
|
||
|
func (atu *ActionTokenUpdate) SetNillableAction(a *actiontoken.Action) *ActionTokenUpdate {
|
||
|
if a != nil {
|
||
|
atu.SetAction(*a)
|
||
|
}
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetToken sets the "token" field.
|
||
|
func (atu *ActionTokenUpdate) SetToken(b []byte) *ActionTokenUpdate {
|
||
|
atu.mutation.SetToken(b)
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// SetUser sets the "user" edge to the User entity.
|
||
|
func (atu *ActionTokenUpdate) SetUser(u *User) *ActionTokenUpdate {
|
||
|
return atu.SetUserID(u.ID)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the ActionTokenMutation object of the builder.
|
||
|
func (atu *ActionTokenUpdate) Mutation() *ActionTokenMutation {
|
||
|
return atu.mutation
|
||
|
}
|
||
|
|
||
|
// ClearUser clears the "user" edge to the User entity.
|
||
|
func (atu *ActionTokenUpdate) ClearUser() *ActionTokenUpdate {
|
||
|
atu.mutation.ClearUser()
|
||
|
return atu
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
func (atu *ActionTokenUpdate) Save(ctx context.Context) (int, error) {
|
||
|
atu.defaults()
|
||
|
return withHooks(ctx, atu.sqlSave, atu.mutation, atu.hooks)
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (atu *ActionTokenUpdate) SaveX(ctx context.Context) int {
|
||
|
affected, err := atu.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return affected
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (atu *ActionTokenUpdate) Exec(ctx context.Context) error {
|
||
|
_, err := atu.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (atu *ActionTokenUpdate) ExecX(ctx context.Context) {
|
||
|
if err := atu.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (atu *ActionTokenUpdate) defaults() {
|
||
|
if _, ok := atu.mutation.UpdatedAt(); !ok {
|
||
|
v := actiontoken.UpdateDefaultUpdatedAt()
|
||
|
atu.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (atu *ActionTokenUpdate) check() error {
|
||
|
if v, ok := atu.mutation.Action(); ok {
|
||
|
if err := actiontoken.ActionValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "ActionToken.action": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if _, ok := atu.mutation.UserID(); atu.mutation.UserCleared() && !ok {
|
||
|
return errors.New(`ent: clearing a required unique edge "ActionToken.user"`)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (atu *ActionTokenUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||
|
if err := atu.check(); err != nil {
|
||
|
return n, err
|
||
|
}
|
||
|
_spec := sqlgraph.NewUpdateSpec(actiontoken.Table, actiontoken.Columns, sqlgraph.NewFieldSpec(actiontoken.FieldID, field.TypeUUID))
|
||
|
if ps := atu.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := atu.mutation.UpdatedAt(); ok {
|
||
|
_spec.SetField(actiontoken.FieldUpdatedAt, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := atu.mutation.Action(); ok {
|
||
|
_spec.SetField(actiontoken.FieldAction, field.TypeEnum, value)
|
||
|
}
|
||
|
if value, ok := atu.mutation.Token(); ok {
|
||
|
_spec.SetField(actiontoken.FieldToken, field.TypeBytes, value)
|
||
|
}
|
||
|
if atu.mutation.UserCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: actiontoken.UserTable,
|
||
|
Columns: []string{actiontoken.UserColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := atu.mutation.UserIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: actiontoken.UserTable,
|
||
|
Columns: []string{actiontoken.UserColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
if n, err = sqlgraph.UpdateNodes(ctx, atu.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{actiontoken.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return 0, err
|
||
|
}
|
||
|
atu.mutation.done = true
|
||
|
return n, nil
|
||
|
}
|
||
|
|
||
|
// ActionTokenUpdateOne is the builder for updating a single ActionToken entity.
|
||
|
type ActionTokenUpdateOne struct {
|
||
|
config
|
||
|
fields []string
|
||
|
hooks []Hook
|
||
|
mutation *ActionTokenMutation
|
||
|
}
|
||
|
|
||
|
// SetUserID sets the "user_id" field.
|
||
|
func (atuo *ActionTokenUpdateOne) SetUserID(u uuid.UUID) *ActionTokenUpdateOne {
|
||
|
atuo.mutation.SetUserID(u)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||
|
func (atuo *ActionTokenUpdateOne) SetNillableUserID(u *uuid.UUID) *ActionTokenUpdateOne {
|
||
|
if u != nil {
|
||
|
atuo.SetUserID(*u)
|
||
|
}
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (atuo *ActionTokenUpdateOne) SetUpdatedAt(t time.Time) *ActionTokenUpdateOne {
|
||
|
atuo.mutation.SetUpdatedAt(t)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetAction sets the "action" field.
|
||
|
func (atuo *ActionTokenUpdateOne) SetAction(a actiontoken.Action) *ActionTokenUpdateOne {
|
||
|
atuo.mutation.SetAction(a)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetNillableAction sets the "action" field if the given value is not nil.
|
||
|
func (atuo *ActionTokenUpdateOne) SetNillableAction(a *actiontoken.Action) *ActionTokenUpdateOne {
|
||
|
if a != nil {
|
||
|
atuo.SetAction(*a)
|
||
|
}
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetToken sets the "token" field.
|
||
|
func (atuo *ActionTokenUpdateOne) SetToken(b []byte) *ActionTokenUpdateOne {
|
||
|
atuo.mutation.SetToken(b)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// SetUser sets the "user" edge to the User entity.
|
||
|
func (atuo *ActionTokenUpdateOne) SetUser(u *User) *ActionTokenUpdateOne {
|
||
|
return atuo.SetUserID(u.ID)
|
||
|
}
|
||
|
|
||
|
// Mutation returns the ActionTokenMutation object of the builder.
|
||
|
func (atuo *ActionTokenUpdateOne) Mutation() *ActionTokenMutation {
|
||
|
return atuo.mutation
|
||
|
}
|
||
|
|
||
|
// ClearUser clears the "user" edge to the User entity.
|
||
|
func (atuo *ActionTokenUpdateOne) ClearUser() *ActionTokenUpdateOne {
|
||
|
atuo.mutation.ClearUser()
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// Where appends a list predicates to the ActionTokenUpdate builder.
|
||
|
func (atuo *ActionTokenUpdateOne) Where(ps ...predicate.ActionToken) *ActionTokenUpdateOne {
|
||
|
atuo.mutation.Where(ps...)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||
|
// The default is selecting all fields defined in the entity schema.
|
||
|
func (atuo *ActionTokenUpdateOne) Select(field string, fields ...string) *ActionTokenUpdateOne {
|
||
|
atuo.fields = append([]string{field}, fields...)
|
||
|
return atuo
|
||
|
}
|
||
|
|
||
|
// Save executes the query and returns the updated ActionToken entity.
|
||
|
func (atuo *ActionTokenUpdateOne) Save(ctx context.Context) (*ActionToken, error) {
|
||
|
atuo.defaults()
|
||
|
return withHooks(ctx, atuo.sqlSave, atuo.mutation, atuo.hooks)
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (atuo *ActionTokenUpdateOne) SaveX(ctx context.Context) *ActionToken {
|
||
|
node, err := atuo.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// Exec executes the query on the entity.
|
||
|
func (atuo *ActionTokenUpdateOne) Exec(ctx context.Context) error {
|
||
|
_, err := atuo.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (atuo *ActionTokenUpdateOne) ExecX(ctx context.Context) {
|
||
|
if err := atuo.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (atuo *ActionTokenUpdateOne) defaults() {
|
||
|
if _, ok := atuo.mutation.UpdatedAt(); !ok {
|
||
|
v := actiontoken.UpdateDefaultUpdatedAt()
|
||
|
atuo.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (atuo *ActionTokenUpdateOne) check() error {
|
||
|
if v, ok := atuo.mutation.Action(); ok {
|
||
|
if err := actiontoken.ActionValidator(v); err != nil {
|
||
|
return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "ActionToken.action": %w`, err)}
|
||
|
}
|
||
|
}
|
||
|
if _, ok := atuo.mutation.UserID(); atuo.mutation.UserCleared() && !ok {
|
||
|
return errors.New(`ent: clearing a required unique edge "ActionToken.user"`)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (atuo *ActionTokenUpdateOne) sqlSave(ctx context.Context) (_node *ActionToken, err error) {
|
||
|
if err := atuo.check(); err != nil {
|
||
|
return _node, err
|
||
|
}
|
||
|
_spec := sqlgraph.NewUpdateSpec(actiontoken.Table, actiontoken.Columns, sqlgraph.NewFieldSpec(actiontoken.FieldID, field.TypeUUID))
|
||
|
id, ok := atuo.mutation.ID()
|
||
|
if !ok {
|
||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ActionToken.id" for update`)}
|
||
|
}
|
||
|
_spec.Node.ID.Value = id
|
||
|
if fields := atuo.fields; len(fields) > 0 {
|
||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, actiontoken.FieldID)
|
||
|
for _, f := range fields {
|
||
|
if !actiontoken.ValidColumn(f) {
|
||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
}
|
||
|
if f != actiontoken.FieldID {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ps := atuo.mutation.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if value, ok := atuo.mutation.UpdatedAt(); ok {
|
||
|
_spec.SetField(actiontoken.FieldUpdatedAt, field.TypeTime, value)
|
||
|
}
|
||
|
if value, ok := atuo.mutation.Action(); ok {
|
||
|
_spec.SetField(actiontoken.FieldAction, field.TypeEnum, value)
|
||
|
}
|
||
|
if value, ok := atuo.mutation.Token(); ok {
|
||
|
_spec.SetField(actiontoken.FieldToken, field.TypeBytes, value)
|
||
|
}
|
||
|
if atuo.mutation.UserCleared() {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: actiontoken.UserTable,
|
||
|
Columns: []string{actiontoken.UserColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||
|
},
|
||
|
}
|
||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
}
|
||
|
if nodes := atuo.mutation.UserIDs(); len(nodes) > 0 {
|
||
|
edge := &sqlgraph.EdgeSpec{
|
||
|
Rel: sqlgraph.M2O,
|
||
|
Inverse: true,
|
||
|
Table: actiontoken.UserTable,
|
||
|
Columns: []string{actiontoken.UserColumn},
|
||
|
Bidi: false,
|
||
|
Target: &sqlgraph.EdgeTarget{
|
||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||
|
},
|
||
|
}
|
||
|
for _, k := range nodes {
|
||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
}
|
||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
}
|
||
|
_node = &ActionToken{config: atuo.config}
|
||
|
_spec.Assign = _node.assignValues
|
||
|
_spec.ScanValues = _node.scanValues
|
||
|
if err = sqlgraph.UpdateNode(ctx, atuo.driver, _spec); err != nil {
|
||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
err = &NotFoundError{actiontoken.Label}
|
||
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
}
|
||
|
return nil, err
|
||
|
}
|
||
|
atuo.mutation.done = true
|
||
|
return _node, nil
|
||
|
}
|