Enhance Notification Request Structure and Service Interface

- Updated the NotificationRequest struct to include new fields: Title, Type, Priority, and ScheduledAt, improving the flexibility and usability of notification requests.
- Implemented validation for the new ScheduledAt field to ensure it is a future timestamp or zero for immediate delivery.
- Refactored the NotificationService interface and SDK methods to accept a new Model struct, streamlining the parameters for sending notifications.
- Enhanced the builder pattern for constructing notification requests, adding methods for setting Title, Type, Priority, and ScheduledAt, promoting a fluent API design.
- Updated service methods for sending notifications (Email, SMS, Push, OTP) to utilize the new Model struct, ensuring consistency across notification types.
This commit is contained in:
n.nakhostin
2025-09-20 15:29:00 +03:30
parent c6801ef2f3
commit 0857314906
4 changed files with 129 additions and 46 deletions
+18 -4
View File
@@ -24,10 +24,14 @@ type NotificationMethods struct {
// NotificationRequest represents the request structure for sending notifications
type NotificationRequest struct {
EventType EventType `json:"event_type" valid:"required,in(EMAIL|SMS|PUSH|OTP)"`
Message string `json:"message" valid:"required,length(1|1000)"`
Methods NotificationMethods `json:"methods" valid:"required"`
UserID string `json:"user_id,omitempty" valid:"optional"`
UserID string `json:"user_id,omitempty" valid:"optional"`
Title string `json:"title" valid:"required"`
Message string `json:"message" valid:"required,length(1|1000)"`
Type string `json:"type" valid:"required,in(info|warning|alert|reject)"`
EventType EventType `json:"event_type" valid:"required,in(EMAIL|SMS|PUSH|OTP)"`
Priority string `json:"priority" valid:"required,in(low|medium|important)"`
ScheduledAt int64 `json:"scheduled_at"`
Methods NotificationMethods `json:"methods" valid:"required"`
}
// NotificationResponse represents the successful response from notification service
@@ -67,6 +71,11 @@ func (nr *NotificationRequest) Validate() error {
}
}
// Validate scheduled_at: 0 means immediate delivery, otherwise must be future timestamp
if nr.ScheduledAt < 0 {
return ErrValidation{Field: "scheduled_at", Message: "scheduled_at cannot be negative"}
}
return nil
}
@@ -101,3 +110,8 @@ func (nm *NotificationMethods) GetMethodValue(eventType EventType) string {
return ""
}
}
// IsImmediate returns true if the notification should be sent immediately (scheduled_at = 0)
func (nr *NotificationRequest) IsImmediate() bool {
return nr.ScheduledAt == 0
}