Use Cases
Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.
One section per command in contexts[offer-availability].aggregates[*].commands.
The proposed Go package is internal/application/usecases. Step-by-step
diagrams are on Sequence Diagrams;
payloads are on Domain Events.
Error mapping rule (proposed contract): validation → 422, conflict or
state → 409, not found → 404, stale → 409. Every error body is
application/problem+json (RFC 9457) whose type is the slug shown.
Reads (GET /catalog, GET /catalog/{catalogItemId},
GET /listings?nodeId=&catalogItemId=, GET /inventory-feeds/{feedId})
are not use cases: they read the repositories directly.
Triggers at a glance
| Use case | Aggregate | Actor / trigger | Inbound adapter |
|---|---|---|---|
CreateCatalogItem | CatalogItem | Network merchandising | REST POST /catalog-items |
DiscontinueItem | CatalogItem | Network merchandising | REST POST /catalog-items/{catalogItemId}/discontinuations |
CreateListing | Listing | Network merchandising | REST POST /listings |
ApplyInventoryFeed | InventoryFeed (+ Listing) | vendor-connectivity | REST POST /inventory-feeds (in-org) |
ApplyAvailability | Listing | ApplyInventoryFeed | none of its own |
SuppressListing | Listing | policy SuppressOnNodeUnavailable on NodeSuspended / NodeRetired | Kafka consumer, retailnetwork.node-topology.events |
RestoreListing | Listing | policy SuppressOnNodeUnavailable on NodeActivated | Kafka consumer, retailnetwork.node-topology.events |
CreateCatalogItem
- Actor / trigger: network merchandising.
- Inbound adapter: REST
POST /catalog-items, headerIdempotency-Key. - Preconditions: none.
- Main flow:
- Read
title,lengthMm,widthMm,heightMm,weightG,hazmat,fragile. - Build
catalog.Itemin stateACTIVEwith a newcatalogItemId; dimensions and weight must be positive. - In one transaction: insert the item and the
CatalogItemCreatedoutbox row. - Reply
201with the item.
- Read
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
ErrInvalidItemDimensions | 422 | invalid-item-dimensions |
- Events emitted:
CatalogItemCreated. - Idempotency: a repeated
Idempotency-Keywith the same body replays the stored201; no second item, no second event.
DiscontinueItem
- Actor / trigger: network merchandising.
- Inbound adapter: REST
POST /catalog-items/{catalogItemId}/discontinuations, headerIdempotency-Key. - Preconditions: the item exists. A
DISCONTINUEDitem is not an error: see Idempotency. - Main flow:
- Load the item by
catalogItemId. - Transition
ACTIVE→DISCONTINUED. - In the same transaction (policy
SuppressOnItemDiscontinued, ADR 0002 A4): every listing of the item that is not alreadySUPPRESSED(DISCONTINUED)is suppressed with reasonDISCONTINUED, oneListingSuppressedeach. A listing suppressed forNODE_NOT_SELLABLEchanges reason and raises the event again, so a laterNodeActivatedcan never restore it. - Still in that transaction, with a
versioncheck: update the item and insert theCatalogItemDiscontinuedandListingSuppressedoutbox rows. - Reply
200with the item.
- Load the item by
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
unknown catalogItemId (ErrNotFound, a port error) | 404 | not-found |
version mismatch (ErrConcurrentUpdate, after one automatic retry) | 409 | concurrent-update |
- Events emitted:
CatalogItemDiscontinued, andListingSuppressed(reasonDISCONTINUED) per suppressed listing. - Idempotency: discontinuing a
DISCONTINUEDitem answers200with the item unchanged and emits nothing (ADR 0002 A3;ErrIllegalTransitionis not used for it); a repeatedIdempotency-Keyreplays the first answer.
CreateListing
- Actor / trigger: network merchandising.
- Inbound adapter: REST
POST /listings, headerIdempotency-Key. - Preconditions: no listing exists for (
catalogItemId,nodeId). - Main flow:
- Read
catalogItemId,nodeId. - Read the node's status from
NodeStatusView. - Build
listing.Listingwith a newlistingId:LIVEonly if the node isACTIVEinNodeStatusView; otherwise (and for a node the view does not know yet)SUPPRESSEDwith reasonNODE_NOT_SELLABLE. A listing created for aDISCONTINUEDitem startsSUPPRESSED(DISCONTINUED), which wins (ADR 0002 A4, A5). An unknowncatalogItemIdis 404not-found. - In one transaction: insert the listing (unique key on
catalog_item_id, node_id) and theListingCreatedoutbox row. - Reply
201with the listing.
- Read
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
ErrDuplicateListing | 409 | duplicate-listing |
- Events emitted:
ListingCreated. - Idempotency: a repeated
Idempotency-Keyreplays the stored201. Without the key, the unique key turns a duplicate intoErrDuplicateListing.
The model names no error for an unknown catalogItemId or nodeId; that
gap is listed on the canvas.
ApplyInventoryFeed
- Actor / trigger:
vendor-connectivity, while it processes a vendor'sSubmitInventory(POST /vendor/inventory) transaction.vendor-connectivityowns the asynchronousSubmission, the202to the vendor, rate limits and the vendor-owns-node check. - Inbound adapter: REST
POST /inventory-feeds(in-org), headerIdempotency-Key. - Preconditions: no
APPLIEDorSUPERSEDEDfeed with thisfeedId(aFAILEDone may be sent again). - Main flow:
- Read
feedId,nodeId,fullUpdate,asOfand the lines (listingId,availableQty,basis). A feed has at most 10000 lines, one per listing;asOfis feed-level (ADR 0002 A12). - Load the feed by
feedId. If it isAPPLIEDorSUPERSEDED, refuse withErrFeedAlreadyApplied. If it isFAILED, it is resubmitted (FAILED → RECEIVED) and must keep itsnodeId(elseErrValidation). - Record the feed
RECEIVED. - If the feed's
asOfis strictly older than theasOfof the lastAPPLIEDfeed of that node, the feed endsSUPERSEDED: nothing is applied and no event is raised; reply201with the feed. - Load the listings the lines name and, for a full feed, every listing
of
nodeId. - For each line: the listing must belong to
nodeId(ErrListingNotOnNode). CallApplyAvailabilitywith (availableQty,basis,asOf,feedId). A negative quantity fails the feed (ErrNegativeAvailability). A stale line (ErrStaleAvailability) is ignored, counted and the apply continues. - If
fullUpdate: policyFullFeedZeroingcallsApplyAvailabilitywithavailableQty=0on every listing of the node the feed omits. - On any failing invariant: set the feed
FAILED(its row andfailureCodeare kept), change no listing, raise no event, reply422withinstance/inventory-feeds/{feedId}. - Otherwise set the feed
APPLIEDand commit, in one transaction: the feed, every changed listing (each with itsversioncheck), oneListingAvailabilityChangedoutbox row per changed listing, and oneInventoryFeedAppliedrow. - Reply
201with the feed.
- Read
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
ErrListingNotOnNode | 422 | listing-not-on-node |
ErrNegativeAvailability | 422 | negative-availability |
ErrFeedAlreadyApplied (an APPLIED or SUPERSEDED feedId) | 409 | feed-already-applied |
ErrConcurrentUpdate (after one automatic retry) | 409 | concurrent-update |
ErrStaleAvailability | 409 | stale-availability (reserved: a stale update is ignored, so this route does not return it; the line is skipped) |
listing version mismatch | — | not returned: the use case re-runs the apply from step 5 |
- Events emitted:
ListingAvailabilityChanged(per changed listing, zeroed ones included),InventoryFeedApplied(once). AFAILEDorSUPERSEDEDfeed emits nothing. - Idempotency: two layers. A repeated
Idempotency-Keyreplays the stored answer. A different key with anAPPLIEDorSUPERSEDEDfeedIdgetsErrFeedAlreadyApplied. AFAILEDfeedIdmay be sent again (ADR 0002 A11,apis/openapi.yaml): the feed is applied afresh, it is not a replay of the stored422, and a corrected feed need not use a newfeedId.
ApplyAvailability
- Actor / trigger: the
ApplyInventoryFeeduse case, once per line and once per listing zeroed byFullFeedZeroing. - Inbound adapter: none; it runs inside the
ApplyInventoryFeedtransaction. - Preconditions: the listing exists.
- Main flow:
- Compare the new
asOfwith the listing's currentasOf. Not later: returnErrStaleAvailability(the caller ignores the line). - Check
availableQty >= 0. - Replace
Availabilitywith (availableQty,basis,asOf,feedId), keeping the vendor'sbasisas given. - Record
ListingAvailabilityChanged.
- Compare the new
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
ErrNegativeAvailability | 422 (through ApplyInventoryFeed) | negative-availability |
ErrStaleAvailability | none (line ignored) | stale-availability (reserved) |
- Events emitted:
ListingAvailabilityChanged. - Idempotency: monotonic
asOfmakes a replayed line a stale no-op. The state (LIVE/SUPPRESSED) is not touched; proposed: aSUPPRESSEDlisting still takes availability updates.
SuppressListing
- Actor / trigger: policy
SuppressOnNodeUnavailable, oncom.retailnetwork.logistics.node-topology.node.NodeSuspendedorcom.retailnetwork.logistics.node-topology.node.NodeRetired. - Inbound adapter: Kafka consumer of
retailnetwork.node-topology.events(proposed groupoffer-availability-node-status). - Preconditions: the listing is
LIVE. - Main flow:
- Skip the message if its CloudEvents
idis inprocessed_events. - Update
NodeStatusViewtoSUSPENDEDorRETIRED. - For every
LIVElisting ofnodeId: transition toSUPPRESSEDwith areasonnaming node unavailability. - In one transaction: the view row, the listings, one
ListingSuppressedoutbox row per listing, and theprocessed_eventsrow.
- Skip the message if its CloudEvents
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
| none in the model | n/a (consumer) | — |
A version mismatch rolls back and the message is redelivered.
- Events emitted:
ListingSuppressedper listing. - Idempotency: the inbox on CloudEvents
id; aSUPPRESSEDlisting is skipped and raises no event.
RestoreListing
- Actor / trigger: policy
SuppressOnNodeUnavailable, oncom.retailnetwork.logistics.node-topology.node.NodeActivated. - Inbound adapter: Kafka consumer of
retailnetwork.node-topology.events. - Preconditions: the listing is
SUPPRESSEDfor node unavailability; the node isACTIVEinNodeStatusView. - Main flow:
- Skip the message if its CloudEvents
idis inprocessed_events. - Update
NodeStatusViewtoACTIVE. - For every listing of
nodeIdsuppressed for node unavailability: check the node isACTIVE, transition toLIVE. - In one transaction: the view row, the listings, one
ListingRestoredoutbox row per listing, and theprocessed_eventsrow.
- Skip the message if its CloudEvents
- Errors:
| Error | HTTP | Problem type |
|---|---|---|
ErrNodeNotSellable | n/a (consumer); 409 node-not-sellable if a route ever exposes it | node-not-sellable |
ErrNodeNotSellable means the view says the node is not ACTIVE (for
example after an out-of-order replay); the listing stays SUPPRESSED.
- Events emitted:
ListingRestoredper listing. - Idempotency: the inbox on CloudEvents
id; aLIVElisting is skipped and raises no event.