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:
@@ -135,7 +135,14 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm
|
|||||||
"company_ids": Companies,
|
"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
|
return customer.ToResponse(nil), nil
|
||||||
}
|
}
|
||||||
@@ -332,7 +339,14 @@ func (s *customerService) UpdateStatus(ctx context.Context, id string, form *Upd
|
|||||||
"status": form.Status,
|
"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
|
return nil
|
||||||
}
|
}
|
||||||
@@ -794,7 +808,14 @@ func (s *customerService) RequestResetPassword(ctx context.Context, form *Reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send OTP via email
|
// 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{}{
|
s.logger.Info("Password reset OTP sent successfully", map[string]interface{}{
|
||||||
"email": form.Email,
|
"email": form.Email,
|
||||||
@@ -982,7 +1003,14 @@ func (s *customerService) ResetPassword(ctx context.Context, form *ResetPassword
|
|||||||
"customer_id": customer.ID,
|
"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{
|
return &ResetPasswordResponse{
|
||||||
Message: "Password reset successfully",
|
Message: "Password reset successfully",
|
||||||
|
|||||||
@@ -117,7 +117,14 @@ func (s *userService) Register(ctx context.Context, form *CreateUserForm) (*User
|
|||||||
"role": user.Role,
|
"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
|
return user.ToResponse(), nil
|
||||||
}
|
}
|
||||||
@@ -221,7 +228,14 @@ func (s *userService) UpdateStatus(ctx context.Context, id string, form *UpdateU
|
|||||||
"status": form.Status,
|
"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
|
return nil
|
||||||
}
|
}
|
||||||
@@ -456,7 +470,14 @@ func (s *userService) ChangePassword(ctx context.Context, userID string, form *C
|
|||||||
"user_id": userID,
|
"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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user