Handle user creation upon registration.
This commit is contained in:
parent
79d2db3c1f
commit
8657380530
13 changed files with 201 additions and 46 deletions
|
|
@ -50,6 +50,9 @@ func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
|||
affected int
|
||||
)
|
||||
if len(uu.hooks) == 0 {
|
||||
if err = uu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
affected, err = uu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
|
|
@ -57,6 +60,9 @@ func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
|||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
uu.mutation = mutation
|
||||
affected, err = uu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
|
|
@ -97,6 +103,21 @@ func (uu *UserUpdate) ExecX(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uu *UserUpdate) check() error {
|
||||
if v, ok := uu.mutation.Username(); ok {
|
||||
if err := user.UsernameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf("ent: validator failed for field \"username\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uu.mutation.Password(); ok {
|
||||
if err := user.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf("ent: validator failed for field \"password\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
|
|
@ -179,6 +200,9 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|||
node *User
|
||||
)
|
||||
if len(uuo.hooks) == 0 {
|
||||
if err = uuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = uuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
|
|
@ -186,6 +210,9 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uuo.mutation = mutation
|
||||
node, err = uuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
|
|
@ -226,6 +253,21 @@ func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uuo *UserUpdateOne) check() error {
|
||||
if v, ok := uuo.mutation.Username(); ok {
|
||||
if err := user.UsernameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf("ent: validator failed for field \"username\": %w", err)}
|
||||
}
|
||||
}
|
||||
if v, ok := uuo.mutation.Password(); ok {
|
||||
if err := user.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf("ent: validator failed for field \"password\": %w", err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue