2023-12-30 19:51:22 +00:00
|
|
|
package adminkindboxreqvalidator
|
2023-12-27 21:55:15 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
MinKindBoxReq = 1
|
|
|
|
MaxKindBoxReq = 100
|
|
|
|
)
|
|
|
|
|
|
|
|
type Repository interface {
|
2024-01-22 08:14:57 +00:00
|
|
|
// BenefactorExist(id int) (bool, error)
|
|
|
|
// KindBoxRequestExist(id int) (bool, error)
|
|
|
|
// TypeExist(id int) (bool, error)
|
|
|
|
// KindBoxBelongToBenefactor(benefactorID uint, kindboxID uint) (bool, error)
|
|
|
|
// PendingStatus(id uint) (bool, error)
|
2023-12-27 21:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Validator struct {
|
|
|
|
repo Repository
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(repo Repository) Validator {
|
|
|
|
return Validator{repo: repo}
|
|
|
|
}
|
|
|
|
|
2024-01-22 08:14:57 +00:00
|
|
|
//
|
|
|
|
// func (v Validator) doesBenefactorExist(value interface{}) error {
|
|
|
|
// benefactorID, ok := value.(int)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.BenefactorExist(benefactorID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc {
|
|
|
|
// return func(value interface{}) error {
|
|
|
|
// kbID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.KindBoxBelongToBenefactor(benefactorID, kbID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// func (v Validator) doesKindBoxRequestExist(value interface{}) error {
|
|
|
|
// kindboxreqID, ok := value.(int)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.KindBoxRequestExist(kindboxreqID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// func (v Validator) doesTypeExist(value interface{}) error {
|
|
|
|
// typeID, ok := value.(int)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.TypeExist(typeID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func (v Validator) hasPendingStatus(value interface{}) error {
|
|
|
|
// kindboxID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.PendingStatus(kindboxID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|