[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
883
backend/ent/user_update.go
Normal file
883
backend/ent/user_update.go
Normal file
|
@ -0,0 +1,883 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
"tss-rocks-be/ent/contributor"
|
||||
"tss-rocks-be/ent/media"
|
||||
"tss-rocks-be/ent/predicate"
|
||||
"tss-rocks-be/ent/role"
|
||||
"tss-rocks-be/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
type UserUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||
uu.mutation.Where(ps...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (uu *UserUpdate) SetEmail(s string) *UserUpdate {
|
||||
uu.mutation.SetEmail(s)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableEmail(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
uu.SetEmail(*s)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetPasswordHash sets the "password_hash" field.
|
||||
func (uu *UserUpdate) SetPasswordHash(s string) *UserUpdate {
|
||||
uu.mutation.SetPasswordHash(s)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillablePasswordHash sets the "password_hash" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillablePasswordHash(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
uu.SetPasswordHash(*s)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (uu *UserUpdate) SetStatus(u user.Status) *UserUpdate {
|
||||
uu.mutation.SetStatus(u)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableStatus(u *user.Status) *UserUpdate {
|
||||
if u != nil {
|
||||
uu.SetStatus(*u)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (uu *UserUpdate) SetCreatedAt(t time.Time) *UserUpdate {
|
||||
uu.mutation.SetCreatedAt(t)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableCreatedAt(t *time.Time) *UserUpdate {
|
||||
if t != nil {
|
||||
uu.SetCreatedAt(*t)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (uu *UserUpdate) SetUpdatedAt(t time.Time) *UserUpdate {
|
||||
uu.mutation.SetUpdatedAt(t)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddRoleIDs adds the "roles" edge to the Role entity by IDs.
|
||||
func (uu *UserUpdate) AddRoleIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.AddRoleIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddRoles adds the "roles" edges to the Role entity.
|
||||
func (uu *UserUpdate) AddRoles(r ...*Role) *UserUpdate {
|
||||
ids := make([]int, len(r))
|
||||
for i := range r {
|
||||
ids[i] = r[i].ID
|
||||
}
|
||||
return uu.AddRoleIDs(ids...)
|
||||
}
|
||||
|
||||
// AddContributorIDs adds the "contributors" edge to the Contributor entity by IDs.
|
||||
func (uu *UserUpdate) AddContributorIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.AddContributorIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddContributors adds the "contributors" edges to the Contributor entity.
|
||||
func (uu *UserUpdate) AddContributors(c ...*Contributor) *UserUpdate {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return uu.AddContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// AddMediumIDs adds the "media" edge to the Media entity by IDs.
|
||||
func (uu *UserUpdate) AddMediumIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.AddMediumIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddMedia adds the "media" edges to the Media entity.
|
||||
func (uu *UserUpdate) AddMedia(m ...*Media) *UserUpdate {
|
||||
ids := make([]int, len(m))
|
||||
for i := range m {
|
||||
ids[i] = m[i].ID
|
||||
}
|
||||
return uu.AddMediumIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uu *UserUpdate) Mutation() *UserMutation {
|
||||
return uu.mutation
|
||||
}
|
||||
|
||||
// ClearRoles clears all "roles" edges to the Role entity.
|
||||
func (uu *UserUpdate) ClearRoles() *UserUpdate {
|
||||
uu.mutation.ClearRoles()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveRoleIDs removes the "roles" edge to Role entities by IDs.
|
||||
func (uu *UserUpdate) RemoveRoleIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.RemoveRoleIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveRoles removes "roles" edges to Role entities.
|
||||
func (uu *UserUpdate) RemoveRoles(r ...*Role) *UserUpdate {
|
||||
ids := make([]int, len(r))
|
||||
for i := range r {
|
||||
ids[i] = r[i].ID
|
||||
}
|
||||
return uu.RemoveRoleIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearContributors clears all "contributors" edges to the Contributor entity.
|
||||
func (uu *UserUpdate) ClearContributors() *UserUpdate {
|
||||
uu.mutation.ClearContributors()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveContributorIDs removes the "contributors" edge to Contributor entities by IDs.
|
||||
func (uu *UserUpdate) RemoveContributorIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.RemoveContributorIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveContributors removes "contributors" edges to Contributor entities.
|
||||
func (uu *UserUpdate) RemoveContributors(c ...*Contributor) *UserUpdate {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return uu.RemoveContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearMedia clears all "media" edges to the Media entity.
|
||||
func (uu *UserUpdate) ClearMedia() *UserUpdate {
|
||||
uu.mutation.ClearMedia()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveMediumIDs removes the "media" edge to Media entities by IDs.
|
||||
func (uu *UserUpdate) RemoveMediumIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.RemoveMediumIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveMedia removes "media" edges to Media entities.
|
||||
func (uu *UserUpdate) RemoveMedia(m ...*Media) *UserUpdate {
|
||||
ids := make([]int, len(m))
|
||||
for i := range m {
|
||||
ids[i] = m[i].ID
|
||||
}
|
||||
return uu.RemoveMediumIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
uu.defaults()
|
||||
return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (uu *UserUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := uu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (uu *UserUpdate) Exec(ctx context.Context) error {
|
||||
_, err := uu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (uu *UserUpdate) ExecX(ctx context.Context) {
|
||||
if err := uu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (uu *UserUpdate) defaults() {
|
||||
if _, ok := uu.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
uu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uu *UserUpdate) check() error {
|
||||
if v, ok := uu.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uu.mutation.PasswordHash(); ok {
|
||||
if err := user.PasswordHashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uu.mutation.Status(); ok {
|
||||
if err := user.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := uu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := uu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := uu.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uu.mutation.PasswordHash(); ok {
|
||||
_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uu.mutation.Status(); ok {
|
||||
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := uu.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := uu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if uu.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedRolesIDs(); len(nodes) > 0 && !uu.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RolesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uu.mutation.ContributorsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedContributorsIDs(); len(nodes) > 0 && !uu.mutation.ContributorsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.ContributorsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uu.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedMediaIDs(); len(nodes) > 0 && !uu.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.MediaIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
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, uu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
uu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// UserUpdateOne is the builder for updating a single User entity.
|
||||
type UserUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne {
|
||||
uuo.mutation.SetEmail(s)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableEmail(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
uuo.SetEmail(*s)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetPasswordHash sets the "password_hash" field.
|
||||
func (uuo *UserUpdateOne) SetPasswordHash(s string) *UserUpdateOne {
|
||||
uuo.mutation.SetPasswordHash(s)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillablePasswordHash sets the "password_hash" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillablePasswordHash(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
uuo.SetPasswordHash(*s)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (uuo *UserUpdateOne) SetStatus(u user.Status) *UserUpdateOne {
|
||||
uuo.mutation.SetStatus(u)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableStatus(u *user.Status) *UserUpdateOne {
|
||||
if u != nil {
|
||||
uuo.SetStatus(*u)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (uuo *UserUpdateOne) SetCreatedAt(t time.Time) *UserUpdateOne {
|
||||
uuo.mutation.SetCreatedAt(t)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableCreatedAt(t *time.Time) *UserUpdateOne {
|
||||
if t != nil {
|
||||
uuo.SetCreatedAt(*t)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (uuo *UserUpdateOne) SetUpdatedAt(t time.Time) *UserUpdateOne {
|
||||
uuo.mutation.SetUpdatedAt(t)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddRoleIDs adds the "roles" edge to the Role entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddRoleIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.AddRoleIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddRoles adds the "roles" edges to the Role entity.
|
||||
func (uuo *UserUpdateOne) AddRoles(r ...*Role) *UserUpdateOne {
|
||||
ids := make([]int, len(r))
|
||||
for i := range r {
|
||||
ids[i] = r[i].ID
|
||||
}
|
||||
return uuo.AddRoleIDs(ids...)
|
||||
}
|
||||
|
||||
// AddContributorIDs adds the "contributors" edge to the Contributor entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddContributorIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.AddContributorIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddContributors adds the "contributors" edges to the Contributor entity.
|
||||
func (uuo *UserUpdateOne) AddContributors(c ...*Contributor) *UserUpdateOne {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return uuo.AddContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// AddMediumIDs adds the "media" edge to the Media entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddMediumIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.AddMediumIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddMedia adds the "media" edges to the Media entity.
|
||||
func (uuo *UserUpdateOne) AddMedia(m ...*Media) *UserUpdateOne {
|
||||
ids := make([]int, len(m))
|
||||
for i := range m {
|
||||
ids[i] = m[i].ID
|
||||
}
|
||||
return uuo.AddMediumIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uuo *UserUpdateOne) Mutation() *UserMutation {
|
||||
return uuo.mutation
|
||||
}
|
||||
|
||||
// ClearRoles clears all "roles" edges to the Role entity.
|
||||
func (uuo *UserUpdateOne) ClearRoles() *UserUpdateOne {
|
||||
uuo.mutation.ClearRoles()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveRoleIDs removes the "roles" edge to Role entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveRoleIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.RemoveRoleIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveRoles removes "roles" edges to Role entities.
|
||||
func (uuo *UserUpdateOne) RemoveRoles(r ...*Role) *UserUpdateOne {
|
||||
ids := make([]int, len(r))
|
||||
for i := range r {
|
||||
ids[i] = r[i].ID
|
||||
}
|
||||
return uuo.RemoveRoleIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearContributors clears all "contributors" edges to the Contributor entity.
|
||||
func (uuo *UserUpdateOne) ClearContributors() *UserUpdateOne {
|
||||
uuo.mutation.ClearContributors()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveContributorIDs removes the "contributors" edge to Contributor entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveContributorIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.RemoveContributorIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveContributors removes "contributors" edges to Contributor entities.
|
||||
func (uuo *UserUpdateOne) RemoveContributors(c ...*Contributor) *UserUpdateOne {
|
||||
ids := make([]int, len(c))
|
||||
for i := range c {
|
||||
ids[i] = c[i].ID
|
||||
}
|
||||
return uuo.RemoveContributorIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearMedia clears all "media" edges to the Media entity.
|
||||
func (uuo *UserUpdateOne) ClearMedia() *UserUpdateOne {
|
||||
uuo.mutation.ClearMedia()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveMediumIDs removes the "media" edge to Media entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveMediumIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.RemoveMediumIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveMedia removes "media" edges to Media entities.
|
||||
func (uuo *UserUpdateOne) RemoveMedia(m ...*Media) *UserUpdateOne {
|
||||
ids := make([]int, len(m))
|
||||
for i := range m {
|
||||
ids[i] = m[i].ID
|
||||
}
|
||||
return uuo.RemoveMediumIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||
uuo.mutation.Where(ps...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
||||
uuo.fields = append([]string{field}, fields...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated User entity.
|
||||
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
uuo.defaults()
|
||||
return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
|
||||
node, err := uuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := uuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := uuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (uuo *UserUpdateOne) defaults() {
|
||||
if _, ok := uuo.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
uuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uuo *UserUpdateOne) check() error {
|
||||
if v, ok := uuo.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uuo.mutation.PasswordHash(); ok {
|
||||
if err := user.PasswordHashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uuo.mutation.Status(); ok {
|
||||
if err := user.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
if err := uuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
id, ok := uuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := uuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for _, f := range fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != user.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := uuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := uuo.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.PasswordHash(); ok {
|
||||
_spec.SetField(user.FieldPasswordHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.Status(); ok {
|
||||
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if uuo.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedRolesIDs(); len(nodes) > 0 && !uuo.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RolesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.RolesTable,
|
||||
Columns: user.RolesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uuo.mutation.ContributorsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedContributorsIDs(); len(nodes) > 0 && !uuo.mutation.ContributorsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.ContributorsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ContributorsTable,
|
||||
Columns: []string{user.ContributorsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(contributor.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uuo.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedMediaIDs(); len(nodes) > 0 && !uuo.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.MediaIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.MediaTable,
|
||||
Columns: []string{user.MediaColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &User{config: uuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
uuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue