feat(api): global settings with a typed key catalog (#19, part 2) #85

Merged
amiryahaya merged 1 commit from feat/settings into main 2026-10-23 10:47:34 +02:00
Owner

Closes #19 (part 2 of 2; part 1 was #84).

What

Global settings: the few values the business tunes.

  • Keys are code, values are data. The catalog (internal/settings) defines tax and convenience_fee (percentages 0 to 100, up to 4 decimals) and notification_email and notification_bcc_email (one plain address). A value is validated against its key's type when it is saved. Legacy found settings by display name ("Tax", "Convenience Fee", "Email", "BCC Email") and parsed the text at checkout (decimal.Parse), so one bad value crashed it.
  • Migration 0009: settings (one row per key), row-audited with old and new values, so a tax change is traceable to who and when.
  • API (admin only, administration.manage): GET /v1/admin/settings/keys (the catalog, for the admin screen), GET/POST /v1/admin/settings, PUT/DELETE /v1/admin/settings/{id} with optimistic locking. Deleting a value unsets the key. A setting cannot be repointed at another key.

Decisions to confirm

  • Global only. Legacy rows could name a park, but its reader (GetSettingByNameAsync) ignores the park, so a per-park value never took effect. I did not build per-park overrides; add a park scope when something needs it.
  • No capacity key. The legacy capacity setting is read in the ticket flow but every use is commented out, so capacity limits are not enforced today (also noted as [verify] in the spec).
  • Checkout will read these through a typed reader when the transaction module (#26) needs it; it is not built ahead of its consumer.

Standards review (docs/development-standards.md)

  • TDD: catalog and validation, handler, schema, store and end-to-end tests first. I mutated the store's "key cannot change" rule twice: the first mutation failed every update through an invalid query (right result, wrong reason), so I redid it with a valid query and confirmed the intended test fails. The standards doc now says to check the reason.
  • SOLID / coupling: one narrow SettingStore; shared rest/pgrest plumbing; rbactest guard reused. The catalog is the only place that knows the keys.
  • Coverage: 95.0% total; settings 100%, settings store 93.9%. make lint 0 issues. Security scans run on main after merge.

🤖 Generated with Claude Code

Closes #19 (part 2 of 2; part 1 was #84). ## What Global settings: the few values the business tunes. - **Keys are code, values are data.** The catalog (`internal/settings`) defines `tax` and `convenience_fee` (percentages 0 to 100, up to 4 decimals) and `notification_email` and `notification_bcc_email` (one plain address). A value is validated against its key's type **when it is saved**. Legacy found settings by display name (`"Tax"`, `"Convenience Fee"`, `"Email"`, `"BCC Email"`) and parsed the text at checkout (`decimal.Parse`), so one bad value crashed it. - **Migration 0009**: `settings` (one row per key), row-audited with old and new values, so a tax change is traceable to who and when. - **API** (admin only, `administration.manage`): `GET /v1/admin/settings/keys` (the catalog, for the admin screen), `GET/POST /v1/admin/settings`, `PUT/DELETE /v1/admin/settings/{id}` with optimistic locking. Deleting a value unsets the key. A setting cannot be repointed at another key. ## Decisions to confirm - **Global only.** Legacy rows could name a park, but its reader (`GetSettingByNameAsync`) ignores the park, so a per-park value never took effect. I did not build per-park overrides; add a park scope when something needs it. - **No `capacity` key.** The legacy capacity setting is read in the ticket flow but every use is commented out, so capacity limits are not enforced today (also noted as **[verify]** in the spec). - Checkout will read these through a typed reader when the transaction module (#26) needs it; it is not built ahead of its consumer. ## Standards review (docs/development-standards.md) - **TDD**: catalog and validation, handler, schema, store and end-to-end tests first. I mutated the store's "key cannot change" rule twice: the first mutation failed every update through an invalid query (right result, wrong reason), so I redid it with a valid query and confirmed the intended test fails. The standards doc now says to check the reason. - **SOLID / coupling**: one narrow `SettingStore`; shared `rest`/`pgrest` plumbing; `rbactest` guard reused. The catalog is the only place that knows the keys. - **Coverage**: 95.0% total; settings 100%, settings store 93.9%. `make lint` 0 issues. Security scans run on `main` after merge. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(api): global settings with a typed key catalog (closes #19)
All checks were successful
ci / changes (pull_request) Successful in 11s
ci / api (pull_request) Successful in 5m45s
ci / ci-gate (pull_request) Successful in 4s
dee745473b
Migration 0009: settings table, one value per key, audited with old and new values. internal/settings:
the keys (tax, convenience_fee, notification_email, notification_bcc_email) are code with a type each
value is validated against when saved, replacing legacy name lookups and checkout-time decimal.Parse.
Admin CRUD gated by administration.manage with optimistic locking. Global only: legacy per-park rows
were never honoured by its reader.

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