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
+16 -16
View File
@@ -55,23 +55,23 @@ func (s *SDK) SendNotification(ctx context.Context, req *NotificationRequest) (*
}
// SendEmail sends an email notification
func (s *SDK) SendEmail(ctx context.Context, email, message, userID string) (*NotificationResponse, error) {
return s.service.SendEmail(ctx, email, message, userID)
func (s *SDK) SendEmail(ctx context.Context, model Model) (*NotificationResponse, error) {
return s.service.SendEmail(ctx, model)
}
// SendSMS sends an SMS notification
func (s *SDK) SendSMS(ctx context.Context, phoneNumber, message, userID string) (*NotificationResponse, error) {
return s.service.SendSMS(ctx, phoneNumber, message, userID)
func (s *SDK) SendSMS(ctx context.Context, model Model) (*NotificationResponse, error) {
return s.service.SendSMS(ctx, model)
}
// SendPush sends a push notification
func (s *SDK) SendPush(ctx context.Context, deviceToken, message, userID string) (*NotificationResponse, error) {
return s.service.SendPush(ctx, deviceToken, message, userID)
func (s *SDK) SendPush(ctx context.Context, model Model) (*NotificationResponse, error) {
return s.service.SendPush(ctx, model)
}
// SendOTP sends an OTP notification
func (s *SDK) SendOTP(ctx context.Context, phoneNumber, message, userID string) (*NotificationResponse, error) {
return s.service.SendOTP(ctx, phoneNumber, message, userID)
func (s *SDK) SendOTP(ctx context.Context, model Model) (*NotificationResponse, error) {
return s.service.SendOTP(ctx, model)
}
// NewBuilder creates a new notification builder for fluent API usage
@@ -92,26 +92,26 @@ func (s *SDK) GetConfig() *Config {
// Convenience functions for quick notifications
// QuickEmail sends a simple email notification
func (s *SDK) QuickEmail(ctx context.Context, email, message string) error {
_, err := s.SendEmail(ctx, email, message, "")
func (s *SDK) QuickEmail(ctx context.Context, model Model) error {
_, err := s.SendEmail(ctx, model)
return err
}
// QuickSMS sends a simple SMS notification
func (s *SDK) QuickSMS(ctx context.Context, phoneNumber, message string) error {
_, err := s.SendSMS(ctx, phoneNumber, message, "")
func (s *SDK) QuickSMS(ctx context.Context, model Model) error {
_, err := s.SendSMS(ctx, model)
return err
}
// QuickPush sends a simple push notification
func (s *SDK) QuickPush(ctx context.Context, deviceToken, message string) error {
_, err := s.SendPush(ctx, deviceToken, message, "")
func (s *SDK) QuickPush(ctx context.Context, model Model) error {
_, err := s.SendPush(ctx, model)
return err
}
// QuickOTP sends a simple OTP notification
func (s *SDK) QuickOTP(ctx context.Context, phoneNumber, message string) error {
_, err := s.SendOTP(ctx, phoneNumber, message, "")
func (s *SDK) QuickOTP(ctx context.Context, model Model) error {
_, err := s.SendOTP(ctx, model)
return err
}