diff --git a/src/Lending/Book/Domain/AvailableBook.php b/src/Lending/Book/Domain/AvailableBook.php index 613db92..8174a58 100644 --- a/src/Lending/Book/Domain/AvailableBook.php +++ b/src/Lending/Book/Domain/AvailableBook.php @@ -12,8 +12,7 @@ final readonly class AvailableBook implements Book { public function __construct( - public BookId $bookId, - public BookType $bookType, + public BookInformation $bookInformation, public LibraryBranchId $libraryBranch, public Version $version) { @@ -21,12 +20,12 @@ public function __construct( public function bookId(): BookId { - return $this->bookId; + return $this->bookInformation->bookId; } public function bookType(): BookType { - return $this->bookType; + return $this->bookInformation->bookType; } public function version(): Version @@ -36,6 +35,6 @@ public function version(): Version public function isRestricted(): bool { - return $this->bookType === BookType::RESTRICTED; + return $this->bookInformation->bookType === BookType::RESTRICTED; } } diff --git a/src/Lending/Book/Domain/BookInformation.php b/src/Lending/Book/Domain/BookInformation.php new file mode 100644 index 0000000..fb1991d --- /dev/null +++ b/src/Lending/Book/Domain/BookInformation.php @@ -0,0 +1,15 @@ +bookId; + return $this->bookInformation->bookId; } public function bookType(): BookType { - return $this->bookType; + return $this->bookInformation->bookType; } public function version(): Version diff --git a/src/Lending/Patron/Domain/CheckoutDuration.php b/src/Lending/Patron/Domain/CheckoutDuration.php new file mode 100644 index 0000000..1561340 --- /dev/null +++ b/src/Lending/Patron/Domain/CheckoutDuration.php @@ -0,0 +1,27 @@ +noOfDays->isGreaterThan(self::MAX_CHECKOUT_DURATION)) { + throw new \InvalidArgumentException(sprintf('Cannot checkout for more than %s days!', self::MAX_CHECKOUT_DURATION)); + } + } + + public static function maxDuration(): self + { + return new self(new \DateTimeImmutable(), NumberOfDays::of(self::MAX_CHECKOUT_DURATION)); + } + + public function to(): \DateTimeImmutable + { + return $this->from->modify(sprintf('+%d days', $this->noOfDays->days)); + } +} diff --git a/src/Lending/Patron/Domain/PatronEvent/BookCheckedOut.php b/src/Lending/Patron/Domain/PatronEvent/BookCheckedOut.php new file mode 100644 index 0000000..4322916 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/BookCheckedOut.php @@ -0,0 +1,60 @@ +to() + ); + } + + public function patronId(): PatronId + { + return $this->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/BookPlacedOnHold.php b/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php index 10500df..e30d003 100644 --- a/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php +++ b/src/Lending/Patron/Domain/PatronEvent/BookPlacedOnHold.php @@ -12,7 +12,7 @@ use Akondas\Library\Lending\Patron\Domain\PatronEvent; use Akondas\Library\Lending\Patron\Domain\PatronId; -final class BookPlacedOnHold implements PatronEvent +final readonly class BookPlacedOnHold implements PatronEvent { private function __construct( public UUID $eventId, diff --git a/src/Lending/Patron/Domain/PatronEvent/MaximumNumberOnHoldsReached.php b/src/Lending/Patron/Domain/PatronEvent/MaximumNumberOnHoldsReached.php new file mode 100644 index 0000000..b309e9b --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/MaximumNumberOnHoldsReached.php @@ -0,0 +1,50 @@ +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/PatronCreated.php b/src/Lending/Patron/Domain/PatronEvent/PatronCreated.php new file mode 100644 index 0000000..c99d815 --- /dev/null +++ b/src/Lending/Patron/Domain/PatronEvent/PatronCreated.php @@ -0,0 +1,51 @@ +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/Fixture/BookFixture.php b/tests/Fixture/BookFixture.php index 2b13b0a..092c310 100644 --- a/tests/Fixture/BookFixture.php +++ b/tests/Fixture/BookFixture.php @@ -8,16 +8,17 @@ use Akondas\Library\Common\Aggregate\Version; use Akondas\Library\Common\UUID; use Akondas\Library\Lending\Book\Domain\AvailableBook; +use Akondas\Library\Lending\Book\Domain\BookInformation; use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; function restrictedBook(): AvailableBook { - return new AvailableBook(anyBookId(), BookType::RESTRICTED, anyBranch(), Version::zero()); + return new AvailableBook(new BookInformation(anyBookId(), BookType::RESTRICTED), anyBranch(), Version::zero()); } function circulatingBook(): AvailableBook { - return new AvailableBook(anyBookId(), BookType::CIRCULATING, anyBranch(), Version::zero()); + return new AvailableBook(new BookInformation(anyBookId(), BookType::CIRCULATING), anyBranch(), Version::zero()); } function anyBookId(): BookId diff --git a/tests/Unit/Lending/Patron/Domain/CheckoutDurationTest.php b/tests/Unit/Lending/Patron/Domain/CheckoutDurationTest.php new file mode 100644 index 0000000..5d84904 --- /dev/null +++ b/tests/Unit/Lending/Patron/Domain/CheckoutDurationTest.php @@ -0,0 +1,31 @@ +expectException(\InvalidArgumentException::class); + + new CheckoutDuration(new \DateTimeImmutable(), NumberOfDays::of(61)); + } + + #[Test] + public function it_will_calculate_to_timestamp(): void + { + $checkoutDuration = new CheckoutDuration(new \DateTimeImmutable('2024-06-10 10:10:10'), NumberOfDays::of(60)); + + self::assertEquals(new \DateTimeImmutable('2024-08-09 10:10:10'), $checkoutDuration->to()); + } +}