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.
This commit is contained in:
n.nakhostin
2025-09-20 15:35:53 +03:30
parent 0857314906
commit d2f7c6a1e5
2 changed files with 56 additions and 7 deletions
+32 -4
View File
@@ -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",