From e92cb7fb019d1a76a98101ad45eddffb235afaa3 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Dec 2015 18:01:33 +0000 Subject: [PATCH] Added AlreadySubscribedException Closes #1201 --- app/Exceptions/AlreadySubscribedException.php | 24 +++++++++++++++++++ .../SubscribeSubscriberCommandHandler.php | 7 ++++++ 2 files changed, 31 insertions(+) create mode 100644 app/Exceptions/AlreadySubscribedException.php diff --git a/app/Exceptions/AlreadySubscribedException.php b/app/Exceptions/AlreadySubscribedException.php new file mode 100644 index 00000000..6929051f --- /dev/null +++ b/app/Exceptions/AlreadySubscribedException.php @@ -0,0 +1,24 @@ + + */ +class AlreadySubscribedException extends Exception implements ExceptionInterface +{ + // +} diff --git a/app/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php b/app/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php index e96fb8fe..9ab617ed 100644 --- a/app/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php +++ b/app/Handlers/Commands/Subscriber/SubscribeSubscriberCommandHandler.php @@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Handlers\Commands\Subscriber; use CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand; use CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand; use CachetHQ\Cachet\Events\Subscriber\SubscriberHasSubscribedEvent; +use CachetHQ\Cachet\Exceptions\AlreadySubscribedException; use CachetHQ\Cachet\Models\Subscriber; use Illuminate\Foundation\Bus\DispatchesJobs; @@ -26,10 +27,16 @@ class SubscribeSubscriberCommandHandler * * @param \CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand $command * + * @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException + * * @return \CachetHQ\Cachet\Models\Subscriber */ public function handle(SubscribeSubscriberCommand $command) { + if (Subscriber::where('email', $command->email)->first()) { + throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed."); + } + $subscriber = Subscriber::create(['email' => $command->email]); if ($command->verified) {