feat(api): add endpoint to fetch guest list
* implement ListGuests method in store * create handleGuestList function in API * add GuestListEntry and GuestList interfaces in UI * create guest list page to display RSVPs
This commit is contained in:
@@ -33,6 +33,7 @@ func (s *Server) Routes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /healthz", s.handleHealthz)
|
||||
mux.HandleFunc("GET /api/config", s.handleConfig)
|
||||
mux.HandleFunc("POST /api/rsvp", s.handleRSVP)
|
||||
mux.HandleFunc("GET /api/guests", s.handleGuestList)
|
||||
mux.HandleFunc("POST /api/photos/upload", s.handlePhotoUpload)
|
||||
}
|
||||
|
||||
@@ -108,6 +109,38 @@ func (s *Server) handleRSVP(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusCreated, map[string]bool{"ok": true})
|
||||
}
|
||||
|
||||
type guestResponse struct {
|
||||
Name string `json:"name"`
|
||||
IsChild bool `json:"isChild"`
|
||||
}
|
||||
|
||||
func (s *Server) handleGuestList(w http.ResponseWriter, r *http.Request) {
|
||||
guests, err := s.store.ListGuests()
|
||||
if err != nil {
|
||||
log.Printf("guests: list failed: %v", err)
|
||||
writeError(w, http.StatusInternalServerError, "could not load guests")
|
||||
return
|
||||
}
|
||||
|
||||
out := make([]guestResponse, 0, len(guests))
|
||||
adults, children := 0, 0
|
||||
for _, g := range guests {
|
||||
out = append(out, guestResponse{Name: g.Name, IsChild: g.IsChild})
|
||||
if g.IsChild {
|
||||
children++
|
||||
} else {
|
||||
adults++
|
||||
}
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"guests": out,
|
||||
"total": len(out),
|
||||
"adults": adults,
|
||||
"children": children,
|
||||
})
|
||||
}
|
||||
|
||||
var allowedImageTypes = map[string]bool{
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
|
||||
Reference in New Issue
Block a user