refactor create freight order to return dto

This commit is contained in:
Yisroel Baum 2025-11-17 21:45:59 +02:00
parent 21216ab52f
commit f322a0f80e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 19 additions and 5 deletions

View file

@ -19,14 +19,14 @@ class CreateFreightOrder
public function execute(
CreateFreightOrderRequestDTO $dto,
): FreightOrder {
): CreateFreightOrderResponseDTO {
$savedFreightOrder = $this->saveFreightOrder($dto);
$this->handleCarrierActions(
$dto->carrierIds,
$savedFreightOrder,
);
return $savedFreightOrder;
return new CreateFreightOrderResponseDTO($savedFreightOrder);
}
/**

View file

@ -0,0 +1,12 @@
<?php
namespace FreightQuote\FreightOrder\UseCases;
use FreightQuote\FreightOrder\FreightOrder;
class CreateFreightOrderResponseDTO
{
public function __construct(
public FreightOrder $freightOrder,
) {}
}

View file

@ -42,7 +42,8 @@ class CreateFreightOrderTest extends TestCase
fileAttachments: ['path/to/file', 'another/path/file'],
carrierIds: [],
);
$createdFreightOrder = $this->useCase->execute($dto);
$response = $this->useCase->execute($dto);
$createdFreightOrder = $response->freightOrder;
$foundFreightOrder = $this->freightOrderRepo->find(
$createdFreightOrder->getId()
);
@ -81,7 +82,8 @@ class CreateFreightOrderTest extends TestCase
fileAttachments: ['path/to/file', 'another/path/file'],
carrierIds: [$carrierId],
);
$createdFreightOrder = $this->useCase->execute($dto);
$response = $this->useCase->execute($dto);
$createdFreightOrder = $response->freightOrder;
$foundCarrier = $this->carrierRepo->find($carrierId);
$this->assertEquals(
[$createdFreightOrder->getId()],
@ -113,7 +115,7 @@ class CreateFreightOrderTest extends TestCase
fileAttachments: ['path/to/file', 'another/path/file'],
carrierIds: [$carrierId],
);
$createdFreightOrder = $this->useCase->execute($dto);
$this->useCase->execute($dto);
$this->assertEquals(1, $this->emailer->getSentEmailCount());
}
}