2023-12-30 19:51:22 +00:00
|
|
|
package adminkindboxvalidator
|
2023-12-27 21:55:15 +00:00
|
|
|
|
|
|
|
type Repository interface {
|
|
|
|
KindBoxRequestExist(id uint) (bool, error)
|
|
|
|
EmployeeExist(id uint) (bool, error)
|
|
|
|
BenefactorExist(id uint) (bool, error)
|
|
|
|
KindBoxExist(id uint) (bool, error)
|
|
|
|
KindBoxBelongToBenefactor(benefactorID uint, kindboxID uint) (bool, error)
|
2023-12-28 13:43:06 +00:00
|
|
|
PendingStatus(id uint) (bool, error)
|
2023-12-27 21:55:15 +00:00
|
|
|
CheckStatus(status string) (bool, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Validator struct {
|
|
|
|
repo Repository
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(repo Repository) Validator {
|
|
|
|
return Validator{repo: repo}
|
|
|
|
}
|
|
|
|
|
2024-01-23 10:21:56 +00:00
|
|
|
// func (v Validator) doesKindBoxRequestExist(value interface{}) error {
|
|
|
|
// receiverID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.KindBoxRequestExist(receiverID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// func (v Validator) doesEmployeeExist(value interface{}) error {
|
|
|
|
// senderID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.EmployeeExist(senderID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// func (v Validator) doesBenefactorExist(value interface{}) error {
|
|
|
|
// benefactorID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.BenefactorExist(benefactorID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func (v Validator) doesKindBoxExist(value interface{}) error {
|
|
|
|
// kindboxID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.KindBoxExist(kindboxID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func (v Validator) doesKindBoxBelongToBenefactor(benefactorID uint) validation.RuleFunc {
|
|
|
|
// return func(value interface{}) error {
|
|
|
|
// kbID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.KindBoxBelongToBenefactor(benefactorID, kbID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
//}
|
2023-12-27 21:55:15 +00:00
|
|
|
|
2024-01-01 07:22:14 +00:00
|
|
|
// TODO: this temperary to ignore linter error. (unused function)
|
|
|
|
// func (v Validator) hasCorrectStatus(value interface{}) error {
|
|
|
|
// status, ok := value.(string)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.CheckStatus(status)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
2023-12-27 21:55:15 +00:00
|
|
|
|
2024-01-01 07:22:14 +00:00
|
|
|
// return nil
|
|
|
|
// }
|
2023-12-28 13:43:06 +00:00
|
|
|
|
2024-01-23 10:21:56 +00:00
|
|
|
// func (v Validator) hasPendingStatus(value interface{}) error {
|
|
|
|
// kindboxID, ok := value.(uint)
|
|
|
|
// if !ok {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
|
|
|
// }
|
|
|
|
// _, err := v.repo.PendingStatus(kindboxID)
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf(errmsg.ErrorMsgNotFound)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
//}
|