forked from ebhomengo/niki
46 lines
784 B
Go
46 lines
784 B
Go
|
package kindboxreq
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
MinKindBoxReq = 1
|
||
|
MaxKindBoxReq = 100
|
||
|
)
|
||
|
|
||
|
type Repository interface {
|
||
|
BeneFactorExist(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
|
||
|
}
|