Delete auto-RSVP on unclaim and count going from RSVPs only
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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 = ?;
|
||||
|
||||
|
||||
@@ -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 = ?
|
||||
`
|
||||
|
||||
+16
-9
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user