diff --git a/README.md b/README.md index b10991e..b6356d8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # TODO - - Make GetBidsOfFreightOrder use case - Dashboard: - Show open requests use case - Show closed requests use case diff --git a/src/Bid/Bid.php b/src/Bid/Bid.php index 72c9981..8e087b7 100644 --- a/src/Bid/Bid.php +++ b/src/Bid/Bid.php @@ -79,6 +79,9 @@ class Bid return $this->fileAttachments; } + /** + * @param string[] $attachments + */ public function setFileAttachments(array $attachments): void { $this->fileAttachments = $attachments; diff --git a/src/Bid/BidRepository.php b/src/Bid/BidRepository.php index e72582e..46eb8fc 100644 --- a/src/Bid/BidRepository.php +++ b/src/Bid/BidRepository.php @@ -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; } diff --git a/src/Bid/UseCases/GetBidsOfFreightOrder.php b/src/Bid/UseCases/GetBidsOfFreightOrder.php new file mode 100644 index 0000000..a0759ff --- /dev/null +++ b/src/Bid/UseCases/GetBidsOfFreightOrder.php @@ -0,0 +1,17 @@ +bidRepo->findByFreightOrderId($dto->freightOrderId); + } +} diff --git a/src/Bid/UseCases/GetBidsOfFreightOrderRequest.php b/src/Bid/UseCases/GetBidsOfFreightOrderRequest.php new file mode 100644 index 0000000..a5e75f7 --- /dev/null +++ b/src/Bid/UseCases/GetBidsOfFreightOrderRequest.php @@ -0,0 +1,10 @@ +existingBids, + function (Bid $bid) use ($freightOrderId){ + return $bid->getFreightOrderId() === $freightOrderId; + }); + } } diff --git a/tests/Unit/Bid/UseCases/GetBidsOfFreightOrderTest.php b/tests/Unit/Bid/UseCases/GetBidsOfFreightOrderTest.php new file mode 100644 index 0000000..abb8b40 --- /dev/null +++ b/tests/Unit/Bid/UseCases/GetBidsOfFreightOrderTest.php @@ -0,0 +1,39 @@ +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]); + } +}