fix: connect EmailService to contact form handler

The contact form was logging submissions but never actually sending emails.
This commit:
- Adds EmailService field to CVHandler
- Initializes EmailService in main.go with SMTP config
- Calls SendContactForm in HandleContact handler
- Updates all test files to pass nil for emailService parameter
This commit is contained in:
juanatsap
2025-12-02 14:27:03 +00:00
parent 9842f183ea
commit f3842a3486
9 changed files with 66 additions and 30 deletions
+23 -3
View File
@@ -9,6 +9,7 @@ import (
"time"
uimodel "github.com/juanatsap/cv-site/internal/models/ui"
"github.com/juanatsap/cv-site/internal/services"
)
// ==============================================================================
@@ -81,14 +82,33 @@ func (h *CVHandler) HandleContact(w http.ResponseWriter, r *http.Request) {
return
}
// Log the contact form submission (in production, send email or save to database)
// Log the contact form submission
log.Printf("Contact form submission from %s (IP: %s)", formData.Email, getClientIP(r))
log.Printf(" Name: %s, Company: %s", formData.Name, formData.Company)
log.Printf(" Subject: %s", formData.Subject)
log.Printf(" Message length: %d characters", len(formData.Message))
// TODO: Implement actual email sending or database storage here
// For now, we just log and return success
// Send email via EmailService
if h.emailService != nil {
emailData := &services.ContactFormData{
Email: formData.Email,
Name: formData.Name,
Company: formData.Company,
Subject: formData.Subject,
Message: formData.Message,
IP: getClientIP(r),
Time: time.Now(),
}
if err := h.emailService.SendContactForm(emailData); err != nil {
log.Printf("ERROR sending contact email: %v", err)
h.renderContactError(w, r, "Failed to send message. Please try again later.")
return
}
log.Printf("Contact email sent successfully to configured recipient")
} else {
log.Printf("WARNING: Email service not configured, skipping email send")
}
// Render success response
h.renderContactSuccess(w, r, lang)