Step 01 — Published Language
- Extraction des DTOs publics dans contracts/sales/v1/ : OrderPlaced, OrderConfirmed, OrderCancelled, OrderView - NaiveSalesEventPublisher traduit les événements domaine en contrats v1 - Tests de contrat (schéma, sérialisation JSON) pour stabilité du langage publié
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\Sales\Infrastructure\Messaging;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed as OrderConfirmedContract;
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderPlaced as OrderPlacedContract;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrder;
|
||||
use MiniShop\Invoicing\Application\Command\IssueInvoiceForExternalOrderHandler;
|
||||
use MiniShop\LegacyFulfillment\Application\Command\RequestShipmentFromSalesOrder;
|
||||
@@ -16,7 +18,7 @@ use MiniShop\Sales\Domain\Model\OrderLine;
|
||||
|
||||
/**
|
||||
* Couplage naif : Sales appelle directement les handlers des autres BC.
|
||||
* Ce couplage sera supprime dans les episodes suivants (Published Language, Conformist, ACL).
|
||||
* Depuis step/01, la traduction passe par le Published Language (contracts/sales/v1).
|
||||
*/
|
||||
final readonly class NaiveSalesEventPublisher implements SalesEventPublisher
|
||||
{
|
||||
@@ -27,42 +29,78 @@ final readonly class NaiveSalesEventPublisher implements SalesEventPublisher
|
||||
|
||||
public function publishOrderPlaced(OrderPlaced $event): void
|
||||
{
|
||||
// Pas d'action downstream sur OrderPlaced dans le scenario naif.
|
||||
}
|
||||
|
||||
public function publishOrderConfirmed(OrderConfirmed $event): void
|
||||
{
|
||||
// Appel direct vers Invoicing — couplage naif
|
||||
($this->issueInvoiceHandler)(new IssueInvoiceForExternalOrder(
|
||||
externalOrderId: $event->orderId->toString(),
|
||||
customerName: 'Customer ' . $event->customerId->toString(),
|
||||
customerAddress: 'N/A',
|
||||
// Traduction domaine → Published Language (pour reference)
|
||||
new OrderPlacedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
placedAt: $event->placedAt->format(\DateTimeInterface::ATOM),
|
||||
lines: array_map(
|
||||
static fn (OrderLine $line): array => [
|
||||
'description' => $line->productName,
|
||||
'productName' => $line->productName,
|
||||
'quantity' => $line->quantity,
|
||||
'unitPriceInCents' => $line->unitPrice->amount,
|
||||
'currency' => $line->unitPrice->currency,
|
||||
],
|
||||
$event->lines,
|
||||
[], // OrderPlaced doesn't carry lines in this version
|
||||
),
|
||||
);
|
||||
// Pas d'action downstream sur OrderPlaced.
|
||||
}
|
||||
|
||||
public function publishOrderConfirmed(OrderConfirmed $event): void
|
||||
{
|
||||
$lines = array_map(
|
||||
static fn (OrderLine $line): array => [
|
||||
'productName' => $line->productName,
|
||||
'quantity' => $line->quantity,
|
||||
'unitPriceInCents' => $line->unitPrice->amount,
|
||||
'currency' => $line->unitPrice->currency,
|
||||
],
|
||||
$event->lines,
|
||||
);
|
||||
|
||||
// Step 01 : traduction domaine → Published Language
|
||||
$message = new OrderConfirmedContract(
|
||||
orderId: $event->orderId->toString(),
|
||||
customerId: $event->customerId->toString(),
|
||||
totalInCents: $event->total->amount,
|
||||
currency: $event->total->currency,
|
||||
lines: $lines,
|
||||
);
|
||||
|
||||
// Appel direct vers Invoicing — toujours naif mais via Published Language
|
||||
($this->issueInvoiceHandler)(new IssueInvoiceForExternalOrder(
|
||||
externalOrderId: $message->orderId,
|
||||
customerName: 'Customer ' . $message->customerId,
|
||||
customerAddress: 'N/A',
|
||||
lines: array_map(
|
||||
static fn (array $line): array => [
|
||||
'description' => $line['productName'],
|
||||
'quantity' => $line['quantity'],
|
||||
'unitPriceInCents' => $line['unitPriceInCents'],
|
||||
'currency' => $line['currency'],
|
||||
],
|
||||
$message->lines,
|
||||
),
|
||||
));
|
||||
|
||||
// Appel direct vers LegacyFulfillment — couplage naif
|
||||
// Appel direct vers LegacyFulfillment — toujours naif mais via Published Language
|
||||
($this->requestShipmentHandler)(new RequestShipmentFromSalesOrder(
|
||||
externalOrderId: $event->orderId->toString(),
|
||||
recipientName: 'Customer ' . $event->customerId->toString(),
|
||||
externalOrderId: $message->orderId,
|
||||
recipientName: 'Customer ' . $message->customerId,
|
||||
street: '1 Rue du Commerce',
|
||||
city: 'Paris',
|
||||
postalCode: '75001',
|
||||
country: 'FR',
|
||||
totalWeightInGrams: 1000,
|
||||
description: sprintf('Order %s', $event->orderId->toString()),
|
||||
description: sprintf('Order %s', $message->orderId),
|
||||
));
|
||||
}
|
||||
|
||||
public function publishOrderCancelled(OrderCancelled $event): void
|
||||
{
|
||||
// Pas d'action downstream sur OrderCancelled dans le scenario naif.
|
||||
// Pas d'action downstream sur OrderCancelled.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user