chore: apply new logger to order actions
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"git.ma-al.com/goc_daniel/b2b/app/templ/emails"
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/view"
|
||||
)
|
||||
|
||||
@@ -44,6 +45,11 @@ func getLangID(isoCode string) uint {
|
||||
// SendEmail sends an email to the specified recipient
|
||||
func (s *EmailService) SendEmail(to, subject, body string) error {
|
||||
if !s.config.Enabled {
|
||||
logger.Debug("email service is disabled",
|
||||
"service", "EmailService.SendEmail",
|
||||
"to", to,
|
||||
"subject", subject,
|
||||
)
|
||||
return fmt.Errorf("email service is disabled")
|
||||
}
|
||||
|
||||
@@ -69,6 +75,12 @@ func (s *EmailService) SendEmail(to, subject, body string) error {
|
||||
// Send email
|
||||
addr := fmt.Sprintf("%s:%d", s.config.SMTPHost, s.config.SMTPPort)
|
||||
if err := smtp.SendMail(addr, auth, s.config.FromEmail, []string{to}, []byte(msg.String())); err != nil {
|
||||
logger.Error("failed to send email",
|
||||
"service", "EmailService.SendEmail",
|
||||
"to", to,
|
||||
"subject", subject,
|
||||
"error", err.Error(),
|
||||
)
|
||||
return fmt.Errorf("failed to send email: %w", err)
|
||||
}
|
||||
|
||||
@@ -120,9 +132,12 @@ func (s *EmailService) SendNewUserAdminNotification(userEmail, userName, baseURL
|
||||
// SendNewOrderPlacedNotification sends an email to admin when new order is placed
|
||||
func (s *EmailService) SendNewOrderPlacedNotification(userID uint) error {
|
||||
if s.config.AdminEmail == "" {
|
||||
return nil // No admin email configured
|
||||
logger.Warn("no admin email setup in the config",
|
||||
"service", "EmailService.SendNewOrderPlacedNotification",
|
||||
"user_id", userID,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
fmt.Printf("userID: %v\n", userID)
|
||||
subject := "New Order Created"
|
||||
body := s.newOrderPlacedTemplate(userID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user