Auto-RSVP when claiming a slot
Claiming a slot now also adds the person to the going list if they aren't already there (case-insensitive name match). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,9 @@ DELETE FROM rsvps WHERE id = ?;
|
||||
-- name: CountRsvps :one
|
||||
SELECT COUNT(*) FROM rsvps WHERE event_id = ?;
|
||||
|
||||
-- name: GetRsvpByName :one
|
||||
SELECT * FROM rsvps WHERE event_id = ? AND name = ? COLLATE NOCASE LIMIT 1;
|
||||
|
||||
-- name: GetUserByPhone :one
|
||||
SELECT * FROM users WHERE phone = ?;
|
||||
|
||||
|
||||
@@ -321,6 +321,28 @@ func (q *Queries) GetEventBySlug(ctx context.Context, slug string) (Event, error
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getRsvpByName = `-- name: GetRsvpByName :one
|
||||
SELECT id, event_id, name, note, created_at FROM rsvps WHERE event_id = ? AND name = ? COLLATE NOCASE LIMIT 1
|
||||
`
|
||||
|
||||
type GetRsvpByNameParams struct {
|
||||
EventID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
func (q *Queries) GetRsvpByName(ctx context.Context, arg GetRsvpByNameParams) (Rsvp, error) {
|
||||
row := q.db.QueryRowContext(ctx, getRsvpByName, arg.EventID, arg.Name)
|
||||
var i Rsvp
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.Name,
|
||||
&i.Note,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSession = `-- name: GetSession :one
|
||||
SELECT token, user_id, expires_at FROM sessions WHERE token = ? AND expires_at > CURRENT_TIMESTAMP
|
||||
`
|
||||
|
||||
+10
@@ -310,6 +310,16 @@ func (s *Server) handleClaim(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Auto-RSVP if they're not already on the going list
|
||||
_, err = s.q.GetRsvpByName(r.Context(), db.GetRsvpByNameParams{
|
||||
EventID: event.ID, Name: name,
|
||||
})
|
||||
if err == sql.ErrNoRows {
|
||||
s.q.CreateRsvp(r.Context(), db.CreateRsvpParams{
|
||||
EventID: event.ID, Name: name,
|
||||
})
|
||||
}
|
||||
|
||||
s.notify(slug)
|
||||
|
||||
// Return updated slots partial
|
||||
|
||||
Reference in New Issue
Block a user