feat(validator): add validation for kindbox request refer date

This commit is contained in:
Erfan Mohammadi 2024-05-21 21:08:43 +03:30
parent ee64f70466
commit ba4ebbcb84
2 changed files with 18 additions and 2 deletions

View File

@ -2,7 +2,6 @@ package benefactorkindboxreqvalidator
import ( import (
"errors" "errors"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -30,6 +29,7 @@ func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) *Validator
validation.Field(&req.DeliverReferDate, validation.Field(&req.DeliverReferDate,
validation.Required, validation.Required,
validation.By(v.isDateValid),
), ),
); err != nil { ); err != nil {

View File

@ -3,12 +3,12 @@ package benefactorkindboxreqvalidator
import ( import (
"context" "context"
"fmt" "fmt"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
addressparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/address" addressparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
"time"
) )
const ( const (
@ -94,6 +94,22 @@ func (v Validator) doesAddressExist(benefactorID uint) validation.RuleFunc {
} }
} }
func (v Validator) isDateValid(value interface{}) error {
date, ok := value.(string)
if !ok {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
t, err := time.Parse(time.DateTime, date)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
}
if t.Before(time.Now()) {
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
}
return nil
}
// func (v Validator) doesKindBoxRequestExist(value interface{}) error { // func (v Validator) doesKindBoxRequestExist(value interface{}) error {
// kindBoxReqID, ok := value.(uint) // kindBoxReqID, ok := value.(uint)
// if !ok { // if !ok {