Skip to content

feat(orders): POST /orders grava pedido + OrderPlaced no outbox (fase 2) - #2

Merged
thomasmoreira merged 1 commit into
mainfrom
feat/orders-place-order
Jun 8, 2026
Merged

thomasmoreira merged 1 commit into
mainfrom
feat/orders-place-order

Conversation

@thomasmoreira

@thomasmoreira thomasmoreira commented Jun 8, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Users can now place orders with SKU, quantity, and amount information
    • Order status tracking with Pending, Confirmed, and Cancelled states
  • Tests

    • Integration tests added to validate order placement and persistence workflows
  • Chores

    • PostgreSQL database and RabbitMQ messaging configuration added
    • Required service dependencies configured

Primeiro uso real do outbox da fase 1: criar um pedido persiste o agregado Order
e o evento OrderPlaced na MESMA transação (sem dual-write, ADR-001).

- Domain: agregado Order (Pending/Confirmed/Cancelled) com factory Place() + guards
- Infrastructure: OrdersDbContext deriva de MessagingDbContext (order+outbox+inbox no
  schema orders, ADR-005); OrderConfiguration snake_case; design-time factory
- Migrations EF reais (InitialCreate: schema orders + 3 tabelas + ix_outbox_pending);
  dotnet-ef como tool local (.config/dotnet-tools.json)
- Feature PlaceOrder: handler cria Order + outbox.Add(OrderPlaced) + 1 SaveChanges
- Host: DI completa, migrate no startup, endpoint POST /orders
- Teste de integração (Testcontainers Postgres) prova persistência atômica

Infra: EF Core alinhado a 10.0.4 (versão contra a qual o Npgsql 10.0.2 foi compilado)
para unificar o grafo e zerar o aviso MSB3277. Migrations marcadas como código gerado
no .editorconfig. Build limpo (0/0); unit 4/4; integration PlaceOrder + Outbox verdes.
@thomasmoreira
thomasmoreira merged commit 4c1930a into main Jun 8, 2026
1 of 2 checks passed
@thomasmoreira
thomasmoreira deleted the feat/orders-place-order branch June 8, 2026 16:17
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 77b3b535-61ad-4349-bb8b-eb2121761a88

📥 Commits

Reviewing files that changed from the base of the PR and between 344e72e and 588c613.

📒 Files selected for processing (17)
  • .config/dotnet-tools.json
  • .editorconfig
  • Directory.Packages.props
  • src/BuildingBlocks/Persistence/BuildingBlocks.Persistence.csproj
  • src/Services/Orders/Domain/Order.cs
  • src/Services/Orders/Features/PlaceOrder.cs
  • src/Services/Orders/Infrastructure/OrderConfiguration.cs
  • src/Services/Orders/Infrastructure/OrdersDbContext.cs
  • src/Services/Orders/Infrastructure/OrdersDbContextFactory.cs
  • src/Services/Orders/Migrations/20260608160223_InitialCreate.Designer.cs
  • src/Services/Orders/Migrations/20260608160223_InitialCreate.cs
  • src/Services/Orders/Migrations/OrdersDbContextModelSnapshot.cs
  • src/Services/Orders/Program.cs
  • src/Services/Orders/Services.Orders.csproj
  • src/Services/Orders/appsettings.json
  • tests/Integration/PlaceOrderTests.cs
  • tests/Integration/Tests.Integration.csproj

📝 Walkthrough

Walkthrough

This PR implements a complete Orders service microservice with domain-driven design, EF Core persistence on PostgreSQL, transactional order placement with outbox messaging, and integration tests. Changes include domain models, database schema and migrations, a feature handler, full service wiring, and validation of the atomic persist-and-enqueue workflow.

Changes

Orders Service Implementation

