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

41 lines
754 B
Go
Raw Normal View History

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
}