Clear empty optional fields.
This commit is contained in:
parent
53113101c9
commit
8a4dd9fb3b
4 changed files with 28 additions and 9 deletions
|
|
@ -96,6 +96,9 @@ func (h *Handler) PasswordTokenCreate(ctx echo.Context) error {
|
||||||
if payload.CreatedAt != nil {
|
if payload.CreatedAt != nil {
|
||||||
op.SetCreatedAt(*payload.CreatedAt)
|
op.SetCreatedAt(*payload.CreatedAt)
|
||||||
}
|
}
|
||||||
|
if payload.Abc != nil {
|
||||||
|
op.SetAbc(*payload.Abc)
|
||||||
|
}
|
||||||
_, err := op.Save(ctx.Request().Context())
|
_, err := op.Save(ctx.Request().Context())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +125,11 @@ func (h *Handler) PasswordTokenUpdate(ctx echo.Context, id int) error {
|
||||||
} else {
|
} else {
|
||||||
op.SetCreatedAt(*payload.CreatedAt)
|
op.SetCreatedAt(*payload.CreatedAt)
|
||||||
}
|
}
|
||||||
|
if payload.Abc == nil {
|
||||||
|
op.ClearAbc()
|
||||||
|
} else {
|
||||||
|
op.SetAbc(*payload.Abc)
|
||||||
|
}
|
||||||
_, err = op.Save(ctx.Request().Context())
|
_, err = op.Save(ctx.Request().Context())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -147,6 +155,7 @@ func (h *Handler) PasswordTokenList(ctx echo.Context) (*EntityList, error) {
|
||||||
Columns: []string{
|
Columns: []string{
|
||||||
"User ID",
|
"User ID",
|
||||||
"Created at",
|
"Created at",
|
||||||
|
"Abc",
|
||||||
},
|
},
|
||||||
Entities: make([]EntityValues, 0, len(res)),
|
Entities: make([]EntityValues, 0, len(res)),
|
||||||
HasNextPage: len(res) > h.Config.ItemsPerPage,
|
HasNextPage: len(res) > h.Config.ItemsPerPage,
|
||||||
|
|
@ -158,6 +167,7 @@ func (h *Handler) PasswordTokenList(ctx echo.Context) (*EntityList, error) {
|
||||||
Values: []string{
|
Values: []string{
|
||||||
fmt.Sprint(res[i].UserID),
|
fmt.Sprint(res[i].UserID),
|
||||||
res[i].CreatedAt.Format(h.Config.TimeFormat),
|
res[i].CreatedAt.Format(h.Config.TimeFormat),
|
||||||
|
fmt.Sprint(res[i].Abc),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -174,6 +184,7 @@ func (h *Handler) PasswordTokenGet(ctx echo.Context, id int) (url.Values, error)
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("user_id", fmt.Sprint(entity.UserID))
|
v.Set("user_id", fmt.Sprint(entity.UserID))
|
||||||
v.Set("created_at", entity.CreatedAt.Format(time.RFC3339))
|
v.Set("created_at", entity.CreatedAt.Format(time.RFC3339))
|
||||||
|
v.Set("abc", fmt.Sprint(entity.Abc))
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,7 +296,7 @@ func (h *Handler) getOffset(ctx echo.Context) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) bind(ctx echo.Context, entity any) error {
|
func (h *Handler) bind(ctx echo.Context, entity any) error {
|
||||||
// Remove empty field values so Echo's bind does to fail when trying to parse things like
|
// Remove empty field values so Echo's bind does not fail when trying to parse things like
|
||||||
// times, etc.
|
// times, etc.
|
||||||
for k, v := range ctx.Request().Form {
|
for k, v := range ctx.Request().Form {
|
||||||
if len(v) == 1 && len(v[0]) == 0 {
|
if len(v) == 1 && len(v[0]) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,11 @@
|
||||||
}
|
}
|
||||||
{{- else if $f.Nillable }}
|
{{- else if $f.Nillable }}
|
||||||
op.SetNillable{{ fieldName $f.Name }}(payload.{{ fieldName $f.Name }})
|
op.SetNillable{{ fieldName $f.Name }}(payload.{{ fieldName $f.Name }})
|
||||||
if payload.{{ fieldName $f.Name }} != nil {
|
{{- else if $f.Optional }}
|
||||||
// TODO this is not available op.Clear{{ fieldName $f.Name }}()
|
if payload.{{ fieldName $f.Name }} == nil {
|
||||||
|
op.Clear{{ fieldName $f.Name }}()
|
||||||
|
} else {
|
||||||
|
op.Set{{ fieldName $f.Name }}(*payload.{{ fieldName $f.Name }})
|
||||||
}
|
}
|
||||||
{{- else if (fieldIsPointer $f) }}
|
{{- else if (fieldIsPointer $f) }}
|
||||||
if payload.{{ fieldName $f.Name }} == nil {
|
if payload.{{ fieldName $f.Name }} == nil {
|
||||||
|
|
@ -230,7 +233,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) bind(ctx echo.Context, entity any) error {
|
func (h *Handler) bind(ctx echo.Context, entity any) error {
|
||||||
// Remove empty field values so Echo's bind does to fail when trying to parse things like
|
// Remove empty field values so Echo's bind does not fail when trying to parse things like
|
||||||
// times, etc.
|
// times, etc.
|
||||||
for k, v := range ctx.Request().Form {
|
for k, v := range ctx.Request().Form {
|
||||||
if len(v) == 1 && len(v[0]) == 0 {
|
if len(v) == 1 && len(v[0]) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
// Code generated by ent, DO NOT EDIT.
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||||
|
)
|
||||||
|
|
||||||
type PasswordToken struct {
|
type PasswordToken struct {
|
||||||
Hash *string `form:"hash"`
|
Hash *string `form:"hash"`
|
||||||
UserID int `form:"user_id"`
|
UserID int `form:"user_id"`
|
||||||
CreatedAt *time.Time `form:"created_at"`
|
CreatedAt *time.Time `form:"created_at"`
|
||||||
|
Abc *passwordtoken.Abc `form:"abc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values u
|
||||||
}))
|
}))
|
||||||
case field.TypeEnum:
|
case field.TypeEnum:
|
||||||
options := make([]Choice, 0, len(f.Enums)+1)
|
options := make([]Choice, 0, len(f.Enums)+1)
|
||||||
if f.Nillable {
|
if f.Optional {
|
||||||
options = append(options, Choice{
|
options = append(options, Choice{
|
||||||
Label: "-",
|
Label: "-",
|
||||||
Value: "",
|
Value: "",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue