33. Package read model
Status
Accepted.
Context
POST /tasks/{id}/package-seals creates a Package and returns it on 201
(with a Location: /packages/{id} header), and POST /packages/{id}/slam-runs
runs the SLAM weigh-check on it. SLAM returns 204 in both outcomes:
- label applied: status
LABELED,LabelApplied+PackageManifestedraised (ADR-0025); - weight discrepancy: status
DIVERTED,WeightDiscrepancyDetected+PackageDivertedraised.
The API had no read endpoint for a Package at all — the Location header
pointed at a resource nobody could GET. So an associate (or the
fleet's warehouse-day simulator, which drives the fleet purely through
published REST contracts) at the SLAM scale or the outbound dock could not
tell whether a carton goes to the truck by its sortLane or to the
problem-solve area. The only signal was the domain events, which are not on
the wire for LabelApplied/PackageDiverted.
Decision
Add a read model for the Package aggregate, additive only:
GET /packages/{id}returns200with the existingPackageResponseschema (the same DTO seal-package's201returns:id,orderRef,statusOPEN|SEALED|LABELED|DIVERTED,scannedContents,fragileHandling,giftWrapRequested,sortLane). An unknown id is a404RFC 7807package-not-foundproblem, reusingusecases.ErrPackageNotFoundand its existing mapping.GET /packages?orderRef=returns200with an array ofPackageResponse(empty when none), mirroringGET /tasks?orderRef=(ADR-0013): the same query-parameter validation and the same400 invalid-requestfor a missing or emptyorderRef. Ordered by package id.- One read use case per operation,
GetPackageandGetPackagesByOrderRef, followingGetTasksByOrderRef. ports.PackageRepogainsFindByOrderRef, implemented in the memory and postgres adapters. Migration0013_package_order_ref_indexaddsidx_packages_order_ref(non-unique: an order can produce several cartons), the same access path migration 0006 indexed for tasks.
POST /packages/{id}/slam-runs stays 204. Both outcomes are successful
completions of the weigh-check command. Returning a body (or a different
status per outcome) would change a published contract every existing caller
relies on, and would make a command double as a query. The REST-idiomatic
way to observe the result of a command that returns no body is to read the
resource it acted on, which this ADR makes possible.
Consequences
- A caller learns the SLAM outcome with one extra
GET /packages/{id}after the204. That costs one round trip and keeps commands and queries separate. - The
Locationheader seal-package already returned now resolves. - No AsyncAPI change. No new domain events, no domain-layer change.
GET /packages?orderRef=takes the sameorderRefvalueTask.OrderRefcarries: wes-work-planning's WorkUnit id, not order-management's order id. See theorderRefcontract in ADR-0013.