refactor create freight order to return dto
This commit is contained in:
parent
21216ab52f
commit
f322a0f80e
3 changed files with 19 additions and 5 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
12
src/FreightOrder/UseCases/CreateFreightOrderResponseDTO.php
Normal file
12
src/FreightOrder/UseCases/CreateFreightOrderResponseDTO.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace FreightQuote\FreightOrder\UseCases;
|
||||
|
||||
use FreightQuote\FreightOrder\FreightOrder;
|
||||
|
||||
class CreateFreightOrderResponseDTO
|
||||
{
|
||||
public function __construct(
|
||||
public FreightOrder $freightOrder,
|
||||
) {}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue