From f7aa85ac31abe60100bccbbf7992433ad4eb3554 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Thu, 17 Feb 2022 12:25:43 +0100 Subject: [PATCH] #41 - wip --- .../Providers/EventServiceProvider.php | 12 ++- .../Events/VacationRequestCancelled.php | 20 +++++ ...VacationRequestWaitedForAdministrative.php | 20 +++++ .../VacationRequestWaitedForTechnical.php | 20 +++++ ...endApprovedVacationRequestNotification.php | 34 +++++++++ ...ndCancelledVacationRequestNotification.php | 34 +++++++++ ...endRejectedVacationRequestNotification.php | 1 - ...inistrativeVacationRequestNotification.php | 32 ++++++++ ...orTechnicalVacationRequestNotification.php | 32 ++++++++ .../VacationRequestApprovedNotification.php | 75 +++++++++++++++++++ .../VacationRequestCancelledNotification.php | 75 +++++++++++++++++++ .../VacationRequestCreatedNotification.php | 27 +++++-- .../VacationRequestRejectedNotification.php | 24 +++++- ...estWaitedForAdministrativeNotification.php | 75 +++++++++++++++++++ ...nRequestWaitedForTechnicalNotification.php | 75 +++++++++++++++++++ app/Domain/VacationRequestStateManager.php | 10 +++ resources/lang/pl.json | 16 +++- 17 files changed, 568 insertions(+), 14 deletions(-) create mode 100644 app/Domain/Events/VacationRequestCancelled.php create mode 100644 app/Domain/Events/VacationRequestWaitedForAdministrative.php create mode 100644 app/Domain/Events/VacationRequestWaitedForTechnical.php create mode 100644 app/Domain/Listeners/SendApprovedVacationRequestNotification.php create mode 100644 app/Domain/Listeners/SendCancelledVacationRequestNotification.php create mode 100644 app/Domain/Listeners/SendWaitedForAdministrativeVacationRequestNotification.php create mode 100644 app/Domain/Listeners/SendWaitedForTechnicalVacationRequestNotification.php create mode 100644 app/Domain/Notifications/VacationRequestApprovedNotification.php create mode 100644 app/Domain/Notifications/VacationRequestCancelledNotification.php create mode 100644 app/Domain/Notifications/VacationRequestWaitedForAdministrativeNotification.php create mode 100644 app/Domain/Notifications/VacationRequestWaitedForTechnicalNotification.php diff --git a/app/Architecture/Providers/EventServiceProvider.php b/app/Architecture/Providers/EventServiceProvider.php index 19c34bf..2e126e5 100644 --- a/app/Architecture/Providers/EventServiceProvider.php +++ b/app/Architecture/Providers/EventServiceProvider.php @@ -8,16 +8,23 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvi use Toby\Domain\Events\VacationRequestAcceptedByAdministrative; use Toby\Domain\Events\VacationRequestAcceptedByTechnical; use Toby\Domain\Events\VacationRequestApproved; +use Toby\Domain\Events\VacationRequestCancelled; use Toby\Domain\Events\VacationRequestCreated; use Toby\Domain\Events\VacationRequestRejected; use Toby\Domain\Events\VacationRequestStateChanged; +use Toby\Domain\Events\VacationRequestWaitedForAdministrative; +use Toby\Domain\Events\VacationRequestWaitedForTechnical; use Toby\Domain\Listeners\CreateVacationRequestActivity; use Toby\Domain\Listeners\HandleAcceptedByAdministrativeVacationRequest; use Toby\Domain\Listeners\HandleAcceptedByTechnicalVacationRequest; use Toby\Domain\Listeners\HandleApprovedVacationRequest; use Toby\Domain\Listeners\HandleCreatedVacationRequest; +use Toby\Domain\Listeners\SendApprovedVacationRequestNotification; +use Toby\Domain\Listeners\SendCancelledVacationRequestNotification; use Toby\Domain\Listeners\SendCreatedVacationRequestNotification; use Toby\Domain\Listeners\SendRejectedVacationRequestNotification; +use Toby\Domain\Listeners\SendWaitedForAdministrativeVacationRequestNotification; +use Toby\Domain\Listeners\SendWaitedForTechnicalVacationRequestNotification; class EventServiceProvider extends ServiceProvider { @@ -26,7 +33,10 @@ class EventServiceProvider extends ServiceProvider VacationRequestCreated::class => [HandleCreatedVacationRequest::class, SendCreatedVacationRequestNotification::class], VacationRequestAcceptedByTechnical::class => [HandleAcceptedByTechnicalVacationRequest::class], VacationRequestAcceptedByAdministrative::class => [HandleAcceptedByAdministrativeVacationRequest::class], - VacationRequestApproved::class => [HandleApprovedVacationRequest::class], + VacationRequestApproved::class => [HandleApprovedVacationRequest::class, SendApprovedVacationRequestNotification::class], VacationRequestRejected::class => [SendRejectedVacationRequestNotification::class], + VacationRequestCancelled::class => [SendCancelledVacationRequestNotification::class], + VacationRequestWaitedForTechnical::class => [SendWaitedForTechnicalVacationRequestNotification::class], + VacationRequestWaitedForAdministrative::class => [SendWaitedForAdministrativeVacationRequestNotification::class], ]; } diff --git a/app/Domain/Events/VacationRequestCancelled.php b/app/Domain/Events/VacationRequestCancelled.php new file mode 100644 index 0000000..a25e626 --- /dev/null +++ b/app/Domain/Events/VacationRequestCancelled.php @@ -0,0 +1,20 @@ +getUsersForNotifications() as $user) { + $user->notify(new VacationRequestApprovedNotification($event->vacationRequest, $user)); + } + + $event->vacationRequest->user->notify(new VacationRequestApprovedNotification($event->vacationRequest, $event->vacationRequest->user)); + } + + protected function getUsersForNotifications(): Collection + { + return User::query() + ->whereIn("role", [Role::TechnicalApprover, Role::AdministrativeApprover]) + ->get(); + } +} diff --git a/app/Domain/Listeners/SendCancelledVacationRequestNotification.php b/app/Domain/Listeners/SendCancelledVacationRequestNotification.php new file mode 100644 index 0000000..ec64eaf --- /dev/null +++ b/app/Domain/Listeners/SendCancelledVacationRequestNotification.php @@ -0,0 +1,34 @@ +getUsersForNotifications() as $user) { + $user->notify(new VacationRequestCancelledNotification($event->vacationRequest, $user)); + } + + $event->vacationRequest->user->notify(new VacationRequestCancelledNotification($event->vacationRequest, $event->vacationRequest->user)); + } + + protected function getUsersForNotifications(): Collection + { + return User::query() + ->whereIn("role", [Role::TechnicalApprover, Role::AdministrativeApprover]) + ->get(); + } +} diff --git a/app/Domain/Listeners/SendRejectedVacationRequestNotification.php b/app/Domain/Listeners/SendRejectedVacationRequestNotification.php index af5665d..3835d34 100644 --- a/app/Domain/Listeners/SendRejectedVacationRequestNotification.php +++ b/app/Domain/Listeners/SendRejectedVacationRequestNotification.php @@ -6,7 +6,6 @@ namespace Toby\Domain\Listeners; use Illuminate\Support\Collection; use Toby\Domain\Enums\Role; -use Toby\Domain\Events\VacationRequestCreated; use Toby\Domain\Events\VacationRequestRejected; use Toby\Domain\Notifications\VacationRequestRejectedNotification; use Toby\Eloquent\Models\User; diff --git a/app/Domain/Listeners/SendWaitedForAdministrativeVacationRequestNotification.php b/app/Domain/Listeners/SendWaitedForAdministrativeVacationRequestNotification.php new file mode 100644 index 0000000..5b10f2b --- /dev/null +++ b/app/Domain/Listeners/SendWaitedForAdministrativeVacationRequestNotification.php @@ -0,0 +1,32 @@ +getUsersForNotifications() as $user) { + $user->notify(new VacationRequestWaitedForAdministrativeNotification($event->vacationRequest, $user)); + } + } + + protected function getUsersForNotifications(): Collection + { + return User::query() + ->where("role", [Role::AdministrativeApprover]) + ->get(); + } +} diff --git a/app/Domain/Listeners/SendWaitedForTechnicalVacationRequestNotification.php b/app/Domain/Listeners/SendWaitedForTechnicalVacationRequestNotification.php new file mode 100644 index 0000000..4e1517e --- /dev/null +++ b/app/Domain/Listeners/SendWaitedForTechnicalVacationRequestNotification.php @@ -0,0 +1,32 @@ +getUsersForNotifications() as $user) { + $user->notify(new VacationRequestWaitedForTechnicalNotification($event->vacationRequest, $user)); + } + } + + protected function getUsersForNotifications(): Collection + { + return User::query() + ->where("role", [Role::TechnicalApprover]) + ->get(); + } +} diff --git a/app/Domain/Notifications/VacationRequestApprovedNotification.php b/app/Domain/Notifications/VacationRequestApprovedNotification.php new file mode 100644 index 0000000..74c8f65 --- /dev/null +++ b/app/Domain/Notifications/VacationRequestApprovedNotification.php @@ -0,0 +1,75 @@ + $this->vacationRequest, + ], + ); + + return $this->buildMailMessage($url); + } + + protected function buildMailMessage(string $url): MailMessage + { + $user = $this->vacationRequest->user->first_name; + $title = $this->vacationRequest->name; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + $requester = $this->vacationRequest->user->fullName; + + return (new MailMessage()) + ->greeting(__("Hi :user!", [ + "user" => $user, + ])) + ->subject(__("Vacation request :title has been approved", [ + "title" => $title, + ])) + ->line(__("The vacation request :title for user :requester has been approved.", [ + "title" => $title, + "requester" => $requester, + ])) + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); + } +} diff --git a/app/Domain/Notifications/VacationRequestCancelledNotification.php b/app/Domain/Notifications/VacationRequestCancelledNotification.php new file mode 100644 index 0000000..fc23c66 --- /dev/null +++ b/app/Domain/Notifications/VacationRequestCancelledNotification.php @@ -0,0 +1,75 @@ + $this->vacationRequest, + ], + ); + + return $this->buildMailMessage($url); + } + + protected function buildMailMessage(string $url): MailMessage + { + $user = $this->vacationRequest->user->first_name; + $title = $this->vacationRequest->name; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + $requester = $this->vacationRequest->user->fullName; + + return (new MailMessage()) + ->greeting(__("Hi :user!", [ + "user" => $user, + ])) + ->subject(__("Vacation request :title has been cancelled", [ + "title" => $title, + ])) + ->line(__("The vacation request :title for user :requester has been cancelled.", [ + "title" => $title, + "requester" => $requester, + ])) + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); + } +} diff --git a/app/Domain/Notifications/VacationRequestCreatedNotification.php b/app/Domain/Notifications/VacationRequestCreatedNotification.php index fe64791..4598752 100644 --- a/app/Domain/Notifications/VacationRequestCreatedNotification.php +++ b/app/Domain/Notifications/VacationRequestCreatedNotification.php @@ -35,25 +35,38 @@ class VacationRequestCreatedNotification extends Notification "vacationRequest" => $this->vacationRequest, ], ); - return $this->buildMailMessage($url); } protected function buildMailMessage(string $url): MailMessage { + $user = $this->vacationRequest->user->first_name; $title = $this->vacationRequest->name; - - $user = $this->vacationRequest->user; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + $appName = config("app.name"); return (new MailMessage()) ->greeting(__("Hi :user!", [ - "user" => $user->fullName, + "user" => $user, ])) - ->subject(__("Vacation request :title", [ + ->subject(__("Vacation request :title has been created", [ "title" => $title, ])) - ->line(__("Vacation request has been created.", [ + ->line(__("The vacation request :title has been created correctly in the :appName.", [ + "title" => $title, + "appName" => $appName, ])) - ->action(__("Show vacation request"), $url); + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); } } diff --git a/app/Domain/Notifications/VacationRequestRejectedNotification.php b/app/Domain/Notifications/VacationRequestRejectedNotification.php index 9ea88bf..f9777b1 100644 --- a/app/Domain/Notifications/VacationRequestRejectedNotification.php +++ b/app/Domain/Notifications/VacationRequestRejectedNotification.php @@ -43,17 +43,33 @@ class VacationRequestRejectedNotification extends Notification protected function buildMailMessage(string $url): MailMessage { + $user = $this->vacationRequest->user->first_name; $title = $this->vacationRequest->name; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + $requester = $this->vacationRequest->user->fullName; return (new MailMessage()) ->greeting(__("Hi :user!", [ - "user" => $this->user->fullName, + "user" => $user, ])) - ->subject(__("Vacation request :title", [ + ->subject(__("Vacation request :title has been rejected", [ "title" => $title, ])) - ->line(__("Vacation request has been rejected.", [ + ->line(__("The vacation request :title for user :requester has been rejected.", [ + "title" => $title, + "requester" => $requester, ])) - ->action(__("Show vacation request"), $url); + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); } } diff --git a/app/Domain/Notifications/VacationRequestWaitedForAdministrativeNotification.php b/app/Domain/Notifications/VacationRequestWaitedForAdministrativeNotification.php new file mode 100644 index 0000000..57bbb60 --- /dev/null +++ b/app/Domain/Notifications/VacationRequestWaitedForAdministrativeNotification.php @@ -0,0 +1,75 @@ + $this->vacationRequest, + ], + ); + + return $this->buildMailMessage($url); + } + + protected function buildMailMessage(string $url): MailMessage + { + $user = $this->user->first_name; + $requester = $this->vacationRequest->user->fullName; + $title = $this->vacationRequest->name; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + + return (new MailMessage()) + ->greeting(__("Hi :user!", [ + "user" => $user, + ])) + ->subject(__("Vacation request :title is waiting for your approval", [ + "title" => $title, + ])) + ->line(__("The vacation request :title from user: :requester is waiting for your approval.", [ + "title" => $title, + "requester" => $requester, + ])) + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); + } +} diff --git a/app/Domain/Notifications/VacationRequestWaitedForTechnicalNotification.php b/app/Domain/Notifications/VacationRequestWaitedForTechnicalNotification.php new file mode 100644 index 0000000..1357d66 --- /dev/null +++ b/app/Domain/Notifications/VacationRequestWaitedForTechnicalNotification.php @@ -0,0 +1,75 @@ + $this->vacationRequest, + ], + ); + + return $this->buildMailMessage($url); + } + + protected function buildMailMessage(string $url): MailMessage + { + $user = $this->user->first_name; + $requester = $this->vacationRequest->user->fullName; + $title = $this->vacationRequest->name; + $type = $this->vacationRequest->type->label(); + $from = $this->vacationRequest->from->format("d.m.Y"); + $to = $this->vacationRequest->to->format("d.m.Y"); + $days = $this->vacationRequest->vacations()->count(); + + return (new MailMessage()) + ->greeting(__("Hi :user!", [ + "user" => $user, + ])) + ->subject(__("Vacation request :title is waiting for your approval", [ + "title" => $title, + ])) + ->line(__("The vacation request :title from user: :requester is waiting for your approval.", [ + "title" => $title, + "requester" => $requester, + ])) + ->line(__("Vacation type: :type", [ + "type" => $type, + ])) + ->line(__("From :from to :to (number of days: :days)", [ + "from" => $from, + "to" => $to, + "days" => $days, + ])) + ->action(__("Click here for details"), $url); + } +} diff --git a/app/Domain/VacationRequestStateManager.php b/app/Domain/VacationRequestStateManager.php index 8384980..54e7db7 100644 --- a/app/Domain/VacationRequestStateManager.php +++ b/app/Domain/VacationRequestStateManager.php @@ -10,8 +10,11 @@ use Toby\Domain\Enums\VacationRequestState; use Toby\Domain\Events\VacationRequestAcceptedByAdministrative; use Toby\Domain\Events\VacationRequestAcceptedByTechnical; use Toby\Domain\Events\VacationRequestApproved; +use Toby\Domain\Events\VacationRequestCancelled; use Toby\Domain\Events\VacationRequestCreated; use Toby\Domain\Events\VacationRequestRejected; +use Toby\Domain\Events\VacationRequestWaitedForAdministrative; +use Toby\Domain\Events\VacationRequestWaitedForTechnical; use Toby\Eloquent\Models\VacationRequest; class VacationRequestStateManager @@ -39,12 +42,15 @@ class VacationRequestStateManager public function reject(VacationRequest $vacationRequest): void { $this->changeState($vacationRequest, VacationRequestState::Rejected); + $this->dispatcher->dispatch(new VacationRequestRejected($vacationRequest)); } public function cancel(VacationRequest $vacationRequest): void { $this->changeState($vacationRequest, VacationRequestState::Canceled); + + $this->dispatcher->dispatch(new VacationRequestCancelled($vacationRequest)); } public function acceptAsTechnical(VacationRequest $vacationRequest): void @@ -64,11 +70,15 @@ class VacationRequestStateManager public function waitForTechnical(VacationRequest $vacationRequest): void { $this->changeState($vacationRequest, VacationRequestState::WaitingForTechnical); + + $this->dispatcher->dispatch(new VacationRequestWaitedForTechnical($vacationRequest)); } public function waitForAdministrative(VacationRequest $vacationRequest): void { $this->changeState($vacationRequest, VacationRequestState::WaitingForAdministrative); + + $this->dispatcher->dispatch(new VacationRequestWaitedForAdministrative($vacationRequest)); } protected function changeState(VacationRequest $vacationRequest, VacationRequestState $state): void diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 386b736..c56ea8c 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -42,6 +42,7 @@ "Vacation limits have been updated.": "Limity urlopów zostały zaktualizowane.", "Vacation request has been created.": "Wniosek urlopowy został utworzony.", "Vacation request has been accepted.": "Wniosek urlopowy został zaakceptowany.", + "Vacation request has been approved.": "Wniosek urlopowy został zatwierdzony.", "Vacation request has been rejected.": "Wniosek urlopowy został odrzucony.", "Vacation request has been canceled.": "Wniosek urlopowy został anulowany.", "Hi :user!": "Cześć :user!", @@ -50,5 +51,18 @@ "Regards": "Z poważaniem", "If you're having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser:": "Jeżeli masz problemy z kliknięciem przycisku \":actionText\", skopiuj i wklej poniższy adres w pasek przeglądarki:", "All rights reserved.": "Wszelkie prawa zastrzeżone", - "Show vacation request": "Pokaż wniosek" + "Show vacation request": "Pokaż wniosek", + "Vacation request :title has been created" : "Wniosek :title został utworzony", + "The vacation request :title has been created correctly in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title.", + "Vacation type: :type": "Rodzaj wniosku: :type", + "From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)", + "Click here for details": "Kliknij, aby zobaczyć szczegóły", + "Vacation request :title is waiting for your approval": "Wniosek urlopowy :title czeka na zaakceptowanie", + "The vacation request :title from user: :requester is waiting for your approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację.", + "Vacation request :title has been approved": "Wniosek urlopowy :title został zatwierdzony", + "The vacation request :title for user :requester has been approved.": "Wniosek urlopowy :title od użytkownika :requester został zatwierdzony.", + "Vacation request :title has been cancelled": "WNiosek urlopowy :title został anulowany", + "The vacation request :title for user :requester has been cancelled.": "Wniosek urlopowy :title od użytkownika :requester został anulowany.", + "Vacation request :title has been rejected": "Wniosek urlopowy :title został odrzucony", + "The vacation request :title for user :requester has been rejected.": "Wniosek urlopowy :title od użytkownika :requester został odrzucony." }