Use Cases
Derived from network/model/model.yaml. This context's service is built (IQVO/customer-returns, decided by ADR 0012); the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses. Where the model left a choice open, the service's own ADRs 0001 to 0005 record what it does.
One application service per command in
contexts[customer-returns].aggregates[*].commands, under
internal/application/usecases. Runtime views of the key ones are on
Sequence Diagrams.
Reads (GetReturnAuthorization, ListReturnAuthorizations) go to the
repository; a read of an expired, untouched authorization cancels it first
(LazyExpiry). The same two reads back the MCP tools and the A2A skill; see
Reads over REST, MCP and A2A.
Conventions for every use case
- Errors are RFC 9457
application/problem+json: validation and refused preconditions422, conflict or state409, not found404, stale version409. - Idempotency-Key on every
POST(1 to 128 printable ASCII characters). A repeat with the same key replays the first response; the same key on a different request is409 idempotency-key-reused. - One transaction per use case: the aggregate change, its outbox rows, and (for consumers) the inbox row commit together.
- Read models are local.
OrderGroupViewandReturnsNetworkVieware read inside the use case; the only call that leaves the context is the reverse-label call ofIssueLabel, made before the transaction.
| Model error | HTTP | Problem type |
|---|---|---|
ErrGroupNotShipped | 422 | group-not-shipped |
ErrUnknownLine | 422 | validation-failed |
ErrNoReturnDestination | 422 | no-return-destination |
ErrLabelUnavailable | 422 | label-unavailable |
ErrAuthorizationExpired | 422 | authorization-expired |
ErrValidation, ErrNotFound, ErrIllegalTransition, ErrConcurrentUpdate | 422, 404, 409, 409 | the shared slugs from conventions.errors |
AuthorizeReturn
- Actor / trigger: the shopper through the storefront. REST
POST /return-authorizations. - Preconditions: the group is
SHIPPEDorDELIVEREDinOrderGroupView. - Flow:
- Read the group from
OrderGroupView; an unknown or not yet shipped group is refused. - Resolve each requested
lineNoagainst the placed group; the quantity is the quantity placed on that line, the price is the caller's, theownerRefcomes from the sourcing release fact. - Read the two possible destinations from
ReturnsNetworkView: theACTIVEreturns centre of the region of the group's destination prefix, and the node that fulfilled the group. - Decide the disposition (
DispositionDecidedAtAuthorization):KEEP, elseNEAREST_RETURNS_CENTER, elseORIGIN_NODE, else refuse. - Create the authorization:
AUTHORIZED, orCLOSED_KEEPat once forKEEP.expiresAtisauthorizedAtplus 30 days. Save it and writeReturnAuthorizedto the outbox.
- Read the group from
- Errors:
ErrGroupNotShipped,ErrUnknownLine,ErrNoReturnDestination,ErrValidation(line count, method, aPICKUPwithout a valid window). - Events:
ReturnAuthorized, for every disposition. - Idempotency: the
Idempotency-Keyreplays the first answer of a request that succeeded. A lagging view is retried with the same key and the same body.
IssueLabel
- REST:
POST /return-authorizations/{authorizationId}/labels, bodypackageNo1 to 5. - Preconditions: the authorization is
AUTHORIZED, not expired, and its disposition is notKEEP. - Flow:
- Load the authorization; cancel it if expired (
LazyExpiry). - Ask
shipping-and-tracking's reverse-label route for the label of the package, outside the transaction (ReverseLabelCall). - In one transaction re-read the aggregate, link the tracking number and
write
ReturnLabelIssuedto the outbox.
- Load the authorization; cancel it if expired (
- Errors:
ErrLabelUnavailable(the route is not configured, or answered anything but a tracking number),ErrAuthorizationExpired,ErrIllegalTransition,ErrValidation(a sixth package),ErrNotFound. - Events:
ReturnLabelIssued, once per package. - As built: the route is not in
shipping-and-tracking'sdevelopcontract, so this use case answerslabel-unavailable.
CancelReturn
- REST:
POST /return-authorizations/{authorizationId}/cancellations. - Flow:
AUTHORIZED → CANCELLED. The reason isSHOPPER_REQUESTED, orEXPIREDwhen the authorization is pastexpiresAtat that instant. - Errors:
ErrIllegalTransition(any state other thanAUTHORIZED),ErrNotFound. - Events:
ReturnCancelled.
ApplyOutcome
- Trigger: the consumer of the vendor's graded outcome (no HTTP). Not
triggered today: the producer's event is not on
develop(FirstFittingOutcomeCompletes). - Flow: split the outcome lines into the ones the authorization covers
and the ones it never did. When the authorization is open (
AUTHORIZEDorIN_TRANSIT) and at least one line is covered, apply the covered lines: the state becomesRECEIVEDandReturnCompletedis written to the outbox with the authorized lines only. Record the whole outcome onReturnOutcomeFacts, the other lines flagged unexpected. - Errors: none returned. An outcome for an unknown or closed authorization is recorded and acknowledged.
- Events:
ReturnCompleted. - Idempotency: the CloudEvents
idin the inbox.
MarkInTransit / MarkPickupFailed
- Trigger: none as built. Both are transitions of the aggregate
(
AUTHORIZED → IN_TRANSIT,AUTHORIZED → PICKUP_FAILED) with no route and no consumer. - Events: none.
Reads over REST, MCP and A2A
- Use cases:
GetReturnAuthorizationandListReturnAuthorizations(internal/application/usecases/queries.go). REST, MCP and A2A call the same two; there is no agent-only read and no agent write (service ADRs 0006, 0009 and 0011, read ondevelop5f2d5e6on 2026-12-02). - REST:
GET /return-authorizations/{authorizationId}andGET /return-authorizations?orderId=(keyset pages of 20 by default, at most 100). - MCP (
cmd/mcp, port 8090, Streamable HTTP at/api/mcp/customer-returnsthrough the Agent Router): toolsget_return_authorization(argumentauthorizationId) andlist_return_authorizations(orderId, optionalcursorandlimit), both L1 withreadOnlyHint. The one resource template,warehouse://customer-returns/return-authorizations/{authorizationId}, loads the same authorization without a tool call, and the promptreview_return_authorizationnames both tools without calling them. - A2A (
cmd/a2a, port 8093, JSON-RPC 2.0 at/api/a2a/customer-returnsthrough the Agent Router): one skill,get_return_authorization(argumentauthorizationId, tagauthority:L1), answering the authorization as a data part plus a one-line summary; an unknown id is a404 not-foundproblem. - Errors: the REST slugs above, as tool errors and as A2A problems
(
not-found,validation-failed;internal-errornever leaks its cause). - Not exposed:
AuthorizeReturn,IssueLabel,CancelReturnandApplyOutcomehave no tool and no skill; they stay REST-only and consumer-only.
Read-model consumers
CustomerOrderPlacedandShopperNoticeDecidedfeedOrderGroupView.NodeRegistered,NodeActivated,NodeSuspended,NodeRetiredandServiceAreaAssignedfeed the node and prefix halves ofReturnsNetworkView.FulfillmentReleasedToNodeandFulfillmentLockedfeed its origin half.- Each is idempotent on the CloudEvents
id; a staleassignmentVersionis a no-op.