forked from ebhomengo/niki
1
0
Fork 0
niki/validator/agent/kind_box/validator.go

38 lines
823 B
Go
Raw Normal View History

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