From e7022124be1accb5040d95069e868293a4398eff Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 18 May 2026 23:15:48 -0400 Subject: [PATCH] Delete auto-RSVP on unclaim and count going from RSVPs only Co-Authored-By: Claude Opus 4.6 --- db/queries.sql | 3 +++ db/queries.sql.go | 17 +++++++++++++++++ handlers.go | 25 ++++++++++++++++--------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/db/queries.sql b/db/queries.sql index 4c0ae99..761620c 100644 --- a/db/queries.sql +++ b/db/queries.sql @@ -49,6 +49,9 @@ INSERT INTO claims (slot_id, name, note) VALUES (?, ?, ?) RETURNING *; +-- name: GetClaimByID :one +SELECT * FROM claims WHERE id = ?; + -- name: DeleteClaim :exec DELETE FROM claims WHERE id = ?; diff --git a/db/queries.sql.go b/db/queries.sql.go index e3ed5ff..23411dd 100644 --- a/db/queries.sql.go +++ b/db/queries.sql.go @@ -295,6 +295,23 @@ func (q *Queries) DeleteSlot(ctx context.Context, id int64) error { return err } +const getClaimByID = `-- name: GetClaimByID :one +SELECT id, slot_id, name, note, created_at FROM claims WHERE id = ? +` + +func (q *Queries) GetClaimByID(ctx context.Context, id int64) (Claim, error) { + row := q.db.QueryRowContext(ctx, getClaimByID, id) + var i Claim + err := row.Scan( + &i.ID, + &i.SlotID, + &i.Name, + &i.Note, + &i.CreatedAt, + ) + return i, err +} + const getEventByAdminToken = `-- name: GetEventByAdminToken :one SELECT id, slug, title, date, time, location, admin_token, description, user_id, created_at FROM events WHERE admin_token = ? ` diff --git a/handlers.go b/handlers.go index 3e46484..9f5c613 100644 --- a/handlers.go +++ b/handlers.go @@ -203,18 +203,10 @@ func (s *Server) loadEventPage(r *http.Request, slug string, isAdmin bool) (*Eve totalGoing += 1 + r.PlusOne } - // Build deduplicated GoingList: RSVPs first, then claim-only people + // Build GoingList from RSVPs only var goingList []GoingPerson - seen := make(map[string]bool) for _, r := range rsvps { goingList = append(goingList, GoingPerson{Name: r.Name, Note: r.Note, RsvpID: r.ID, PlusOne: r.PlusOne}) - seen[strings.ToLower(r.Name)] = true - } - for _, c := range claims { - if !seen[strings.ToLower(c.Name)] { - goingList = append(goingList, GoingPerson{Name: c.Name}) - seen[strings.ToLower(c.Name)] = true - } } var descHTML template.HTML @@ -271,6 +263,21 @@ func (s *Server) handleUnclaim(w http.ResponseWriter, r *http.Request) { return } + // Look up the claim to get the name, then delete the auto-created RSVP + claim, err := s.q.GetClaimByID(r.Context(), claimID) + if err == nil { + event, err := s.q.GetEventBySlug(r.Context(), slug) + if err == nil { + rsvp, err := s.q.GetRsvpByName(r.Context(), db.GetRsvpByNameParams{ + EventID: event.ID, + Name: claim.Name, + }) + if err == nil { + s.q.DeleteRsvp(r.Context(), rsvp.ID) + } + } + } + err = s.q.DeleteClaim(r.Context(), claimID) if err != nil { http.Error(w, "Failed to remove", http.StatusInternalServerError)