Repository navigation
Add drink sizes to orders - #2
Conversation
Each order item takes an optional size: small (50 cents off the menu price), medium (the menu price, and the default), or large (75 cents more). Every quoted line now returns its size, and an unknown size is rejected with 422. The page gets a size picker on each drink and shows the size on each quoted line. docs/api.md describes the new field and pricing rule.
fa4e848 to
d07cf3c
Compare
✅ Agent review: mergingThe PR adds an optional Tested against preview: https://pr-2.brewbar.presto2.clusters.miren.run
|
There was a problem hiding this comment.
🍪 biscuit: ✅ approved — human code review not needed
This is ready to merge. I found no correctness problems, and the code does what the description says.
Contract compatibility. docs/api.md counts a change to an existing field's meaning as a breaking change. The field that comes closest here is unit_cents: it used to always equal the menu price and now includes the size adjustment. Older clients don't send size, though, so they always get medium and a 0¢ adjustment, and every request they can make returns the same unit_cents, line_cents and totals as before. So I read this as an added optional field plus an added response field, which the contract allows. I checked the docs example by hand (900 − 90 + 71 = 881), and the new examples work out too: 571, 544, 1387 and 1028 all match the round-half-up tax formula in quoteOrder.
Validation and errors. The unknown-size error is a plain fmt.Errorf, and main.go sends every error except ErrEmptyOrder to 422, so the documented status holds. TestOrdersEndpointUnknownSize checks that end to end. Sizes are case-sensitive, as the docs say: "Large" returns 422.
Tests. TestQuoteOrder only compares totals. TestQuotedLineSize fills that gap by comparing whole QuotedLine structs, so it checks Size, UnitCents and LineCents on each line, including a line that defaults to medium. The endpoint test also confirms that size appears in the response JSON.
Front end. The data-id moved from the input to the row div, and nothing else in the repo reads it. The select can only send one of the three valid sizes. capitalize(l.size) is safe because the server always sets size.
Why I recommend approval: it's a small change to the demo app, every pricing path it adds has tests, and clients that don't send size get exactly the same responses as before.
🍪 full review note · reviewed at d07cf3c · comment /biscuit review to run biscuit again.
Adds drink sizes to Brewbar.
What changes
POST /api/orderstakes an optionalsize:small,medium, orlarge. It defaults tomedium.smallis 50 cents less than the menu price,mediumis the menu price, andlargeis 75 cents more.size. It is always set, so callers can rely on it.422, like an unknown item does.docs/api.mdcovers the new field and adds size as the first pricing rule.Compatibility
This only adds things. Requests without
sizeprice exactly as before. Two lattes withWELCOME10still total 881 cents. No existing field is renamed or removed.Examples
WELCOME10Testing
go vet ./...andgo test ./...pass. New cases cover each size, mixed sizes with a discount, the default size on quoted lines, and the 422 for an unknown size.curl.