Skip to main content

Use Cases

Built on develop, not deployed

Derived from model/model.yaml. The product-content service is built on develop (IQVO/product-content at 2f09dc0, checked 2026-10-27) and not deployed (no warehouse-infra entry). Every Err... name, REST route and CloudEvents type of this context named on this page exists in the service; where the built service differs from the model's design, the page says so (As built) or the context's Service and operations section lists it.

One section per command of contexts[product-content].aggregates[*].commands. They are application services in internal/application/usecases (as built). The step-by-step diagrams are on Sequence Diagrams; the payloads are on Domain Events; the REST contract is apis/product-content/openapi.yaml.

Reads are not use cases here: GET /product-contents (paged, for product-discovery's bootstrap), GET /product-contents/{catalogItemId} and GET /categories read the stores directly. The projection of CatalogItemCreated and CatalogItemDiscontinued into CatalogItemView is not a use case either: it is the projector behind the ErrUnknownCatalogItem check. (CatalogItemDiscontinued additionally triggers the RetireOnDiscontinue policy, which is a use case below.)

Triggers at a glance​

Use caseTriggerInbound adapterEmits
CreateProductContentContent managerREST POST /product-contentsnone
ReviseContentContent managerREST POST /product-contents/{catalogItemId}/revisions (ReviseDraft for a DRAFT, ReviseContent for PUBLISHED)none (shoppers see a new revision after a publish)
DiscardDraftContent managerREST DELETE /product-contents/{catalogItemId}/draftnone
PublishContentContent managerREST POST /product-contents/{catalogItemId}/publicationsProductContentPublished
RetireContentContent managerREST POST /product-contents/{catalogItemId}/retirementsProductContentRetired
RetireContent (policy)RetireOnDiscontinueKafka consumer, CatalogItemDiscontinuedProductContentRetired for PUBLISHED content only; a DRAFT retires silently
CreateCategoryContent managerREST POST /categoriesnone
MoveCategoryContent managerREST PUT /categories/{categoryId}/parentnone
RenameCategoryContent managerREST PUT /categories/{categoryId}/namenone
PublishCategoryTreenot named in the modelnone (no inbound row, no route)CategoryTreePublished

How save and publish commit​

Every use case that changes an aggregate loads it with its version, calls the aggregate, then saves it inside one Postgres transaction. The save is conditional on the version it loaded (UPDATE ... WHERE version = ?). If an event is raised, the outbox row (outbox_events) is written in the same transaction. A consumer-driven use case also inserts the CloudEvents id into processed_events in that transaction. A relay publishes outbox rows to Kafka after the commit. This context makes no synchronous calls (sync_calls is empty), so no use case waits on another context.

Error responses use application/problem+json (RFC 9457) with type /problems/<slug> (a relative URI reference). Shared slugs (conventions.integration_rules): not-found 404, illegal-transition 409, concurrent-update 409, validation-failed 422, plus one kebab-case slug per Err below. Every write route takes an Idempotency-Key header; a repeated key returns the stored response of the first call.

CreateProductContent​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST POST /product-contents, header Idempotency-Key required; body catalogItemId, description, bullets[], attributes[], media[], primaryCategoryId.
  • Preconditions: the item exists in CatalogItemView and is not DISCONTINUED; the content does not exist yet.
  • Main flow:
    1. Look up the Idempotency-Key. On a hit with the same request body, return the stored response.
    2. Check the catalogItemId against CatalogItemView (ErrUnknownCatalogItem) and that the item is not DISCONTINUED (ErrItemDiscontinued).
    3. Check primaryCategoryId, when given, against the current tree (ErrUnknownCategory).
    4. ProductContent.CreateProductContent(...): state DRAFT, revision 1. A DRAFT may be incomplete (every body field is optional); it is edited later through ReviseContent (DRAFT → DRAFT) and must be complete only to publish.
    5. In one transaction, insert the content and store the response under the Idempotency-Key.
    6. Answer 201 with the content.
  • Errors:
ErrorHTTPProblem type slugNote
ErrUnknownCatalogItem422unknown-catalog-itemThe item is not in CatalogItemView: never created, or the projection lags.
ErrItemDiscontinued422item-discontinuedThe item is DISCONTINUED in CatalogItemView: content is neither created nor published for a discontinued item.
ErrUnknownCategory422unknown-categoryThe primaryCategoryId is not in the current tree.
validation422validation-failedSchema rules, including the collection bounds (bullets at most 10, attributes at most 50, media at most 12), which have no Err names.
duplicate content for the item409concurrent-updateThe API maps a second create to 409 (as built too); the model names no Err for it.
  • Events emitted: none.
  • Idempotency: Idempotency-Key; the primary key on catalogItemId is the last guard.
  • Discontinued items: content for a discontinued item is not created: the aggregate's invariant (see the Aggregate Design Canvas) refuses it with ErrItemDiscontinued, the same check as on publish.

ReviseContent​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST POST /product-contents/{catalogItemId}/revisions, header Idempotency-Key required; same body as create.
  • Preconditions: the content exists and is DRAFT or PUBLISHED (RETIRED never changes again); the named category exists.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load ProductContent with its version (404 if absent).
    3. One route, two commands picked by the state: ReviseDraft(...) for a DRAFT (DRAFT → DRAFT) and ReviseContent(...) for PUBLISHED (PUBLISHED → PUBLISHED). Each replaces description, bullets, attributes, media and primary category with the body and takes the next revision; the state does not change. They check ErrContentRetired and ErrUnknownCategory; revised PUBLISHED content must stay complete (ErrIncompleteContent).
    4. Save (version checked) and store the key response in one transaction.
    5. Answer 200 with the revised content.
  • Errors:
ErrorHTTPProblem type slugNote
content not found404not-foundNo content for the item.
ErrContentRetired409content-retiredRETIRED content never changes again.
ErrUnknownCategory422unknown-categoryThe new primary category is not in the current tree.
ErrIncompleteContent422incomplete-contentPUBLISHED content would be left without a description, exactly one PRIMARY medium or a category.
validation422validation-failedSchema rules and collection bounds.
version conflict409concurrent-updateRetried once inside the use case before it is returned.
  • Events emitted: none. Shoppers see the new revision only after a publish: PublishContent is DRAFT → PUBLISHED and PUBLISHED → PUBLISHED (the re-publication path), carrying the new revision in ProductContentPublished, which product-discovery orders by.
  • Idempotency: Idempotency-Key.

PublishContent​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST POST /product-contents/{catalogItemId}/publications, header Idempotency-Key required.
  • Preconditions: the content exists and is DRAFT or PUBLISHED; the item is known and not DISCONTINUED; the publish gate passes.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load ProductContent with its version (404 if absent).
    3. PublishContent(...): checks ErrContentRetired, ErrItemDiscontinued, ErrUnknownCategory and the publish gate ErrIncompleteContent (a description, exactly one PRIMARY medium and a category). State PUBLISHED, publishedRevision set to the current revision.
    4. In one transaction, save (version checked), write ProductContentPublished to the outbox, store the key response.
    5. Answer 200 with the published content.
  • Errors:
ErrorHTTPProblem type slugNote
content not found404not-foundNo content for the item.
ErrIncompleteContent422incomplete-contentMissing description, not exactly one PRIMARY medium, or no category.
ErrItemDiscontinued422item-discontinuedThe item is DISCONTINUED: a discontinued item can never publish.
ErrUnknownCategory422unknown-categoryThe primary category left the current tree.
ErrContentRetired409content-retiredRETIRED never publishes again.
version conflict409concurrent-updateRetried once inside the use case.
  • Events emitted: ProductContentPublished with the full content and the new revision.
  • Idempotency: Idempotency-Key; publishing PUBLISHED content whose publishedRevision already equals its revision has nothing new to publish: the call succeeds, saves nothing and raises nothing (ADR 0002 A1). A revision made after the last publish is published again by the next call.

RetireContent (content manager)​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST POST /product-contents/{catalogItemId}/retirements, header Idempotency-Key required.
  • Preconditions: the content exists and is PUBLISHED.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load ProductContent with its version (404 if absent).
    3. RetireContent(...): state RETIRED (terminal), reason MANUAL.
    4. In one transaction, save (version checked), write ProductContentRetired to the outbox, store the key response.
    5. Answer 200 with the retired content.
  • Errors:
ErrorHTTPProblem type slugNote
content not found404not-foundNo content for the item.
illegal transition409illegal-transitionThe content is DRAFT (a manager discards a DRAFT with DiscardDraft) or already RETIRED.
version conflict409concurrent-updateRetried once inside the use case.
  • Events emitted: ProductContentRetired (the retired reason, MANUAL, is on the REST read, not on the event).
  • Idempotency: Idempotency-Key; retiring a RETIRED content is the 409 above, not a no-op.

DiscardDraft (content manager)​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST DELETE /product-contents/{catalogItemId}/draft.
  • Preconditions: the content exists and is DRAFT.
  • Main flow: load ProductContent (404 if absent), DiscardDraft(...): DRAFT → RETIRED, reason DISCARDED; save (version checked).
  • Errors: 404 not-found; 409 illegal-transition for content that is not a DRAFT; 409 concurrent-update.
  • Events emitted: none: nothing was ever published.

RetireContent (policy RetireOnDiscontinue)​

  • Actor / trigger: offer-availability discontinued the item.
  • Inbound adapter: Kafka consumer on retailnetwork.offer-availability.events, type com.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemDiscontinued.
  • Preconditions: the item has content that is not yet RETIRED: PUBLISHED content retires with an event, a DRAFT retires silently.
  • Main flow:
    1. Inbox check on the CloudEvents id; a duplicate is acknowledged.
    2. Mark the item discontinued in CatalogItemView.
    3. Load the item's ProductContent. If none, or already RETIRED, stop.
    4. RetireOnDiscontinue(...): PUBLISHED or DRAFT becomes RETIRED, reason DISCONTINUED. A discontinued item can never publish again (ErrItemDiscontinued).
    5. Save, outbox ProductContentRetired (PUBLISHED content only), inbox row, one transaction.
  • Errors: none expected. An anomaly is logged and acknowledged.
  • Events emitted: ProductContentRetired for PUBLISHED content only; a DRAFT retires silently, because nothing was ever published.
  • Idempotency: inbox on the CloudEvents id; the state check makes a replayed effect a no-op.

CreateCategory​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST POST /categories, header Idempotency-Key required; body parentId (optional), name.
  • Preconditions: the parent exists in the working tree; the structural invariants hold after the insert.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load the CategoryTree with its version.
    3. CreateCategory(parentId, name): checks ErrMaxDepth (the tree is at most four levels deep), ErrCategoryCycle and ErrDuplicateSiblingName; computes the new node's path.
    4. Save (version checked) and store the key response in one transaction.
    5. Answer 201 with the category.
  • Errors:
ErrorHTTPProblem type slugNote
ErrMaxDepth422max-depthThe new node would sit below level four.
ErrCategoryCycle422category-cycleThe design-time API listed it on create; a brand-new node cannot close a cycle. As built the API lists it only on :move.
ErrDuplicateSiblingName422duplicate-sibling-nameA sibling already has this name.
validation422validation-failedAn empty name or a missing parent id shape.
  • Events emitted: none; the tree reaches product-discovery only at publication.
  • Idempotency: Idempotency-Key.

MoveCategory​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST PUT /categories/{categoryId}/parent, header Idempotency-Key required; body parentId (nullable: move to the root).
  • Preconditions: the category and the new parent exist; the structural invariants hold after the move.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load the CategoryTree (404 if the category is unknown).
    3. MoveCategory(categoryId, parentId): checks ErrCategoryCycle (a node never moves under its own subtree), ErrMaxDepth and ErrDuplicateSiblingName; recomputes the path of the moved subtree.
    4. Save (version checked) and store the key response.
    5. Answer 200 with the moved category.
  • Errors:
ErrorHTTPProblem type slugNote
category not found404not-foundUnknown categoryId or parentId.
ErrCategoryCycle422category-cycleThe new parent is inside the moved subtree.
ErrMaxDepth422max-depthThe moved subtree would reach below level four.
ErrDuplicateSiblingName422duplicate-sibling-nameThe new siblings already have this name.
ErrCategoryInUse409category-in-useThe design-time API mapped it to :move, although the invariant guards removal and the model has no remove command (model gap). As built no route answers category-in-use.
version conflict409concurrent-updateRetried once inside the use case.
  • Events emitted: none.
  • Idempotency: Idempotency-Key.

RenameCategory​

  • Actor / trigger: the storefront content manager.
  • Inbound adapter: REST PUT /categories/{categoryId}/name, header Idempotency-Key required; body name.
  • Preconditions: the category exists; no sibling has the new name.
  • Main flow:
    1. Look up the Idempotency-Key; replay on a hit.
    2. Load the CategoryTree (404 if the category is unknown).
    3. RenameCategory(categoryId, name): checks ErrDuplicateSiblingName; the path segments depending on the name are recomputed.
    4. Save (version checked) and store the key response.
    5. Answer 200 with the renamed category.
  • Errors:
ErrorHTTPProblem type slugNote
category not found404not-foundUnknown categoryId.
ErrDuplicateSiblingName422duplicate-sibling-nameA sibling already has this name.
validation422validation-failedAn empty name.
  • Events emitted: none.
  • Idempotency: Idempotency-Key.

PublishCategoryTree​

  • Actor / trigger: not named in the model: no inbound row carries the command and no route in rest publishes the tree (model gap). These pages read it as a deliberate content-manager action whose route the model has not named yet.
  • Inbound adapter: unknown; drawn as a content-manager action.
  • Preconditions: the working tree differs from the last publication (otherwise the publication is a no-op with a bumped version; the model allows PUBLISHED → PUBLISHED).
  • Main flow:
    1. Load the CategoryTree with its optimistic-concurrency guard.
    2. PublishCategoryTree(...): state PUBLISHED, tree version bumped.
    3. In one transaction, save and write CategoryTreePublished (the whole tree under the new version) to the outbox.
    4. Answer with the published tree.
  • Errors: none named in the model. The structural invariants hold for the working tree at all times, so publication needs no re-check.
  • Events emitted: CategoryTreePublished.
  • Idempotency: the trigger is unknown, so no Idempotency-Key handling is specified; the event's version is the consumer's guard.