Layer / File(s) Summary
Project Dependencies & Tooling
.config/dotnet-tools.json, .editorconfig, Directory.Packages.props, src/BuildingBlocks/Persistence/BuildingBlocks.Persistence.csproj, src/Services/Orders/Services.Orders.csproj, tests/Integration/Tests.Integration.csproj
Added dotnet-ef tool manifest pinned to 10.0.8, exempted migration files from style rules, downgraded EF Core packages from 10.0.8 to 10.0.4 (for Npgsql alignment), and added EF Core and PostgreSQL dependencies across project files.
Order Domain Model
src/Services/Orders/Domain/Order.cs
Defined OrderStatus enum with Pending, Confirmed, Cancelled states and sealed Order aggregate with validated Place() factory, immutable properties, and Confirm()/Cancel() state transitions.
Database Schema & EF Core Mapping
src/Services/Orders/Infrastructure/OrderConfiguration.cs, src/Services/Orders/Infrastructure/OrdersDbContext.cs, src/Services/Orders/Infrastructure/OrdersDbContextFactory.cs, src/Services/Orders/Migrations/*
Created EF Core entity configuration mapping Order to orders table, implemented OrdersDbContext with orders schema and outbox/inbox inheritance, added design-time factory, and generated migrations defining inbox, outbox, and orders tables with filtered outbox index.
Order Placement Feature Handler
src/Services/Orders/Features/PlaceOrder.cs
Implemented PlaceOrderHandler that validates PlaceOrderRequest, creates a pending Order via the domain factory, persists it with OrdersDbContext, enqueues OrderPlaced integration event to IOutbox, and returns the new order ID in a single atomic SaveChangesAsync call.
Service Startup & Configuration
src/Services/Orders/Program.cs, src/Services/Orders/appsettings.json
Configured OrdersDbContext with PostgreSQL connection, mapped MessagingDbContext for shared outbox unit-of-work, enabled outbox/inbox with RabbitMQ publisher and dispatcher, registered TimeProvider.System and PlaceOrderHandler, applied migrations at startup, and wired POST /orders endpoint to invoke the handler and return 201 Created.
Integration Test Suite
tests/Integration/PlaceOrderTests.cs
Added integration test using Testcontainers PostgreSQL 17 container, validates that PlaceOrderHandler atomically persists a pending order and writes an unprocessed OrderPlaced outbox entry in a single transaction, including assertions on order state and outbox payload.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • thomasmoreira/distributed-consistency-lab#1: The Orders service implementation directly builds on the messaging and outbox infrastructure (IOutbox, MessagingDbContext, outbox/inbox models, and RabbitMQ publisher/dispatcher) introduced in that PR.

Poem

🐰 Hops with joy – Orders now bloom!
A domain dance in the database room,
Pending state begins its tale,
Outbox enqueues without fail.
Migrations set the schema stage – tests prevail! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/orders-place-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

thomasmoreira added a commit that referenced this pull request Jun 10, 2026
… 2) (#2)

Primeiro uso real do outbox da fase 1: criar um pedido persiste o agregado Order
e o evento OrderPlaced na MESMA transação (sem dual-write, ADR-001).

- Domain: agregado Order (Pending/Confirmed/Cancelled) com factory Place() + guards
- Infrastructure: OrdersDbContext deriva de MessagingDbContext (order+outbox+inbox no
  schema orders, ADR-005); OrderConfiguration snake_case; design-time factory
- Migrations EF reais (InitialCreate: schema orders + 3 tabelas + ix_outbox_pending);
  dotnet-ef como tool local (.config/dotnet-tools.json)
- Feature PlaceOrder: handler cria Order + outbox.Add(OrderPlaced) + 1 SaveChanges
- Host: DI completa, migrate no startup, endpoint POST /orders
- Teste de integração (Testcontainers Postgres) prova persistência atômica

Infra: EF Core alinhado a 10.0.4 (versão contra a qual o Npgsql 10.0.2 foi compilado)
para unificar o grafo e zerar o aviso MSB3277. Migrations marcadas como código gerado
no .editorconfig. Build limpo (0/0); unit 4/4; integration PlaceOrder + Outbox verdes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant