proposal-system/api/src
Adam Moussa 85bca54e08
feat(api): optimistic concurrency on the proposal aggregate + atomic audit staging
Phase 6a of the SHOC-alignment plan (ADR 0004, wire contract extracted
verbatim from shoc-backend PRs #10/#13-#18).

Concurrency (SHOC double-guard, Postgres port):
- long Version on Proposal + LineItem, IsConcurrencyToken, additive
  migration AddProposalLineItemVersion (DEFAULT 1; Up/Down inspected —
  no drift, exactly two AddColumn/DropColumn).
- Tokens are opaque base64 strings on the wire (RowVersionCodec:
  8-byte big-endian long), rowVersion on responses, proposalVersion on
  guarded requests. Missing -> 422 ProposalVersionRequired; malformed
  -> 422 InvalidRowVersion (BusinessRuleException carrier).
- Guarded: update, approve, return-to-review, send, revise, and bulk
  line-item update (proposal-level token — bulk replaces the item set
  wholesale, so per-item tokens are meaningless; deviation from the
  plan documented). Creates/deletes unguarded per SHOC precedent but
  bump the aggregate version.
- Conflict -> 409 { message, currentState } (SHOC envelope, reloaded
  row embedded); bare DbUpdateConcurrencyException -> 409
  { status, message, code } fallback. Both non-ProblemDetails,
  emitted by GlobalExceptionHandler.

Audit atomicity (stage-then-single-SaveChanges):
- IAuditService.Stage adds to the shared context without saving;
  every proposal/line-item mutation stages before its own single
  SaveChangesAsync, so mutation + audit commit or fail together.
  LogAsync (self-saving) remains for standalone events (downloads,
  role changes, delivery).
2026-07-13 20:48:28 -04:00
..
ProposalSystem.Api feat(api): optimistic concurrency on the proposal aggregate + atomic audit staging 2026-07-13 20:48:28 -04:00
ProposalSystem.Application feat(api): optimistic concurrency on the proposal aggregate + atomic audit staging 2026-07-13 20:48:28 -04:00
ProposalSystem.Domain feat(api): optimistic concurrency on the proposal aggregate + atomic audit staging 2026-07-13 20:48:28 -04:00
ProposalSystem.Infrastructure feat(api): optimistic concurrency on the proposal aggregate + atomic audit staging 2026-07-13 20:48:28 -04:00