forked from ebhomengo/niki
1
0
Fork 0
niki/validator/benefactor/kind_box_req/validator.go

57 lines
1.0 KiB
Go

package userkindboxreq
import (
"fmt"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
)
const (
MinKindBoxReq = 1
MaxKindBoxReq = 100
)
type Repository interface {
BenefactorExist(id int) (bool, error)
KindBoxReqExist(id int) (bool, error)
TypeExist(id int) (bool, error)
}
type Validator struct {
repo Repository
}
func New(repo Repository) Validator {
return Validator{repo: repo}
}
func (v Validator) doesBenefactorExist(value interface{}) error {
benefactorID := value.(int)
_, err := v.repo.BenefactorExist(benefactorID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}
func (v Validator) doesTypeExist(value interface{}) error {
typeID := value.(int)
_, err := v.repo.TypeExist(typeID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}
func (v Validator) doesKindBoxRequestExist(value interface{}) error {
kindBoxReqID := value.(int)
_, err := v.repo.KindBoxReqExist(kindBoxReqID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}