Step 03 — ACL (LegacyFulfillment)
- LegacyShipmentAcl : mapping explicite sales.v1.OrderConfirmed → LegacyCreateShipmentCommand - LegacyCreateShipmentCommand : modèle legacy (champs abrégés, codification date/status) - WhenOrderConfirmed (LegacyFulfillment) : consumer Messenger via ACL - Tests unitaires mapping ACL + test d'intégration
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||
|
||||
/**
|
||||
* Modele legacy : champs abreges et codifications imposees par le systeme d'expedition historique.
|
||||
* Ce format ne doit jamais fuiter en dehors de l'ACL.
|
||||
*/
|
||||
final readonly class LegacyCreateShipmentCommand
|
||||
{
|
||||
public function __construct(
|
||||
public string $ord_ref, // reference commande (format legacy: prefixe LEG-)
|
||||
public string $rcpt_nm, // nom destinataire (tronque a 35 chars)
|
||||
public string $rcpt_addr, // adresse sur une ligne
|
||||
public string $rcpt_zip, // code postal
|
||||
public string $rcpt_cty, // code pays ISO 2
|
||||
public int $wgt_g, // poids en grammes
|
||||
public string $desc, // description colis
|
||||
public string $req_dt, // date demande format legacy YYYYMMDD
|
||||
public string $sts, // statut: NEW, DIS (dispatched)
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MiniShop\LegacyFulfillment\Infrastructure\AntiCorruption;
|
||||
|
||||
use MiniShop\Contracts\Sales\V1\Event\OrderConfirmed;
|
||||
|
||||
/**
|
||||
* Anti-Corruption Layer : traduit le Published Language sales.v1 vers le modele
|
||||
* legacy d'expedition. Isole toutes les bizarreries du format legacy.
|
||||
*
|
||||
* @see §13.2 du boilerplate spec
|
||||
*/
|
||||
final class LegacyShipmentAcl
|
||||
{
|
||||
private const int MAX_RECIPIENT_LENGTH = 35;
|
||||
|
||||
public function fromSalesOrderConfirmed(OrderConfirmed $message): LegacyCreateShipmentCommand
|
||||
{
|
||||
$recipientName = mb_substr('Customer ' . $message->customerId, 0, self::MAX_RECIPIENT_LENGTH);
|
||||
|
||||
$totalWeight = max(100, count($message->lines) * 500);
|
||||
|
||||
$description = sprintf(
|
||||
'CMD-%s/%d articles',
|
||||
mb_substr($message->orderId, 0, 8),
|
||||
count($message->lines),
|
||||
);
|
||||
|
||||
return new LegacyCreateShipmentCommand(
|
||||
ord_ref: 'LEG-' . $message->orderId,
|
||||
rcpt_nm: $recipientName,
|
||||
rcpt_addr: 'N/A',
|
||||
rcpt_zip: '00000',
|
||||
rcpt_cty: 'FR',
|
||||
wgt_g: $totalWeight,
|
||||
desc: $description,
|
||||
req_dt: date('Ymd'),
|
||||
sts: 'NEW',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user