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(
|
public function execute(
|
||||||
CreateFreightOrderRequestDTO $dto,
|
CreateFreightOrderRequestDTO $dto,
|
||||||
): FreightOrder {
|
): CreateFreightOrderResponseDTO {
|
||||||
$savedFreightOrder = $this->saveFreightOrder($dto);
|
$savedFreightOrder = $this->saveFreightOrder($dto);
|
||||||
$this->handleCarrierActions(
|
$this->handleCarrierActions(
|
||||||
$dto->carrierIds,
|
$dto->carrierIds,
|
||||||
$savedFreightOrder,
|
$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'],
|
fileAttachments: ['path/to/file', 'another/path/file'],
|
||||||
carrierIds: [],
|
carrierIds: [],
|
||||||
);
|
);
|
||||||
$createdFreightOrder = $this->useCase->execute($dto);
|
$response = $this->useCase->execute($dto);
|
||||||
|
$createdFreightOrder = $response->freightOrder;
|
||||||
$foundFreightOrder = $this->freightOrderRepo->find(
|
$foundFreightOrder = $this->freightOrderRepo->find(
|
||||||
$createdFreightOrder->getId()
|
$createdFreightOrder->getId()
|
||||||
);
|
);
|
||||||
|
|
@ -81,7 +82,8 @@ class CreateFreightOrderTest extends TestCase
|
||||||
fileAttachments: ['path/to/file', 'another/path/file'],
|
fileAttachments: ['path/to/file', 'another/path/file'],
|
||||||
carrierIds: [$carrierId],
|
carrierIds: [$carrierId],
|
||||||
);
|
);
|
||||||
$createdFreightOrder = $this->useCase->execute($dto);
|
$response = $this->useCase->execute($dto);
|
||||||
|
$createdFreightOrder = $response->freightOrder;
|
||||||
$foundCarrier = $this->carrierRepo->find($carrierId);
|
$foundCarrier = $this->carrierRepo->find($carrierId);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
[$createdFreightOrder->getId()],
|
[$createdFreightOrder->getId()],
|
||||||
|
|
@ -113,7 +115,7 @@ class CreateFreightOrderTest extends TestCase
|
||||||
fileAttachments: ['path/to/file', 'another/path/file'],
|
fileAttachments: ['path/to/file', 'another/path/file'],
|
||||||
carrierIds: [$carrierId],
|
carrierIds: [$carrierId],
|
||||||
);
|
);
|
||||||
$createdFreightOrder = $this->useCase->execute($dto);
|
$this->useCase->execute($dto);
|
||||||
$this->assertEquals(1, $this->emailer->getSentEmailCount());
|
$this->assertEquals(1, $this->emailer->getSentEmailCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue