niki/validator/kind_box/validator.go

41 lines
754 B
Go

package kindbox
import (
"fmt"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
)
type Repository interface {
ReceiverUserExist(id int) (bool, error)
SenderUserExist(id int) (bool, error)
}
type Validator struct {
repo Repository
}
func New(repo Repository) Validator {
return Validator{repo: repo}
}
func (v Validator) doesReceiverUserExist(value interface{}) error {
receiverID := value.(int)
_, err := v.repo.ReceiverUserExist(receiverID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}
func (v Validator) doesSenderUserExist(value interface{}) error {
senderID := value.(int)
_, err := v.repo.SenderUserExist(senderID)
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}
return nil
}