fix(mail): include guest list in RSVP emails

This commit is contained in:
2026-08-23 11:41:08 +02:00
parent 5b3c256a5e
commit 79e4c11a16
2 changed files with 22 additions and 2 deletions
+5 -1
View File
@@ -105,7 +105,11 @@ func (s *Server) handleRSVP(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.mailer.SendRSVP(rsvp); err != nil {
allGuests, err := s.store.ListGuests()
if err != nil {
log.Printf("rsvp: list guests failed: %v", err)
}
if err := s.mailer.SendRSVP(rsvp, allGuests); err != nil {
log.Printf("rsvp: email failed: %v", err)
}
if err := s.webhook.SendRSVP(rsvp); err != nil {
+17 -1
View File
@@ -58,7 +58,7 @@ func (m *Mailer) send(subject, body string) error {
return smtp.SendMail(addr, auth, m.cfg.From, recipients, []byte(msg))
}
func (m *Mailer) SendRSVP(r store.RSVP) error {
func (m *Mailer) SendRSVP(r store.RSVP, allGuests []store.Guest) error {
names := make([]string, len(r.Guests))
adults, children := 0, 0
for i, g := range r.Guests {
@@ -77,6 +77,22 @@ func (m *Mailer) SendRSVP(r store.RSVP) error {
if r.Message != "" {
fmt.Fprintf(&b, "\nMessage:\n%s\n", r.Message)
}
if len(allGuests) > 0 {
totalAdults, totalChildren := 0, 0
fmt.Fprintf(&b, "\nRSVPs so far (%d guest(s)):\n", len(allGuests))
for _, g := range allGuests {
if g.IsChild {
totalChildren++
fmt.Fprintf(&b, "- %s (child)\n", g.Name)
} else {
totalAdults++
fmt.Fprintf(&b, "- %s\n", g.Name)
}
}
fmt.Fprintf(&b, "\n%d adult(s), %d child(ren) total\n", totalAdults, totalChildren)
}
return m.send(fmt.Sprintf("RSVP from %s", joined), b.String())
}