| @@ 21-40 (lines=20) @@ | ||
| 18 | use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
| 19 | use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
| 20 | ||
| 21 | class ReadNotificationHandler |
|
| 22 | { |
|
| 23 | private $repository; |
|
| 24 | ||
| 25 | public function __construct(UserRepository $repository) |
|
| 26 | { |
|
| 27 | $this->repository = $repository; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke(ReadNotificationCommand $command) : void |
|
| 31 | { |
|
| 32 | $id = UserId::generate($command->userId()); |
|
| 33 | $notificationId = NotificationId::generate($command->notificationId()); |
|
| 34 | ||
| 35 | $user = $this->repository->get($id); |
|
| 36 | $notification = $user->notification($notificationId); |
|
| 37 | $user->readNotification($notification); |
|
| 38 | $this->repository->save($user); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 22-41 (lines=20) @@ | ||
| 19 | use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
| 20 | use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
| 21 | ||
| 22 | class ReceiveNotificationHandler |
|
| 23 | { |
|
| 24 | private $repository; |
|
| 25 | ||
| 26 | public function __construct(UserRepository $repository) |
|
| 27 | { |
|
| 28 | $this->repository = $repository; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function __invoke(ReceiveNotificationCommand $command) : void |
|
| 32 | { |
|
| 33 | $id = UserId::generate($command->userId()); |
|
| 34 | $notificationId = NotificationId::generate($command->notificationId()); |
|
| 35 | $body = new NotificationBody($command->body()); |
|
| 36 | ||
| 37 | $user = $this->repository->get($id); |
|
| 38 | $user->receiveNotification($notificationId, $body); |
|
| 39 | $this->repository->save($user); |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| @@ 21-40 (lines=20) @@ | ||
| 18 | use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
| 19 | use Kreta\Notifier\Domain\Model\Inbox\UserRepository; |
|
| 20 | ||
| 21 | class UnreadNotificationHandler |
|
| 22 | { |
|
| 23 | private $repository; |
|
| 24 | ||
| 25 | public function __construct(UserRepository $repository) |
|
| 26 | { |
|
| 27 | $this->repository = $repository; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke(UnreadNotificationCommand $command) : void |
|
| 31 | { |
|
| 32 | $id = UserId::generate($command->userId()); |
|
| 33 | $notificationId = NotificationId::generate($command->notificationId()); |
|
| 34 | ||
| 35 | $user = $this->repository->get($id); |
|
| 36 | $notification = $user->notification($notificationId); |
|
| 37 | $user->unreadNotification($notification); |
|
| 38 | $this->repository->save($user); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||