2023-12-21 13:00:31 +00:00
|
|
|
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 {
|
2023-12-22 21:25:16 +00:00
|
|
|
receiverID := value.(int)
|
|
|
|
_, err := v.repo.ReceiverUserExist(receiverID)
|
2023-12-21 13:00:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Validator) doesSenderUserExist(value interface{}) error {
|
2023-12-22 21:25:16 +00:00
|
|
|
senderID := value.(int)
|
|
|
|
_, err := v.repo.SenderUserExist(senderID)
|
2023-12-21 13:00:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|