notification
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/contract"
|
||||
)
|
||||
|
||||
type NotificationValidator interface {
|
||||
ValidateSendRequest(req *contract.SendNotificationRequest) (error, string)
|
||||
ValidateBroadcastRequest(req *contract.BroadcastNotificationRequest) (error, string)
|
||||
ValidateListRequest(req *contract.ListNotificationsRequest) (error, string)
|
||||
}
|
||||
|
||||
type NotificationValidatorImpl struct{}
|
||||
|
||||
func NewNotificationValidator() *NotificationValidatorImpl {
|
||||
return &NotificationValidatorImpl{}
|
||||
}
|
||||
|
||||
func (v *NotificationValidatorImpl) ValidateSendRequest(req *contract.SendNotificationRequest) (error, string) {
|
||||
if req.Title == "" {
|
||||
return fmt.Errorf("title is required"), constants.MissingFieldErrorCode
|
||||
}
|
||||
if req.Body == "" {
|
||||
return fmt.Errorf("body is required"), constants.MissingFieldErrorCode
|
||||
}
|
||||
if len(req.ReceiverIDs) == 0 {
|
||||
return fmt.Errorf("at least one receiver_id is required"), constants.MissingFieldErrorCode
|
||||
}
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *NotificationValidatorImpl) ValidateBroadcastRequest(req *contract.BroadcastNotificationRequest) (error, string) {
|
||||
if req.Title == "" {
|
||||
return fmt.Errorf("title is required"), constants.MissingFieldErrorCode
|
||||
}
|
||||
if req.Body == "" {
|
||||
return fmt.Errorf("body is required"), constants.MissingFieldErrorCode
|
||||
}
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *NotificationValidatorImpl) ValidateListRequest(req *contract.ListNotificationsRequest) (error, string) {
|
||||
if req.Page < 1 {
|
||||
return fmt.Errorf("page must be greater than 0"), constants.ValidationErrorCode
|
||||
}
|
||||
if req.Limit < 1 || req.Limit > 100 {
|
||||
return fmt.Errorf("limit must be between 1 and 100"), constants.ValidationErrorCode
|
||||
}
|
||||
return nil, ""
|
||||
}
|
||||
Reference in New Issue
Block a user