accountserver/ent/email_update.go

492 lines
14 KiB
Go
Raw Normal View History

2024-08-19 13:55:36 +02:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"code.icod.de/auth/accountserver/ent/account"
"code.icod.de/auth/accountserver/ent/email"
"code.icod.de/auth/accountserver/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// EmailUpdate is the builder for updating Email entities.
type EmailUpdate struct {
config
hooks []Hook
mutation *EmailMutation
}
// Where appends a list predicates to the EmailUpdate builder.
func (eu *EmailUpdate) Where(ps ...predicate.Email) *EmailUpdate {
eu.mutation.Where(ps...)
return eu
}
// SetEmail sets the "email" field.
func (eu *EmailUpdate) SetEmail(s string) *EmailUpdate {
eu.mutation.SetEmail(s)
return eu
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (eu *EmailUpdate) SetNillableEmail(s *string) *EmailUpdate {
if s != nil {
eu.SetEmail(*s)
}
return eu
}
// SetPrimary sets the "primary" field.
func (eu *EmailUpdate) SetPrimary(b bool) *EmailUpdate {
eu.mutation.SetPrimary(b)
return eu
}
// SetNillablePrimary sets the "primary" field if the given value is not nil.
func (eu *EmailUpdate) SetNillablePrimary(b *bool) *EmailUpdate {
if b != nil {
eu.SetPrimary(*b)
}
return eu
}
// SetVerified sets the "verified" field.
func (eu *EmailUpdate) SetVerified(b bool) *EmailUpdate {
eu.mutation.SetVerified(b)
return eu
}
// SetNillableVerified sets the "verified" field if the given value is not nil.
func (eu *EmailUpdate) SetNillableVerified(b *bool) *EmailUpdate {
if b != nil {
eu.SetVerified(*b)
}
return eu
}
// SetVerificationCode sets the "verification_code" field.
func (eu *EmailUpdate) SetVerificationCode(s string) *EmailUpdate {
eu.mutation.SetVerificationCode(s)
return eu
}
// SetNillableVerificationCode sets the "verification_code" field if the given value is not nil.
func (eu *EmailUpdate) SetNillableVerificationCode(s *string) *EmailUpdate {
if s != nil {
eu.SetVerificationCode(*s)
}
return eu
}
// ClearVerificationCode clears the value of the "verification_code" field.
func (eu *EmailUpdate) ClearVerificationCode() *EmailUpdate {
eu.mutation.ClearVerificationCode()
return eu
}
// SetResetCode sets the "reset_code" field.
func (eu *EmailUpdate) SetResetCode(s string) *EmailUpdate {
eu.mutation.SetResetCode(s)
return eu
}
// SetNillableResetCode sets the "reset_code" field if the given value is not nil.
func (eu *EmailUpdate) SetNillableResetCode(s *string) *EmailUpdate {
if s != nil {
eu.SetResetCode(*s)
}
return eu
}
// ClearResetCode clears the value of the "reset_code" field.
func (eu *EmailUpdate) ClearResetCode() *EmailUpdate {
eu.mutation.ClearResetCode()
return eu
}
2024-09-03 15:56:34 +02:00
// SetAccountID sets the "account" edge to the Account entity by ID.
func (eu *EmailUpdate) SetAccountID(id uuid.UUID) *EmailUpdate {
eu.mutation.SetAccountID(id)
2024-08-19 13:55:36 +02:00
return eu
}
2024-09-03 15:56:34 +02:00
// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil.
func (eu *EmailUpdate) SetNillableAccountID(id *uuid.UUID) *EmailUpdate {
2024-08-19 13:55:36 +02:00
if id != nil {
2024-09-03 15:56:34 +02:00
eu = eu.SetAccountID(*id)
2024-08-19 13:55:36 +02:00
}
return eu
}
2024-09-03 15:56:34 +02:00
// SetAccount sets the "account" edge to the Account entity.
func (eu *EmailUpdate) SetAccount(a *Account) *EmailUpdate {
return eu.SetAccountID(a.ID)
2024-08-19 13:55:36 +02:00
}
// Mutation returns the EmailMutation object of the builder.
func (eu *EmailUpdate) Mutation() *EmailMutation {
return eu.mutation
}
2024-09-03 15:56:34 +02:00
// ClearAccount clears the "account" edge to the Account entity.
func (eu *EmailUpdate) ClearAccount() *EmailUpdate {
eu.mutation.ClearAccount()
2024-08-19 13:55:36 +02:00
return eu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (eu *EmailUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (eu *EmailUpdate) SaveX(ctx context.Context) int {
affected, err := eu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (eu *EmailUpdate) Exec(ctx context.Context) error {
_, err := eu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (eu *EmailUpdate) ExecX(ctx context.Context) {
if err := eu.Exec(ctx); err != nil {
panic(err)
}
}
func (eu *EmailUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(email.Table, email.Columns, sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID))
if ps := eu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := eu.mutation.Email(); ok {
_spec.SetField(email.FieldEmail, field.TypeString, value)
}
if value, ok := eu.mutation.Primary(); ok {
_spec.SetField(email.FieldPrimary, field.TypeBool, value)
}
if value, ok := eu.mutation.Verified(); ok {
_spec.SetField(email.FieldVerified, field.TypeBool, value)
}
if value, ok := eu.mutation.VerificationCode(); ok {
_spec.SetField(email.FieldVerificationCode, field.TypeString, value)
}
if eu.mutation.VerificationCodeCleared() {
_spec.ClearField(email.FieldVerificationCode, field.TypeString)
}
if value, ok := eu.mutation.ResetCode(); ok {
_spec.SetField(email.FieldResetCode, field.TypeString, value)
}
if eu.mutation.ResetCodeCleared() {
_spec.ClearField(email.FieldResetCode, field.TypeString)
}
2024-09-03 15:56:34 +02:00
if eu.mutation.AccountCleared() {
2024-08-19 13:55:36 +02:00
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
2024-09-03 15:56:34 +02:00
Table: email.AccountTable,
Columns: []string{email.AccountColumn},
2024-08-19 13:55:36 +02:00
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
2024-09-03 15:56:34 +02:00
if nodes := eu.mutation.AccountIDs(); len(nodes) > 0 {
2024-08-19 13:55:36 +02:00
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
2024-09-03 15:56:34 +02:00
Table: email.AccountTable,
Columns: []string{email.AccountColumn},
2024-08-19 13:55:36 +02:00
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.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, eu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{email.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
eu.mutation.done = true
return n, nil
}
// EmailUpdateOne is the builder for updating a single Email entity.
type EmailUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EmailMutation
}
// SetEmail sets the "email" field.
func (euo *EmailUpdateOne) SetEmail(s string) *EmailUpdateOne {
euo.mutation.SetEmail(s)
return euo
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (euo *EmailUpdateOne) SetNillableEmail(s *string) *EmailUpdateOne {
if s != nil {
euo.SetEmail(*s)
}
return euo
}
// SetPrimary sets the "primary" field.
func (euo *EmailUpdateOne) SetPrimary(b bool) *EmailUpdateOne {
euo.mutation.SetPrimary(b)
return euo
}
// SetNillablePrimary sets the "primary" field if the given value is not nil.
func (euo *EmailUpdateOne) SetNillablePrimary(b *bool) *EmailUpdateOne {
if b != nil {
euo.SetPrimary(*b)
}
return euo
}
// SetVerified sets the "verified" field.
func (euo *EmailUpdateOne) SetVerified(b bool) *EmailUpdateOne {
euo.mutation.SetVerified(b)
return euo
}
// SetNillableVerified sets the "verified" field if the given value is not nil.
func (euo *EmailUpdateOne) SetNillableVerified(b *bool) *EmailUpdateOne {
if b != nil {
euo.SetVerified(*b)
}
return euo
}
// SetVerificationCode sets the "verification_code" field.
func (euo *EmailUpdateOne) SetVerificationCode(s string) *EmailUpdateOne {
euo.mutation.SetVerificationCode(s)
return euo
}
// SetNillableVerificationCode sets the "verification_code" field if the given value is not nil.
func (euo *EmailUpdateOne) SetNillableVerificationCode(s *string) *EmailUpdateOne {
if s != nil {
euo.SetVerificationCode(*s)
}
return euo
}
// ClearVerificationCode clears the value of the "verification_code" field.
func (euo *EmailUpdateOne) ClearVerificationCode() *EmailUpdateOne {
euo.mutation.ClearVerificationCode()
return euo
}
// SetResetCode sets the "reset_code" field.
func (euo *EmailUpdateOne) SetResetCode(s string) *EmailUpdateOne {
euo.mutation.SetResetCode(s)
return euo
}
// SetNillableResetCode sets the "reset_code" field if the given value is not nil.
func (euo *EmailUpdateOne) SetNillableResetCode(s *string) *EmailUpdateOne {
if s != nil {
euo.SetResetCode(*s)
}
return euo
}
// ClearResetCode clears the value of the "reset_code" field.
func (euo *EmailUpdateOne) ClearResetCode() *EmailUpdateOne {
euo.mutation.ClearResetCode()
return euo
}
2024-09-03 15:56:34 +02:00
// SetAccountID sets the "account" edge to the Account entity by ID.
func (euo *EmailUpdateOne) SetAccountID(id uuid.UUID) *EmailUpdateOne {
euo.mutation.SetAccountID(id)
2024-08-19 13:55:36 +02:00
return euo
}
2024-09-03 15:56:34 +02:00
// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil.
func (euo *EmailUpdateOne) SetNillableAccountID(id *uuid.UUID) *EmailUpdateOne {
2024-08-19 13:55:36 +02:00
if id != nil {
2024-09-03 15:56:34 +02:00
euo = euo.SetAccountID(*id)
2024-08-19 13:55:36 +02:00
}
return euo
}
2024-09-03 15:56:34 +02:00
// SetAccount sets the "account" edge to the Account entity.
func (euo *EmailUpdateOne) SetAccount(a *Account) *EmailUpdateOne {
return euo.SetAccountID(a.ID)
2024-08-19 13:55:36 +02:00
}
// Mutation returns the EmailMutation object of the builder.
func (euo *EmailUpdateOne) Mutation() *EmailMutation {
return euo.mutation
}
2024-09-03 15:56:34 +02:00
// ClearAccount clears the "account" edge to the Account entity.
func (euo *EmailUpdateOne) ClearAccount() *EmailUpdateOne {
euo.mutation.ClearAccount()
2024-08-19 13:55:36 +02:00
return euo
}
// Where appends a list predicates to the EmailUpdate builder.
func (euo *EmailUpdateOne) Where(ps ...predicate.Email) *EmailUpdateOne {
euo.mutation.Where(ps...)
return euo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (euo *EmailUpdateOne) Select(field string, fields ...string) *EmailUpdateOne {
euo.fields = append([]string{field}, fields...)
return euo
}
// Save executes the query and returns the updated Email entity.
func (euo *EmailUpdateOne) Save(ctx context.Context) (*Email, error) {
return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (euo *EmailUpdateOne) SaveX(ctx context.Context) *Email {
node, err := euo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (euo *EmailUpdateOne) Exec(ctx context.Context) error {
_, err := euo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (euo *EmailUpdateOne) ExecX(ctx context.Context) {
if err := euo.Exec(ctx); err != nil {
panic(err)
}
}
func (euo *EmailUpdateOne) sqlSave(ctx context.Context) (_node *Email, err error) {
_spec := sqlgraph.NewUpdateSpec(email.Table, email.Columns, sqlgraph.NewFieldSpec(email.FieldID, field.TypeUUID))
id, ok := euo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Email.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := euo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, email.FieldID)
for _, f := range fields {
if !email.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != email.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := euo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := euo.mutation.Email(); ok {
_spec.SetField(email.FieldEmail, field.TypeString, value)
}
if value, ok := euo.mutation.Primary(); ok {
_spec.SetField(email.FieldPrimary, field.TypeBool, value)
}
if value, ok := euo.mutation.Verified(); ok {
_spec.SetField(email.FieldVerified, field.TypeBool, value)
}
if value, ok := euo.mutation.VerificationCode(); ok {
_spec.SetField(email.FieldVerificationCode, field.TypeString, value)
}
if euo.mutation.VerificationCodeCleared() {
_spec.ClearField(email.FieldVerificationCode, field.TypeString)
}
if value, ok := euo.mutation.ResetCode(); ok {
_spec.SetField(email.FieldResetCode, field.TypeString, value)
}
if euo.mutation.ResetCodeCleared() {
_spec.ClearField(email.FieldResetCode, field.TypeString)
}
2024-09-03 15:56:34 +02:00
if euo.mutation.AccountCleared() {
2024-08-19 13:55:36 +02:00
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
2024-09-03 15:56:34 +02:00
Table: email.AccountTable,
Columns: []string{email.AccountColumn},
2024-08-19 13:55:36 +02:00
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
2024-09-03 15:56:34 +02:00
if nodes := euo.mutation.AccountIDs(); len(nodes) > 0 {
2024-08-19 13:55:36 +02:00
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
2024-09-03 15:56:34 +02:00
Table: email.AccountTable,
Columns: []string{email.AccountColumn},
2024-08-19 13:55:36 +02:00
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Email{config: euo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{email.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
euo.mutation.done = true
return _node, nil
}