Skip to content

Feature/25 price lookup by date - #87

Merged
lauriechammah merged 4 commits into
developfrom
feature/25-price-lookup-by-date
Nov 18, 2026
Merged

lauriechammah merged 4 commits into
developfrom
feature/25-price-lookup-by-date

Conversation

@jspngl

@jspngl jspngl commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #25

Overview

The donation value calculation (#30) needs the price of a food item on the date it was donated. This PR adds that lookup, plus an endpoint to read an item's price history.

Price lookup

  • PriceService.GetPriceInEffectAsync(catalogItemId, date) returns the price in effect on a date: the price with the latest effective date on or before that date. A price applies from its effective date itself.
  • The rule lives in one place, PriceHistory.FindPriceInEffect (in Core), so the service and any future code use the same logic.

Clear behavior when there is no price

  • A date before the item's first price, or an item with no price at all, throws PriceNotFoundException. The error gives the item, the date asked for, and the first effective date, for example: "Catalog item … has no price on 2026-10-20: its first price starts on 2026-11-01."
  • An unknown item throws CatalogItemNotFoundException.
  • The lookup never falls back to the first or closest price, so a donation is never valued with a wrong price.

API endpoints

  • GET /api/catalog-items/{id}/prices returns the price history, oldest first (an empty list if the item has no prices yet), or 404 if the item doesn't exist.
  • GET /api/catalog-items/{id}/prices/in-effect?date=yyyy-MM-dd returns the price on that date. It returns 404 with a clear message (and firstEffectiveDate) if there is no price on that date or the item doesn't exist, and 400 if the date is missing or invalid.

Errors use the standard application/problem+json format. I also updated docs/database/prices.md to explain the lookup and the endpoints, and added example requests to MoissonMontreal.Api.http.

Open point: both endpoints only require a signed-in user (access_as_user scope), like /api/me. There is no "view prices" permission yet, so someone in the Microsoft tenant who was never added to the app could still read prices. Should a permission protect these endpoints?

Testing

Unit tests, no Docker needed (PriceHistoryTests):

  • Exact effective date of the first, a later, and the latest price
  • A date between two prices, and the last day before the next price starts
  • A date after the latest price, and far in the future
  • The day before the first price, and earlier dates → no price
  • An item with no prices → no price
  • Prices given in any order
  • The error messages

Integration tests against PostgreSQL (Testcontainers):

  • PriceServiceTests: correct price for each date, a date before the first price, an item with no prices, an unknown item, another item's prices ignored, history order
  • CatalogItemPricesEndpointTests: both endpoints, the contents of the 404 errors, missing or invalid dates (400), missing token (401)

Full suite: 343 tests passing (dotnet test).

Screenshots / Screencasts

N/A. This is a back-end change with no frontend components.

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and well-documented
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned (one of your tech leads)

Tip: You can make the issue and then check them after the fact or replace [ ] with [x] to check it!

Notes

@lauriechammah lauriechammah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See requested changes

Comment thread docs/database/prices.md Resolved
@lauriechammah
lauriechammah removed the request for review from anis022 November 18, 2026 16:14
@jspngl
jspngl requested a review from lauriechammah November 18, 2026 18:05

@lauriechammah lauriechammah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lauriechammah
lauriechammah merged commit 98104c5 into develop Nov 18, 2026
5 checks passed
@lauriechammah
lauriechammah deleted the feature/25-price-lookup-by-date branch November 18, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants