fix(mail): include guest list in RSVP emails
This commit is contained in:
@@ -105,7 +105,11 @@ func (s *Server) handleRSVP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
log.Printf("rsvp: email failed: %v", err)
|
||||||
}
|
}
|
||||||
if err := s.webhook.SendRSVP(rsvp); err != nil {
|
if err := s.webhook.SendRSVP(rsvp); err != nil {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func (m *Mailer) send(subject, body string) error {
|
|||||||
return smtp.SendMail(addr, auth, m.cfg.From, recipients, []byte(msg))
|
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))
|
names := make([]string, len(r.Guests))
|
||||||
adults, children := 0, 0
|
adults, children := 0, 0
|
||||||
for i, g := range r.Guests {
|
for i, g := range r.Guests {
|
||||||
@@ -77,6 +77,22 @@ func (m *Mailer) SendRSVP(r store.RSVP) error {
|
|||||||
if r.Message != "" {
|
if r.Message != "" {
|
||||||
fmt.Fprintf(&b, "\nMessage:\n%s\n", 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())
|
return m.send(fmt.Sprintf("RSVP from %s", joined), b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user