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:
@@ -10,19 +10,22 @@ type NotificationService interface {
|
||||
SendNotification(ctx context.Context, req *NotificationRequest) (*NotificationResponse, error)
|
||||
|
||||
// SendEmail sends an email notification
|
||||
SendEmail(ctx context.Context, email, message, userID string) (*NotificationResponse, error)
|
||||
SendEmail(ctx context.Context, model Model) (*NotificationResponse, error)
|
||||
|
||||
// SendSMS sends an SMS notification
|
||||
SendSMS(ctx context.Context, phoneNumber, message, userID string) (*NotificationResponse, error)
|
||||
SendSMS(ctx context.Context, model Model) (*NotificationResponse, error)
|
||||
|
||||
// SendPush sends a push notification
|
||||
SendPush(ctx context.Context, deviceToken, message, userID string) (*NotificationResponse, error)
|
||||
SendPush(ctx context.Context, model Model) (*NotificationResponse, error)
|
||||
|
||||
// SendOTP sends an OTP notification
|
||||
SendOTP(ctx context.Context, phoneNumber, message, userID string) (*NotificationResponse, error)
|
||||
SendOTP(ctx context.Context, model Model) (*NotificationResponse, error)
|
||||
|
||||
// Health checks if the notification service is available
|
||||
Health(ctx context.Context) error
|
||||
|
||||
// NewBuilder creates a new notification builder
|
||||
NewBuilder() Builder
|
||||
}
|
||||
|
||||
// Builder provides a fluent interface for building notification requests
|
||||
@@ -48,6 +51,18 @@ type Builder interface {
|
||||
// SetOTP sets the OTP phone number
|
||||
SetOTP(phoneNumber string) Builder
|
||||
|
||||
// SetTitle sets the notification title
|
||||
SetTitle(title string) Builder
|
||||
|
||||
// SetType sets the notification type
|
||||
SetType(notificationType string) Builder
|
||||
|
||||
// SetPriority sets the notification priority
|
||||
SetPriority(priority string) Builder
|
||||
|
||||
// SetScheduledAt sets the scheduled delivery time (0 for immediate)
|
||||
SetScheduledAt(scheduledAt int64) Builder
|
||||
|
||||
// Build creates the notification request
|
||||
Build() (*NotificationRequest, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user