From b95c3aa5d6cedcd4fd30066a14313d2ef7ab40cc Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Wed, 12 Jun 2024 07:59:38 +0200 Subject: [PATCH] Daily sheet model (#17) --- .../Model/CheckoutsToOverdueSheet.php | 32 +++++++++++ src/Lending/DailySheet/Model/DailySheet.php | 28 +++++++++ src/Lending/DailySheet/Model/ExpiredHold.php | 22 +++++++ .../DailySheet/Model/HoldsToExpireSheet.php | 32 +++++++++++ .../DailySheet/Model/OverdueCheckout.php | 22 +++++++ .../Domain/PatronEvent/BookHoldCanceled.php | 54 ++++++++++++++++++ .../Domain/PatronEvent/BookHoldExpired.php | 54 ++++++++++++++++++ .../Domain/PatronEvent/BookReturned.php | 57 +++++++++++++++++++ .../PatronEvent/OverdueCheckoutRegistered.php | 54 ++++++++++++++++++ .../Model/CheckoutsToOverdueSheetTest.php | 35 ++++++++++++ .../Model/HoldsToExpireSheetTest.php | 35 ++++++++++++ 11 files changed, 425 insertions(+) create mode 100644 src/Lending/DailySheet/Model/CheckoutsToOverdueSheet.php create mode 100644 src/Lending/DailySheet/Model/DailySheet.php create mode 100644 src/Lending/DailySheet/Model/ExpiredHold.php create mode 100644 src/Lending/DailySheet/Model/HoldsToExpireSheet.php create mode 100644 src/Lending/DailySheet/Model/OverdueCheckout.php create mode 100644 src/Lending/Patron/Domain/PatronEvent/BookHoldCanceled.php create mode 100644 src/Lending/Patron/Domain/PatronEvent/BookHoldExpired.php create mode 100644 src/Lending/Patron/Domain/PatronEvent/BookReturned.php create mode 100644 src/Lending/Patron/Domain/PatronEvent/OverdueCheckoutRegistered.php create mode 100644 tests/Unit/Lending/DailySheet/Model/CheckoutsToOverdueSheetTest.php create mode 100644 tests/Unit/Lending/DailySheet/Model/HoldsToExpireSheetTest.php diff --git a/src/Lending/DailySheet/Model/CheckoutsToOverdueSheet.php b/src/Lending/DailySheet/Model/CheckoutsToOverdueSheet.php new file mode 100644 index 0000000..d4654f9 --- /dev/null +++ b/src/Lending/DailySheet/Model/CheckoutsToOverdueSheet.php @@ -0,0 +1,32 @@ + $checkouts + */ + public function __construct(public GenericList $checkouts) + { + } + + /** + * @return Stream + */ + public function toStreamOfEvents(): Stream + { + return $this->checkouts->toStream()->map(fn (OverdueCheckout $oc) => $oc->toEvent()); + } + + public function count(): int + { + return $this->checkouts->length(); + } +} diff --git a/src/Lending/DailySheet/Model/DailySheet.php b/src/Lending/DailySheet/Model/DailySheet.php new file mode 100644 index 0000000..5471e85 --- /dev/null +++ b/src/Lending/DailySheet/Model/DailySheet.php @@ -0,0 +1,28 @@ +patronId, $this->bookId, $this->libraryBranchId); + } +} diff --git a/src/Lending/DailySheet/Model/HoldsToExpireSheet.php b/src/Lending/DailySheet/Model/HoldsToExpireSheet.php new file mode 100644 index 0000000..dda6f05 --- /dev/null +++ b/src/Lending/DailySheet/Model/HoldsToExpireSheet.php @@ -0,0 +1,32 @@ + $expireHolds + */ + public function __construct(public GenericList $expireHolds) + { + } + + /** + * @return Stream + */ + public function toStreamOfEvents(): Stream + { + return $this->expireHolds->toStream()->map(fn (ExpiredHold $eh) => $eh->toEvent()); + } + + public function count(): int + { + return $this->expireHolds->length(); + } +} diff --git a/src/Lending/DailySheet/Model/OverdueCheckout.php b/src/Lending/DailySheet/Model/OverdueCheckout.php new file mode 100644 index 0000000..04f91b1 --- /dev/null +++ b/src/Lending/DailySheet/Model/OverdueCheckout.php @@ -0,0 +1,22 @@ +patronId, $this->bookId, $this->libraryBranchId); + } +} diff --git a/src/Lending/Patron/Domain/PatronEvent/BookHoldCanceled.php b/src/Lending/Patron/Domain/PatronEvent/BookHoldCanceled.php new file mode 100644 index 0000000..b75f155 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/BookHoldCanceled.php @@ -0,0 +1,54 @@ +patronId; + } + + public function eventId(): UUID + { + return $this->eventId; + } + + public function aggregateId(): UUID + { + return $this->patronId->patronId; + } + + public function when(): \DateTimeImmutable + { + return $this->when; + } +} diff --git a/src/Lending/Patron/Domain/PatronEvent/BookHoldExpired.php b/src/Lending/Patron/Domain/PatronEvent/BookHoldExpired.php new file mode 100644 index 0000000..e2e55c0 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/BookHoldExpired.php @@ -0,0 +1,54 @@ +patronId; + } + + public function aggregateId(): UUID + { + return $this->patronId->patronId; + } + + public function eventId(): UUID + { + return $this->eventId; + } + + public function when(): \DateTimeImmutable + { + return $this->when; + } +} diff --git a/src/Lending/Patron/Domain/PatronEvent/BookReturned.php b/src/Lending/Patron/Domain/PatronEvent/BookReturned.php new file mode 100644 index 0000000..dd84060 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/BookReturned.php @@ -0,0 +1,57 @@ +patronId; + } + + public function aggregateId(): UUID + { + return $this->patronId->patronId; + } + + public function eventId(): UUID + { + return $this->eventId; + } + + public function when(): \DateTimeImmutable + { + return $this->when; + } +} diff --git a/src/Lending/Patron/Domain/PatronEvent/OverdueCheckoutRegistered.php b/src/Lending/Patron/Domain/PatronEvent/OverdueCheckoutRegistered.php new file mode 100644 index 0000000..138a546 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/OverdueCheckoutRegistered.php @@ -0,0 +1,54 @@ +patronId; + } + + public function eventId(): UUID + { + return $this->eventId; + } + + public function aggregateId(): UUID + { + return $this->patronId->patronId; + } + + public function when(): \DateTimeImmutable + { + return $this->when; + } +} diff --git a/tests/Unit/Lending/DailySheet/Model/CheckoutsToOverdueSheetTest.php b/tests/Unit/Lending/DailySheet/Model/CheckoutsToOverdueSheetTest.php new file mode 100644 index 0000000..da3aeb4 --- /dev/null +++ b/tests/Unit/Lending/DailySheet/Model/CheckoutsToOverdueSheetTest.php @@ -0,0 +1,35 @@ +toStreamOfEvents()->toArray(); + + self::assertTrue($events[0]->bookId->bookId->isEqual($bookId->bookId)); + self::assertTrue($events[0]->patronId->patronId->isEqual($patronId->patronId)); + self::assertTrue($events[0]->libraryBranchId->libraryBranchId->isEqual($libraryBranchId->libraryBranchId)); + + self::assertTrue($events[1]->bookId->bookId->isEqual($anotherBookId->bookId)); + self::assertTrue($events[1]->patronId->patronId->isEqual($anotherPatronId->patronId)); + self::assertTrue($events[1]->libraryBranchId->libraryBranchId->isEqual($anotherLibraryBranchId->libraryBranchId)); + } +} diff --git a/tests/Unit/Lending/DailySheet/Model/HoldsToExpireSheetTest.php b/tests/Unit/Lending/DailySheet/Model/HoldsToExpireSheetTest.php new file mode 100644 index 0000000..e1654db --- /dev/null +++ b/tests/Unit/Lending/DailySheet/Model/HoldsToExpireSheetTest.php @@ -0,0 +1,35 @@ +toStreamOfEvents()->toArray(); + + self::assertTrue($events[0]->bookId->bookId->isEqual($bookId->bookId)); + self::assertTrue($events[0]->patronId->patronId->isEqual($patronId->patronId)); + self::assertTrue($events[0]->libraryBranchId->libraryBranchId->isEqual($libraryBranchId->libraryBranchId)); + + self::assertTrue($events[1]->bookId->bookId->isEqual($anotherBookId->bookId)); + self::assertTrue($events[1]->patronId->patronId->isEqual($anotherPatronId->patronId)); + self::assertTrue($events[1]->libraryBranchId->libraryBranchId->isEqual($anotherLibraryBranchId->libraryBranchId)); + } +}