42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package validator
|
|
|
|
import (
|
|
"apskel-pos-be/internal/contract"
|
|
"errors"
|
|
)
|
|
|
|
type VoucherValidator interface {
|
|
ValidateListVouchersForSpinRequest(req *contract.ListVouchersForSpinRequest) (error, string)
|
|
ValidateListVouchersByRowsRequest(req *contract.ListVouchersByRowsRequest) (error, string)
|
|
}
|
|
|
|
type VoucherValidatorImpl struct{}
|
|
|
|
func NewVoucherValidator() VoucherValidator {
|
|
return &VoucherValidatorImpl{}
|
|
}
|
|
|
|
func (v *VoucherValidatorImpl) ValidateListVouchersForSpinRequest(req *contract.ListVouchersForSpinRequest) (error, string) {
|
|
if req.Limit < 1 {
|
|
return errors.New("limit must be at least 1"), "INVALID_LIMIT"
|
|
}
|
|
|
|
if req.Limit > 50 {
|
|
return errors.New("limit cannot exceed 50"), "INVALID_LIMIT"
|
|
}
|
|
|
|
return nil, ""
|
|
}
|
|
|
|
func (v *VoucherValidatorImpl) ValidateListVouchersByRowsRequest(req *contract.ListVouchersByRowsRequest) (error, string) {
|
|
if req.Rows < 1 {
|
|
return errors.New("rows must be at least 1"), "INVALID_ROWS"
|
|
}
|
|
|
|
if req.Rows > 10 {
|
|
return errors.New("rows cannot exceed 10"), "INVALID_ROWS"
|
|
}
|
|
|
|
return nil, ""
|
|
}
|