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.
This commit is contained in:
@@ -145,7 +145,7 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm
|
|||||||
"company_ids": Companies,
|
"company_ids": Companies,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: customer.Email,
|
Recipient: customer.Email,
|
||||||
Title: "Welcome to Opplens",
|
Title: "Welcome to Opplens",
|
||||||
Message: fmt.Sprintf("Welcome to Opplens\nUsername: %s\nPassword: %s", customer.Username, form.Password),
|
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,
|
"status": form.Status,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: customer.Email,
|
Recipient: customer.Email,
|
||||||
Title: "Account Status Updated",
|
Title: "Account Status Updated",
|
||||||
Message: fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)),
|
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
|
// Send OTP via email
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: form.Email,
|
Recipient: form.Email,
|
||||||
Title: "Password Reset",
|
Title: "Password Reset",
|
||||||
Message: fmt.Sprintf("Your password reset code is: %s", otpCode),
|
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,
|
"customer_id": customer.ID,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: tokenData.Email,
|
Recipient: tokenData.Email,
|
||||||
Title: "Password Reset Success",
|
Title: "Password Reset Success",
|
||||||
Message: "Your password has been reset successfully",
|
Message: "Your password has been reset successfully",
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func (s *userService) Register(ctx context.Context, form *CreateUserForm) (*User
|
|||||||
"role": user.Role,
|
"role": user.Role,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: form.Email,
|
Recipient: form.Email,
|
||||||
Title: "Welcome to Opplens",
|
Title: "Welcome to Opplens",
|
||||||
Message: fmt.Sprintf("Welcome to Opplens\nUsername: %s\nPassword: %s", form.Username, form.Password),
|
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,
|
"status": form.Status,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: user.Email,
|
Recipient: user.Email,
|
||||||
Title: "Account Status Updated",
|
Title: "Account Status Updated",
|
||||||
Message: fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)),
|
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,
|
"user_id": userID,
|
||||||
})
|
})
|
||||||
|
|
||||||
go s.notification.SendEmail(ctx, notification.Model{
|
s.notification.SendEmail(ctx, notification.Model{
|
||||||
Recipient: user.Email,
|
Recipient: user.Email,
|
||||||
Title: "Password Reset Success",
|
Title: "Password Reset Success",
|
||||||
Message: "Your password has been reset successfully",
|
Message: "Your password has been reset successfully",
|
||||||
|
|||||||
Reference in New Issue
Block a user