From 29bca402a4de9b0bc345e900b3f1975ef2404f1b Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Sun, 21 Sep 2025 14:59:40 +0330 Subject: [PATCH] Refactor Notification Sending Logic in Customer and User Services - Updated the notification sending logic in the customer and user service layers to send emails synchronously instead of using goroutines, improving clarity and ensuring immediate feedback on notification processing. - Ensured that all relevant service methods (Register, UpdateStatus, RequestResetPassword, ResetPassword) are updated to reflect these changes, promoting consistency in notification handling across services. --- internal/customer/service.go | 8 ++++---- internal/user/service.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/customer/service.go b/internal/customer/service.go index 910aa97..02966b6 100644 --- a/internal/customer/service.go +++ b/internal/customer/service.go @@ -145,7 +145,7 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm "company_ids": Companies, }) - go s.notification.SendEmail(ctx, notification.Model{ + 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), @@ -412,7 +412,7 @@ func (s *customerService) UpdateStatus(ctx context.Context, id string, form *Upd "status": form.Status, }) - go s.notification.SendEmail(ctx, notification.Model{ + 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)), @@ -858,7 +858,7 @@ func (s *customerService) RequestResetPassword(ctx context.Context, form *Reques } // Send OTP via email - go s.notification.SendEmail(ctx, notification.Model{ + s.notification.SendEmail(ctx, notification.Model{ Recipient: form.Email, Title: "Password Reset", Message: fmt.Sprintf("Your password reset code is: %s", otpCode), @@ -1053,7 +1053,7 @@ func (s *customerService) ResetPassword(ctx context.Context, form *ResetPassword "customer_id": customer.ID, }) - go s.notification.SendEmail(ctx, notification.Model{ + s.notification.SendEmail(ctx, notification.Model{ Recipient: tokenData.Email, Title: "Password Reset Success", Message: "Your password has been reset successfully", diff --git a/internal/user/service.go b/internal/user/service.go index 722321e..bfb9839 100644 --- a/internal/user/service.go +++ b/internal/user/service.go @@ -118,7 +118,7 @@ func (s *userService) Register(ctx context.Context, form *CreateUserForm) (*User "role": user.Role, }) - go s.notification.SendEmail(ctx, notification.Model{ + 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), @@ -229,7 +229,7 @@ func (s *userService) UpdateStatus(ctx context.Context, id string, form *UpdateU "status": form.Status, }) - go s.notification.SendEmail(ctx, notification.Model{ + 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)), @@ -488,7 +488,7 @@ func (s *userService) ChangePassword(ctx context.Context, userID string, form *C "user_id": userID, }) - go s.notification.SendEmail(ctx, notification.Model{ + s.notification.SendEmail(ctx, notification.Model{ Recipient: user.Email, Title: "Password Reset Success", Message: "Your password has been reset successfully",