Added email field to user.
This commit is contained in:
parent
dee7a13cba
commit
6ec1b77684
16 changed files with 410 additions and 139 deletions
|
|
@ -20,9 +20,15 @@ type UserCreate struct {
|
|||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (uc *UserCreate) SetUsername(s string) *UserCreate {
|
||||
uc.mutation.SetUsername(s)
|
||||
// SetName sets the "name" field.
|
||||
func (uc *UserCreate) SetName(s string) *UserCreate {
|
||||
uc.mutation.SetName(s)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (uc *UserCreate) SetEmail(s string) *UserCreate {
|
||||
uc.mutation.SetEmail(s)
|
||||
return uc
|
||||
}
|
||||
|
||||
|
|
@ -125,12 +131,20 @@ func (uc *UserCreate) defaults() {
|
|||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uc *UserCreate) check() error {
|
||||
if _, ok := uc.mutation.Username(); !ok {
|
||||
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "username"`)}
|
||||
if _, ok := uc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "name"`)}
|
||||
}
|
||||
if v, ok := uc.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 := uc.mutation.Name(); ok {
|
||||
if err := user.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := uc.mutation.Email(); !ok {
|
||||
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "email"`)}
|
||||
}
|
||||
if v, ok := uc.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := uc.mutation.Password(); !ok {
|
||||
|
|
@ -171,13 +185,21 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
},
|
||||
}
|
||||
)
|
||||
if value, ok := uc.mutation.Username(); ok {
|
||||
if value, ok := uc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldUsername,
|
||||
Column: user.FieldName,
|
||||
})
|
||||
_node.Username = value
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := uc.mutation.Email(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldEmail,
|
||||
})
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := uc.mutation.Password(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue