feat(api): dynamic forms and form inputs with semantic purposes (#19, part 1) #84

Merged
amiryahaya merged 1 commit from feat/forms into main 2026-10-23 07:57:29 +02:00
Owner

Part 1 of #19 (does not close it: settings are part 2).

What

Dynamic forms: the questions a product asks per ticket (guest name, email, ID or passport, nationality, vehicle plate).

  • Migration 0008: forms and form_inputs (soft-deleted, because tickets keep their answers), all 18 legacy input types kept, and the foreign key products.form_id -> forms that migration 0007 deferred.
  • New: purpose. A field may say what it means (email, name, identity_number, nationality, vehicle_registration), at most one live field per purpose in a form. The legacy code found the customer's email, name, ID and nationality by sniffing the label (Label.Contains("ID"), Label.Equals("Email")), which broke as soon as an administrator renamed a label and could match unrelated labels. The ticket and notification code will look fields up by purpose.
  • API (internal/forms): public cacheable GET /v1/forms/{id} (active form and fields only, ordered); admin CRUD under /v1/admin/forms and /v1/admin/form-inputs gated by administration.manage, optimistic locking, versioned soft delete. A form that live products use cannot be removed (409); removing a form removes its fields.
  • Test helper: the same fake permission guard had been pasted into three test files; it is now one shared rbactest package (excluded from coverage like pgtest and authtest), and catalog, lookups and forms tests use it.

Standards review (docs/development-standards.md)

  • TDD: schema, validation, handler, store and end-to-end tests first; disabling the "form in use" rule fails two tests.
  • SOLID / coupling: FormStore and FieldStore are separate narrow interfaces; the handler takes them separately; shared plumbing reused (rest, pgrest), no copies.
  • Coverage: 94.9% total; forms 100%, forms store 96.1%. make lint 0 issues. Security scans run on main after merge.

Known limits

  • A field's grid column is not checked against the form's column count.
  • Whether radio, gender and similar types need option lists is unknown: legacy stores only a default value, so options live in the client. Kept as is.
  • [verify] the legacy "capacity" setting (max people per day) is read but every use is commented out; not enforced today, not built.

Next (part 2, closes #19)

Settings: a catalog of known keys in code (tax, convenience fee, notification emails) with typed validation, values editable as data, optional per-park override.

🤖 Generated with Claude Code

Part 1 of #19 (does not close it: settings are part 2). ## What Dynamic forms: the questions a product asks per ticket (guest name, email, ID or passport, nationality, vehicle plate). - **Migration 0008**: `forms` and `form_inputs` (soft-deleted, because tickets keep their answers), all 18 legacy input types kept, and the foreign key `products.form_id -> forms` that migration 0007 deferred. - **New: `purpose`.** A field may say what it means (`email`, `name`, `identity_number`, `nationality`, `vehicle_registration`), at most one live field per purpose in a form. The legacy code found the customer's email, name, ID and nationality by sniffing the label (`Label.Contains("ID")`, `Label.Equals("Email")`), which broke as soon as an administrator renamed a label and could match unrelated labels. The ticket and notification code will look fields up by purpose. - **API** (`internal/forms`): public cacheable `GET /v1/forms/{id}` (active form and fields only, ordered); admin CRUD under `/v1/admin/forms` and `/v1/admin/form-inputs` gated by `administration.manage`, optimistic locking, versioned soft delete. A form that live products use cannot be removed (409); removing a form removes its fields. - **Test helper**: the same fake permission guard had been pasted into three test files; it is now one shared `rbactest` package (excluded from coverage like `pgtest` and `authtest`), and catalog, lookups and forms tests use it. ## Standards review (docs/development-standards.md) - **TDD**: schema, validation, handler, store and end-to-end tests first; disabling the "form in use" rule fails two tests. - **SOLID / coupling**: `FormStore` and `FieldStore` are separate narrow interfaces; the handler takes them separately; shared plumbing reused (`rest`, `pgrest`), no copies. - **Coverage**: 94.9% total; forms 100%, forms store 96.1%. `make lint` 0 issues. Security scans run on `main` after merge. ## Known limits - A field's grid column is not checked against the form's column count. - Whether `radio`, `gender` and similar types need option lists is unknown: legacy stores only a default value, so options live in the client. Kept as is. - **[verify]** the legacy "capacity" setting (max people per day) is read but every use is commented out; not enforced today, not built. ## Next (part 2, closes #19) Settings: a catalog of known keys in code (tax, convenience fee, notification emails) with typed validation, values editable as data, optional per-park override. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(api): dynamic forms and form inputs with semantic purposes (part 1 of #19)
All checks were successful
ci / changes (pull_request) Successful in 11s
ci / api (pull_request) Successful in 5m39s
ci / ci-gate (pull_request) Successful in 3s
1755061cc6
Migration 0008: forms and form_inputs (soft-deleted, all 18 legacy input types kept, purpose replaces
label sniffing, at most one live input per purpose) and the missing products.form_id foreign key.
internal/forms: public cacheable form read, admin CRUD gated by administration.manage, a form used by
live products cannot be removed. Extracts rbactest (shared fake guard) from three test files.

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!84
No description provided.