feat(checkin): gate check-in/out, ticket activities and QR (#27) #102

Merged
amiryahaya merged 8 commits from feat/27-checkin into main 2026-10-26 18:02:46 +01:00
Owner

Closes #27. Prerequisite for the rest of #36 (overstay, vehicle add-on, ticket top-up).

What

  • Migration 0021: ticket statuses active -> checked_in -> checked_out (and active -> cancelled), check-in/out time and gate columns, check_in_number (unique, from numbering), a stricter tickets_guard, and an append-only ticket_activities log.
  • internal/checkin: Service.CheckIn / CheckOut, one transaction per scan, ticket rows locked in id order through an index-friendly query (a plan test guards it), check-in numbers taken last (numbering.TakeN, no gaps on rollback).
  • Routes (permission admin_portal.tickets.scan, Park Management and Super Admin): POST /v1/admin/gates/{id}/check-in, POST /v1/admin/gates/{id}/check-out, GET /v1/admin/tickets/{code}; customer QR GET /v1/me/tickets/{code}/qr (PNG of the bare code, owner only). /v1/me/tickets exposes the new status and times. OpenAPI and live contract tests; ADR 0017; plan docs/superpowers/plans/2026-10-26-checkin.md.

Rulings and known limits (ADR 0017)

  • Scanning a master checks in its active children valid today (owner decision); a child can also be scanned alone. All-or-nothing per request, at most 50 distinct codes; a second scan is a 409.
  • Overstay follows the legacy rule; staff can let an overstayed visitor out (checkout_overstay); charging overstay is #36.
  • [verify] Early entry is refused before visit_date; legacy never checked dates. Confirm with the business.
  • Scan permission is not scoped to a park; the Checker role belongs to the checker app (#68/#69), which needs its own guard.
  • All check-ins queue briefly on one counter row (the price of gap-free numbers).
  • visit_date, expires_at and holder_name stay editable by hand-written SQL (known limit g). No vehicle scans, no reports (#38).
  • The code (a secret) never appears in logs; {code} routes are logged by pattern.

Review

Dual pass done. Pass 1: no Must fix. Pass 2 found a full-table-scan lock query and a master scan that failed for sales with several visit dates; both fixed in edc18ee with the smaller items; Pass 1 re-check: Ship. Open nits: the plan test depends on Postgres planner output; a cancelled master also blocks check-out (cannot happen yet).

Checks

make cover: 89.5% (minimum 80%). go test -race ./..., make lint, make contract and client generation green (implementer run); the lock query was measured only in review, not at production scale.

Deploy

Run migration 0021. No new environment variables, no worker change. Grant admin_portal.tickets.scan through the Park Management role (re-applied by KWS_MODE=migrate).

🤖 Generated with Claude Code

Closes #27. Prerequisite for the rest of #36 (overstay, vehicle add-on, ticket top-up). ## What - **Migration 0021:** ticket statuses `active -> checked_in -> checked_out` (and `active -> cancelled`), check-in/out time and gate columns, `check_in_number` (unique, from `numbering`), a stricter `tickets_guard`, and an append-only `ticket_activities` log. - **`internal/checkin`:** `Service.CheckIn` / `CheckOut`, one transaction per scan, ticket rows locked in id order through an index-friendly query (a plan test guards it), check-in numbers taken last (`numbering.TakeN`, no gaps on rollback). - **Routes** (permission `admin_portal.tickets.scan`, Park Management and Super Admin): `POST /v1/admin/gates/{id}/check-in`, `POST /v1/admin/gates/{id}/check-out`, `GET /v1/admin/tickets/{code}`; customer QR `GET /v1/me/tickets/{code}/qr` (PNG of the bare code, owner only). `/v1/me/tickets` exposes the new status and times. OpenAPI and live contract tests; ADR 0017; plan `docs/superpowers/plans/2026-10-26-checkin.md`. ## Rulings and known limits (ADR 0017) - Scanning a master checks in its active children valid today (owner decision); a child can also be scanned alone. All-or-nothing per request, at most 50 distinct codes; a second scan is a 409. - Overstay follows the legacy rule; staff can let an overstayed visitor out (`checkout_overstay`); charging overstay is #36. - **[verify] Early entry is refused before `visit_date`; legacy never checked dates. Confirm with the business.** - Scan permission is not scoped to a park; the Checker role belongs to the checker app (#68/#69), which needs its own guard. - All check-ins queue briefly on one counter row (the price of gap-free numbers). - `visit_date`, `expires_at` and `holder_name` stay editable by hand-written SQL (known limit g). No vehicle scans, no reports (#38). - The code (a secret) never appears in logs; `{code}` routes are logged by pattern. ## Review Dual pass done. Pass 1: no Must fix. Pass 2 found a full-table-scan lock query and a master scan that failed for sales with several visit dates; both fixed in edc18ee with the smaller items; Pass 1 re-check: Ship. Open nits: the plan test depends on Postgres planner output; a cancelled master also blocks check-out (cannot happen yet). ## Checks `make cover`: **89.5%** (minimum 80%). `go test -race ./...`, `make lint`, `make contract` and client generation green (implementer run); the lock query was measured only in review, not at production scale. ## Deploy Run migration 0021. No new environment variables, no worker change. Grant `admin_portal.tickets.scan` through the Park Management role (re-applied by `KWS_MODE=migrate`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(checkin): indexed family lock, per-day master scans, cancelled masters, busy lookup (#27)
Some checks failed
ci / changes (pull_request) Successful in 1m0s
ci / clients (pull_request) Successful in 4m51s
ci / api (pull_request) Failing after 26m48s
ci / ci-gate (pull_request) Failing after 3s
edc18ee644
Review fixes: the lock query finds children through the parent index (a plan test
guards it); a master scan skips children not valid today; a cancelled master lets
no child in; the ticket lookup maps ErrBusy to 503; spec and ADR 0017 wording.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge main into feat/27-checkin (seats test flake fix)
All checks were successful
ci / changes (pull_request) Successful in 32s
ci / clients (pull_request) Successful in 1m24s
ci / api (pull_request) Successful in 21m29s
ci / ci-gate (pull_request) Successful in 2s
229d026931
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!102
No description provided.