niki/validator/benefactor/kind_box/validator.go

41 lines
749 B
Go
Raw Normal View History

package userkindbox
import (
"fmt"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
)
type Repository interface {
BenefactorExist(id int) (bool, error)
KindBoxExist(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) doesKindBoxExist(value interface{}) error {
kindBoxID := value.(int)
_, err := v.repo.KindBoxExist(kindBoxID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}