Compare commits
3 commits
14e77d2885
...
ed25fcefde
| Author | SHA1 | Date | |
|---|---|---|---|
| ed25fcefde | |||
| 678f67cbbc | |||
| fa156fd155 |
7 changed files with 83 additions and 1 deletions
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
|
||||
# TODO
|
||||
- Make GetBidsOfFreightOrder use case
|
||||
- Dashboard:
|
||||
- Show open requests use case
|
||||
- Show closed requests use case
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ class Bid
|
|||
return $this->fileAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $attachments
|
||||
*/
|
||||
public function setFileAttachments(array $attachments): void
|
||||
{
|
||||
$this->fileAttachments = $attachments;
|
||||
|
|
|
|||
|
|
@ -6,4 +6,9 @@ interface BidRepository
|
|||
{
|
||||
public function save(Bid $bid): Bid;
|
||||
public function find(string $id): ?Bid;
|
||||
|
||||
/**
|
||||
* @return Bid[]
|
||||
*/
|
||||
public function findByFreightOrderId(int $freightOrderId): array;
|
||||
}
|
||||
|
|
|
|||
17
src/Bid/UseCases/GetBidsOfFreightOrder.php
Normal file
17
src/Bid/UseCases/GetBidsOfFreightOrder.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace FreightQuote\Bid\UseCases;
|
||||
|
||||
use FreightQuote\Bid\BidRepository;
|
||||
|
||||
class GetBidsOfFreightOrder
|
||||
{
|
||||
public function __construct(
|
||||
private BidRepository $bidRepo,
|
||||
) {}
|
||||
|
||||
public function execute(GetBidsOfFreightOrderRequest $dto): array
|
||||
{
|
||||
return $this->bidRepo->findByFreightOrderId($dto->freightOrderId);
|
||||
}
|
||||
}
|
||||
10
src/Bid/UseCases/GetBidsOfFreightOrderRequest.php
Normal file
10
src/Bid/UseCases/GetBidsOfFreightOrderRequest.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace FreightQuote\Bid\UseCases;
|
||||
|
||||
class GetBidsOfFreightOrderRequest
|
||||
{
|
||||
public function __construct(
|
||||
public int $freightOrderId,
|
||||
) {}
|
||||
}
|
||||
|
|
@ -61,4 +61,13 @@ class FakeBidRepository implements BidRepository
|
|||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function findByFreightOrderId(int $freightOrderId): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->existingBids,
|
||||
function (Bid $bid) use ($freightOrderId){
|
||||
return $bid->getFreightOrderId() === $freightOrderId;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
tests/Unit/Bid/UseCases/GetBidsOfFreightOrderTest.php
Normal file
39
tests/Unit/Bid/UseCases/GetBidsOfFreightOrderTest.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Bid\UseCases;
|
||||
|
||||
use FreightQuote\Bid\Bid;
|
||||
use FreightQuote\Bid\UseCases\GetBidsOfFreightOrderRequest;
|
||||
use FreightQuote\Bid\UseCases\GetBidsOfFreightOrder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Fakes\Bid\FakeBidRepository;
|
||||
|
||||
class GetBidsOfFreightOrderTest extends TestCase
|
||||
{
|
||||
private FakeBidRepository $bidRepo;
|
||||
|
||||
private GetBidsOfFreightOrder $useCase;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->bidRepo = new FakeBidRepository();
|
||||
$this->useCase = new GetBidsOfFreightOrder($this->bidRepo);
|
||||
}
|
||||
|
||||
public function test_get_one_bid(): void
|
||||
{
|
||||
$this->bidRepo->save(new Bid(0, 0, 0, false, false, 0, '', []));
|
||||
$dto = new GetBidsOfFreightOrderRequest(freightOrderId: 0);
|
||||
$bids = $this->useCase->execute($dto);
|
||||
$this->assertInstanceOf(Bid::class, $bids[0]);
|
||||
}
|
||||
|
||||
public function test_get_two_bids(): void
|
||||
{
|
||||
$this->bidRepo->save(new Bid(0, 0, 0, false, false, 0, '', []));
|
||||
$this->bidRepo->save(new Bid(1, 0, 0, false, false, 0, '', []));
|
||||
$dto = new GetBidsOfFreightOrderRequest(freightOrderId: 0);
|
||||
$bids = $this->useCase->execute($dto);
|
||||
$this->assertInstanceOf(Bid::class, $bids[1]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue