-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\OverdueCheckoutRegistered; | ||
use Munus\Collection\GenericList; | ||
use Munus\Collection\Stream; | ||
|
||
final readonly class CheckoutsToOverdueSheet | ||
{ | ||
/** | ||
* @param GenericList<OverdueCheckout> $checkouts | ||
*/ | ||
public function __construct(public GenericList $checkouts) | ||
{ | ||
} | ||
|
||
/** | ||
* @return Stream<OverdueCheckoutRegistered> | ||
*/ | ||
public function toStreamOfEvents(): Stream | ||
{ | ||
return $this->checkouts->toStream()->map(fn (OverdueCheckout $oc) => $oc->toEvent()); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return $this->checkouts->length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookCheckedOut; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookHoldCanceled; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookHoldExpired; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookPlacedOnHold; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookReturned; | ||
|
||
interface DailySheet | ||
{ | ||
public function queryForCheckoutsToOverdue(): CheckoutsToOverdueSheet; | ||
|
||
public function queryForHoldsToExpireSheet(): HoldsToExpireSheet; | ||
|
||
public function handleBookPlacedOnHold(BookPlacedOnHold $event): void; | ||
|
||
public function handleBookHoldCanceled(BookHoldCanceled $event): void; | ||
|
||
public function handleBookHoldExpired(BookHoldExpired $event): void; | ||
|
||
public function handleBookCheckedOut(BookCheckedOut $event): void; | ||
|
||
public function handleBookReturned(BookReturned $event): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookHoldExpired; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class ExpiredHold | ||
{ | ||
public function __construct(public BookId $bookId, public PatronId $patronId, public LibraryBranchId $libraryBranchId) | ||
{ | ||
} | ||
|
||
public function toEvent(): BookHoldExpired | ||
{ | ||
return BookHoldExpired::now($this->patronId, $this->bookId, $this->libraryBranchId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\BookHoldExpired; | ||
use Munus\Collection\GenericList; | ||
use Munus\Collection\Stream; | ||
|
||
final readonly class HoldsToExpireSheet | ||
{ | ||
/** | ||
* @param GenericList<ExpiredHold> $expireHolds | ||
*/ | ||
public function __construct(public GenericList $expireHolds) | ||
{ | ||
} | ||
|
||
/** | ||
* @return Stream<BookHoldExpired> | ||
*/ | ||
public function toStreamOfEvents(): Stream | ||
{ | ||
return $this->expireHolds->toStream()->map(fn (ExpiredHold $eh) => $eh->toEvent()); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return $this->expireHolds->length(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent\OverdueCheckoutRegistered; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class OverdueCheckout | ||
{ | ||
public function __construct(public BookId $bookId, public PatronId $patronId, public LibraryBranchId $libraryBranchId) | ||
{ | ||
} | ||
|
||
public function toEvent(): OverdueCheckoutRegistered | ||
{ | ||
return OverdueCheckoutRegistered::now($this->patronId, $this->bookId, $this->libraryBranchId); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Lending/Patron/Domain/PatronEvent/BookHoldCanceled.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Common\UUID; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class BookHoldCanceled implements PatronEvent | ||
{ | ||
private function __construct( | ||
public UUID $eventId, | ||
public \DateTimeImmutable $when, | ||
public PatronId $patronId, | ||
public BookId $bookId, | ||
public LibraryBranchId $libraryBranchId, | ||
) { | ||
} | ||
|
||
public static function now(PatronId $patronId, BookId $bookId, LibraryBranchId $libraryBranchId): self | ||
{ | ||
return new self( | ||
UUID::random(), | ||
new \DateTimeImmutable(), | ||
$patronId, | ||
$bookId, | ||
$libraryBranchId, | ||
); | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Common\UUID; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class BookHoldExpired implements PatronEvent | ||
{ | ||
public function __construct( | ||
public UUID $eventId, | ||
public \DateTimeImmutable $when, | ||
public PatronId $patronId, | ||
public BookId $bookId, | ||
public LibraryBranchId $libraryBranchId, | ||
) { | ||
} | ||
|
||
public static function now(PatronId $patronId, BookId $bookId, LibraryBranchId $libraryBranchId): self | ||
{ | ||
return new self( | ||
UUID::random(), | ||
new \DateTimeImmutable(), | ||
$patronId, | ||
$bookId, | ||
$libraryBranchId, | ||
); | ||
} | ||
|
||
public function patronId(): PatronId | ||
{ | ||
return $this->patronId; | ||
} | ||
|
||
public function aggregateId(): UUID | ||
{ | ||
return $this->patronId->patronId; | ||
} | ||
|
||
public function eventId(): UUID | ||
{ | ||
return $this->eventId; | ||
} | ||
|
||
public function when(): \DateTimeImmutable | ||
{ | ||
return $this->when; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Catalogue\BookType; | ||
use Akondas\Library\Common\UUID; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class BookReturned implements PatronEvent | ||
{ | ||
public function __construct( | ||
public UUID $eventId, | ||
public \DateTimeImmutable $when, | ||
public PatronId $patronId, | ||
public BookId $bookId, | ||
public BookType $bookType, | ||
public LibraryBranchId $libraryBranchId, | ||
) { | ||
} | ||
|
||
public static function now(PatronId $patronId, BookId $bookId, BookType $bookType, LibraryBranchId $libraryBranchId): self | ||
{ | ||
return new self( | ||
UUID::random(), | ||
new \DateTimeImmutable(), | ||
$patronId, | ||
$bookId, | ||
$bookType, | ||
$libraryBranchId, | ||
); | ||
} | ||
|
||
public function patronId(): PatronId | ||
{ | ||
return $this->patronId; | ||
} | ||
|
||
public function aggregateId(): UUID | ||
{ | ||
return $this->patronId->patronId; | ||
} | ||
|
||
public function eventId(): UUID | ||
{ | ||
return $this->eventId; | ||
} | ||
|
||
public function when(): \DateTimeImmutable | ||
{ | ||
return $this->when; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Lending/Patron/Domain/PatronEvent/OverdueCheckoutRegistered.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
|
||
use Akondas\Library\Catalogue\BookId; | ||
use Akondas\Library\Common\UUID; | ||
use Akondas\Library\Lending\LibraryBranch\Domain\LibraryBranchId; | ||
use Akondas\Library\Lending\Patron\Domain\PatronEvent; | ||
use Akondas\Library\Lending\Patron\Domain\PatronId; | ||
|
||
final readonly class OverdueCheckoutRegistered implements PatronEvent | ||
{ | ||
private function __construct( | ||
public UUID $eventId, | ||
public \DateTimeImmutable $when, | ||
public PatronId $patronId, | ||
public BookId $bookId, | ||
public LibraryBranchId $libraryBranchId, | ||
) { | ||
} | ||
|
||
public static function now(PatronId $patronId, BookId $bookId, LibraryBranchId $libraryBranchId): self | ||
{ | ||
return new self( | ||
UUID::random(), | ||
new \DateTimeImmutable(), | ||
$patronId, | ||
$bookId, | ||
$libraryBranchId, | ||
); | ||
} | ||
|
||
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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Unit/Lending/DailySheet/Model/CheckoutsToOverdueSheetTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akondas\Library\Tests\Unit\Lending\DailySheet\Model; | ||
|
||
use Akondas\Library\Lending\DailySheet\Model\CheckoutsToOverdueSheet; | ||
use Akondas\Library\Lending\DailySheet\Model\OverdueCheckout; | ||
use Munus\Collection\GenericList; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(CheckoutsToOverdueSheet::class)] | ||
final class CheckoutsToOverdueSheetTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_will_transform_sheet_into_stream_of_OverdueCheckoutRegistered_events(): void | ||
{ | ||
$sheet = new CheckoutsToOverdueSheet(GenericList::of( | ||
new OverdueCheckout($bookId = anyBookId(), $patronId = anyPatronId(), $libraryBranchId = anyBranch()), | ||
new OverdueCheckout($anotherBookId = anyBookId(), $anotherPatronId = anyPatronId(), $anotherLibraryBranchId = anyBranch()) | ||
)); | ||
|
||
$events = $sheet->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)); | ||
} | ||
} |
Oops, something went wrong.