3 Bounded Contexts (Sales, Invoicing, LegacyFulfillment) avec : - Domaines complets (agrégats, VOs, événements, invariants) - Couche application (commands, queries, ports) - Infrastructure in-memory (repos, gateway fake) - Controllers HTTP Symfony - Couplage naïf synchrone entre BC via NaiveSalesEventPublisher - 20 tests unitaires et d'intégration passants
45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MiniShop\LegacyFulfillment\Interfaces\Http;
|
|
|
|
use MiniShop\LegacyFulfillment\Application\Query\GetShipmentByExternalOrderRef;
|
|
use MiniShop\LegacyFulfillment\Application\Query\GetShipmentByExternalOrderRefHandler;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
#[Route('/fulfillment/orders/{externalOrderId}/shipment', name: 'fulfillment_get_shipment', methods: ['GET'])]
|
|
final readonly class GetShipmentController
|
|
{
|
|
public function __construct(
|
|
private GetShipmentByExternalOrderRefHandler $handler,
|
|
) {}
|
|
|
|
public function __invoke(string $externalOrderId): JsonResponse
|
|
{
|
|
$shipment = ($this->handler)(new GetShipmentByExternalOrderRef($externalOrderId));
|
|
|
|
if ($shipment === null) {
|
|
return new JsonResponse(['error' => 'Shipment not found.'], Response::HTTP_NOT_FOUND);
|
|
}
|
|
|
|
return new JsonResponse([
|
|
'orderRef' => $shipment->orderRef->toString(),
|
|
'status' => $shipment->status()->value,
|
|
'address' => [
|
|
'recipientName' => $shipment->address->recipientName,
|
|
'street' => $shipment->address->street,
|
|
'city' => $shipment->address->city,
|
|
'postalCode' => $shipment->address->postalCode,
|
|
'country' => $shipment->address->country,
|
|
],
|
|
'parcel' => [
|
|
'weightInGrams' => $shipment->parcel->weightInGrams,
|
|
'description' => $shipment->parcel->description,
|
|
],
|
|
]);
|
|
}
|
|
}
|