niki/validator/admin/kind_box/validator.go

37 lines
708 B
Go

package adminkindboxvalidator
import (
"context"
"fmt"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
)
type Repository interface {
KindBoxExist(ctx context.Context, kindBoxID uint) (bool, error)
}
type Validator struct {
repo Repository
}
func New(repo Repository) Validator {
return Validator{repo: repo}
}
func (v Validator) doesKindBoxExist(value interface{}) error {
kindBoxID, ok := value.(uint)
if !ok {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
exists, err := v.repo.KindBoxExist(context.Background(), kindBoxID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
if !exists {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}