* #20 - wip * #20 - wip * #20 - fix * #20 - wip * #20 - fix * #20 - fix
This commit is contained in:
19
app/Domain/Listeners/CreateVacationRequestActivity.php
Normal file
19
app/Domain/Listeners/CreateVacationRequestActivity.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Listeners;
|
||||
|
||||
use Toby\Domain\Events\VacationRequestStateChanged;
|
||||
|
||||
class CreateVacationRequestActivity
|
||||
{
|
||||
public function handle(VacationRequestStateChanged $event): void
|
||||
{
|
||||
$event->vacationRequest->activities()->create([
|
||||
"from" => $event->from,
|
||||
"to" => $event->to,
|
||||
"user_id" => $event->user?->id,
|
||||
]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Listeners;
|
||||
|
||||
use Toby\Domain\Events\VacationRequestAcceptedByAdministrative;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
|
||||
class HandleAcceptedByAdministrativeVacationRequest
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(VacationRequestAcceptedByAdministrative $event): void
|
||||
{
|
||||
$this->stateManager->approve($event->vacationRequest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Listeners;
|
||||
|
||||
use Toby\Domain\Events\VacationRequestAcceptedByTechnical;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
|
||||
class HandleAcceptedByTechnicalVacationRequest
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(VacationRequestAcceptedByTechnical $event): void
|
||||
{
|
||||
$vacationRequest = $event->vacationRequest;
|
||||
|
||||
if ($this->configRetriever->needsAdministrativeApproval($vacationRequest->type)) {
|
||||
$this->stateManager->waitForAdministrative($vacationRequest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->stateManager->approve($vacationRequest);
|
||||
}
|
||||
}
|
24
app/Domain/Listeners/HandleApprovedVacationRequest.php
Normal file
24
app/Domain/Listeners/HandleApprovedVacationRequest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Listeners;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Toby\Domain\Events\VacationRequestApproved;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
|
||||
class HandleApprovedVacationRequest
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(VacationRequestApproved $event): void
|
||||
{
|
||||
$vacationRequest = $event->vacationRequest;
|
||||
|
||||
Log::info("approved! {$vacationRequest->id}");
|
||||
}
|
||||
}
|
37
app/Domain/Listeners/HandleCreatedVacationRequest.php
Normal file
37
app/Domain/Listeners/HandleCreatedVacationRequest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Listeners;
|
||||
|
||||
use Toby\Domain\Events\VacationRequestCreated;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
|
||||
class HandleCreatedVacationRequest
|
||||
{
|
||||
public function __construct(
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
protected VacationRequestStateManager $stateManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(VacationRequestCreated $event): void
|
||||
{
|
||||
$vacationRequest = $event->vacationRequest;
|
||||
|
||||
if ($this->configRetriever->needsTechnicalApproval($vacationRequest->type)) {
|
||||
$this->stateManager->waitForTechnical($vacationRequest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->configRetriever->needsAdministrativeApproval($vacationRequest->type)) {
|
||||
$this->stateManager->waitForAdministrative($vacationRequest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->stateManager->approve($vacationRequest);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user