feat(api): shop price lookup - visit-day prices in the payment currency (#17, part 2) #83

Merged
amiryahaya merged 1 commit from feat/pricing into main 2026-10-23 07:06:01 +02:00
Owner

Closes #17 (part 2 of 2; part 1 was #82).

What

The shop price lookup that replaces the legacy ProductSearchService, following ADR 0004.

GET /v1/parks/{id}/products?date=YYYY-MM-DD&currency=KES[&category_id=][&product_id=] (public, cacheable 60 s):

  • the price valid on the visit day (calendar dates, inclusive ends), in the currency the customer pays in;
  • the native price wins; otherwise one price is converted with the rate for exactly that currency pair valid at the start of the visit day, exact arithmetic (internal/money), rounded once to cents;
  • no price or no rate gives available: false, reason: "not available in KES", never a wrong, duplicated or missing line;
  • converted lines say what they came from (converted_from: native amount, rate, rate id) so the order can store the rate later.

Legacy defects this fixes (each has a test)

Legacy Now
converted with every rate to the target, any source currency, inactive ones too (a EUR rate could convert a USD price) exact (from, to) pair, active rates only
native and converted rows both returned, callers took FirstOrDefault one line per product, native first
nothing returned when no price or rate, callers dereferenced null explicit unavailable line
money through double and culture-dependent ToString("F") money.Amount, rounded once, half away from zero
price valid "at arrival or departure" missed windows in between and returned two prices one price per visit day
rates matched on other dates than prices, caller's request mutated one clock, request untouched

Standards review (docs/development-standards.md)

  • TDD: resolver, service, handler, readers and end-to-end tests written first; two boundary mutations (rate end inclusive, price end off by a day) each fail a test.
  • SOLID / coupling: Resolve is pure; Service depends on three narrow reader interfaces (offers, rates, currencies) defined in the consumer; the PostgreSQL implementation is read-only and swappable; the handler depends on a one-method Quoter. pricing does not import catalog or lookups.
  • Coverage: 94.6% total; pricing 100%, pricing store 90.6%. make lint 0 issues. Security scans run on main after merge (the CI job is authoritative, not a local run).

Known limits

  • Several convertible foreign prices: lowest currency code wins (only KES and USD are priced today).
  • A rate that starts mid-day applies from the next day (rates are entered as whole days).
  • Multi-day totals, tax, and storing the rate on the order line belong to cart and checkout (#26).

🤖 Generated with Claude Code

Closes #17 (part 2 of 2; part 1 was #82). ## What The shop price lookup that replaces the legacy `ProductSearchService`, following ADR 0004. `GET /v1/parks/{id}/products?date=YYYY-MM-DD&currency=KES[&category_id=][&product_id=]` (public, cacheable 60 s): - the price valid on the **visit day** (calendar dates, inclusive ends), in the currency the customer pays in; - the **native price wins**; otherwise one price is converted with the rate for **exactly that currency pair** valid at the start of the visit day, exact arithmetic (`internal/money`), rounded once to cents; - no price or no rate gives `available: false, reason: "not available in KES"`, never a wrong, duplicated or missing line; - converted lines say what they came from (`converted_from`: native amount, rate, rate id) so the order can store the rate later. ## Legacy defects this fixes (each has a test) | Legacy | Now | |---|---| | converted with every rate to the target, any source currency, inactive ones too (a EUR rate could convert a USD price) | exact (from, to) pair, active rates only | | native and converted rows both returned, callers took `FirstOrDefault` | one line per product, native first | | nothing returned when no price or rate, callers dereferenced null | explicit unavailable line | | money through `double` and culture-dependent `ToString("F")` | `money.Amount`, rounded once, half away from zero | | price valid "at arrival or departure" missed windows in between and returned two prices | one price per visit day | | rates matched on other dates than prices, caller's request mutated | one clock, request untouched | ## Standards review (docs/development-standards.md) - **TDD**: resolver, service, handler, readers and end-to-end tests written first; two boundary mutations (rate end inclusive, price end off by a day) each fail a test. - **SOLID / coupling**: `Resolve` is pure; `Service` depends on three narrow reader interfaces (offers, rates, currencies) defined in the consumer; the PostgreSQL implementation is read-only and swappable; the handler depends on a one-method `Quoter`. `pricing` does not import `catalog` or `lookups`. - **Coverage**: 94.6% total; pricing 100%, pricing store 90.6%. `make lint` 0 issues. Security scans run on `main` after merge (the CI job is authoritative, not a local run). ## Known limits - Several convertible foreign prices: lowest currency code wins (only KES and USD are priced today). - A rate that starts mid-day applies from the next day (rates are entered as whole days). - Multi-day totals, tax, and storing the rate on the order line belong to cart and checkout (#26). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(api): shop price lookup - visit-day prices in the payment currency, converted at the admin rate (closes #17)
All checks were successful
ci / changes (pull_request) Successful in 11s
ci / api (pull_request) Successful in 5m50s
ci / ci-gate (pull_request) Successful in 3s
501762a746
internal/pricing: Resolve (pure: native price, else one conversion at the exact currency pair's rate,
else 'not available in <currency>'), Service over three narrow readers, a public cacheable endpoint
GET /v1/parks/{id}/products, and read-only PostgreSQL readers. Money uses internal/money, so
conversion is exact and rounded once. Fixes the legacy defects recorded in ADR 0004: wrong-rate
conversion, duplicate rows, nulls for missing prices, arrival-or-departure window test.

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