mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 08:35:43 +00:00
validate using currency service
This commit is contained in:
parent
e647419eed
commit
fa676d6351
2 changed files with 14 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
"github.com/hay-kot/homebox/backend/internal/sys/validate"
|
||||
"github.com/hay-kot/homebox/backend/internal/web/adapters"
|
||||
"github.com/hay-kot/httpkit/errchain"
|
||||
)
|
||||
|
@ -52,6 +53,14 @@ func (ctrl *V1Controller) HandleGroupGet() errchain.HandlerFunc {
|
|||
func (ctrl *V1Controller) HandleGroupUpdate() errchain.HandlerFunc {
|
||||
fn := func(r *http.Request, body repo.GroupUpdate) (repo.Group, error) {
|
||||
auth := services.NewContext(r.Context())
|
||||
|
||||
ok := ctrl.svc.Currencies.IsSupported(body.Currency)
|
||||
if !ok {
|
||||
return repo.Group{}, validate.NewFieldErrors(
|
||||
validate.NewFieldError("currency", "currency is not supported"),
|
||||
)
|
||||
}
|
||||
|
||||
return ctrl.svc.Group.UpdateGroup(auth, body)
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ func (fe FieldErrors) Nil() bool {
|
|||
return len(fe) == 0
|
||||
}
|
||||
|
||||
// Error implments the error interface.
|
||||
// Error implements the error interface.
|
||||
func (fe FieldErrors) Error() string {
|
||||
d, err := json.Marshal(fe)
|
||||
if err != nil {
|
||||
|
@ -101,6 +101,10 @@ func NewFieldErrors(errs ...FieldError) FieldErrors {
|
|||
return errs
|
||||
}
|
||||
|
||||
func NewFieldError(field, reason string) FieldError {
|
||||
return FieldError{Field: field, Error: reason}
|
||||
}
|
||||
|
||||
func IsFieldError(err error) bool {
|
||||
v := FieldErrors{}
|
||||
return errors.As(err, &v)
|
||||
|
|
Loading…
Reference in a new issue