From d2f7c6a1e5d93339b34147dbfe97ac95a09dc87c Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Sat, 20 Sep 2025 15:35:53 +0330 Subject: [PATCH] Refactor Notification Email Structure in Customer and User Services - Updated the email notification logic in the customer and user service layers to utilize the new notification Model struct, enhancing the clarity and consistency of notification requests. - Modified the email content to include structured fields such as Title, Message, Type, Priority, and UserID, improving the overall notification management. - Ensured that all relevant service methods (Register, UpdateStatus, RequestResetPassword, ResetPassword) are updated to reflect these changes, promoting a unified approach to notification handling. --- internal/customer/service.go | 36 ++++++++++++++++++++++++++++++++---- internal/user/service.go | 27 ++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/internal/customer/service.go b/internal/customer/service.go index ca3af1a..d95b62e 100644 --- a/internal/customer/service.go +++ b/internal/customer/service.go @@ -135,7 +135,14 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm "company_ids": Companies, }) - go s.notification.SendEmail(ctx, customer.Email, fmt.Sprintf("Welcome to Tender Management\nUsername: %s\nPassword: %s", customer.Username, form.Password), customer.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: customer.Email, + Title: "Welcome to Opplens", + Message: fmt.Sprintf("Welcome to Opplens\nUsername: %s\nPassword: %s", customer.Username, form.Password), + Type: "info", + Priority: "important", + UserID: customer.ID.Hex(), + }) return customer.ToResponse(nil), nil } @@ -332,7 +339,14 @@ func (s *customerService) UpdateStatus(ctx context.Context, id string, form *Upd "status": form.Status, }) - go s.notification.SendEmail(ctx, customer.Email, fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)), customer.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: customer.Email, + Title: "Account Status Updated", + Message: fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)), + Type: "warning", + Priority: "important", + UserID: customer.ID.Hex(), + }) return nil } @@ -794,7 +808,14 @@ func (s *customerService) RequestResetPassword(ctx context.Context, form *Reques } // Send OTP via email - go s.notification.SendEmail(ctx, form.Email, fmt.Sprintf("Your password reset code is: %s", otpCode), customer.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: form.Email, + Title: "Password Reset", + Message: fmt.Sprintf("Your password reset code is: %s", otpCode), + Type: "info", + Priority: "important", + UserID: customer.ID.Hex(), + }) s.logger.Info("Password reset OTP sent successfully", map[string]interface{}{ "email": form.Email, @@ -982,7 +1003,14 @@ func (s *customerService) ResetPassword(ctx context.Context, form *ResetPassword "customer_id": customer.ID, }) - go s.notification.SendEmail(ctx, tokenData.Email, "Your password has been reset successfully", customer.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: tokenData.Email, + Title: "Password Reset Success", + Message: "Your password has been reset successfully", + Type: "info", + Priority: "important", + UserID: customer.ID.Hex(), + }) return &ResetPasswordResponse{ Message: "Password reset successfully", diff --git a/internal/user/service.go b/internal/user/service.go index cd06c0a..cccc43f 100644 --- a/internal/user/service.go +++ b/internal/user/service.go @@ -117,7 +117,14 @@ func (s *userService) Register(ctx context.Context, form *CreateUserForm) (*User "role": user.Role, }) - go s.notification.SendEmail(ctx, form.Email, fmt.Sprintf("Welcome to Tender Management\nUsername: %s\nPassword: %s", form.Username, form.Password), user.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: form.Email, + Title: "Welcome to Opplens", + Message: fmt.Sprintf("Welcome to Opplens\nUsername: %s\nPassword: %s", form.Username, form.Password), + Type: "info", + Priority: "important", + UserID: user.ID.Hex(), + }) return user.ToResponse(), nil } @@ -221,7 +228,14 @@ func (s *userService) UpdateStatus(ctx context.Context, id string, form *UpdateU "status": form.Status, }) - go s.notification.SendEmail(ctx, user.Email, fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)), user.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: user.Email, + Title: "Account Status Updated", + Message: fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)), + Type: "warning", + Priority: "important", + UserID: user.ID.Hex(), + }) return nil } @@ -456,7 +470,14 @@ func (s *userService) ChangePassword(ctx context.Context, userID string, form *C "user_id": userID, }) - go s.notification.SendEmail(ctx, user.Email, "Your password has been reset successfully", user.ID.Hex()) + go s.notification.SendEmail(ctx, notification.Model{ + Recipient: user.Email, + Title: "Password Reset Success", + Message: "Your password has been reset successfully", + Type: "info", + Priority: "important", + UserID: user.ID.Hex(), + }) return nil }