-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
188 additions
and
36 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
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
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\User\Commands\Handlers; | ||
|
||
use App\Model\User\Commands\RemovePatrol; | ||
use App\Model\User\Repositories\PatrolRepository; | ||
use App\Model\User\Repositories\UserGroupRoleRepository; | ||
use App\Model\User\Repositories\UserRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | ||
|
||
class RemovePatrolHandler implements MessageHandlerInterface | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $em, | ||
private UserGroupRoleRepository $userGroupRoleRepository, | ||
private PatrolRepository $patrolRepository, | ||
private UserRepository $userRepository | ||
) { | ||
} | ||
|
||
public function __invoke(RemovePatrol $command): void | ||
{ | ||
$this->em->wrapInTransaction(function () use ($command): void { | ||
foreach ($command->getPatrol()->getUsersRoles() as $userRole) { | ||
$user = $userRole->getUser(); | ||
$this->userGroupRoleRepository->remove($userRole); | ||
if ($user->getRoles()->isEmpty() && $user->getGroupRoles()->isEmpty()) { | ||
$this->userRepository->remove($user); | ||
} | ||
} | ||
|
||
$this->patrolRepository->remove($command->getPatrol()); | ||
}); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\User\Commands\Handlers; | ||
|
||
use App\Model\User\Commands\RemovePatrol; | ||
use App\Model\User\Commands\RemoveTroop; | ||
use App\Model\User\Repositories\TroopRepository; | ||
use App\Model\User\Repositories\UserGroupRoleRepository; | ||
use App\Model\User\Repositories\UserRepository; | ||
use App\Services\CommandBus; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | ||
|
||
class RemoveTroopHandler implements MessageHandlerInterface | ||
{ | ||
public function __construct( | ||
private CommandBus $commandBus, | ||
private EntityManagerInterface $em, | ||
private UserGroupRoleRepository $userGroupRoleRepository, | ||
private TroopRepository $troopRepository, | ||
private UserRepository $userRepository | ||
) { | ||
} | ||
|
||
public function __invoke(RemoveTroop $command): void | ||
{ | ||
$this->em->wrapInTransaction(function () use ($command): void { | ||
foreach ($command->getTroop()->getPatrols() as $patrol) { | ||
$this->commandBus->handle(new RemovePatrol($patrol)); | ||
} | ||
|
||
foreach ($command->getTroop()->getUsersRoles() as $userRole) { | ||
$user = $userRole->getUser(); | ||
$this->userGroupRoleRepository->remove($userRole); | ||
if ($user->getRoles()->isEmpty() && $user->getGroupRoles()->isEmpty()) { | ||
$this->userRepository->remove($user); | ||
} | ||
} | ||
|
||
$this->troopRepository->remove($command->getTroop()); | ||
}); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\User\Commands; | ||
|
||
use App\Model\User\Patrol; | ||
|
||
class RemovePatrol | ||
{ | ||
public function __construct(private Patrol $patrol) | ||
{ | ||
} | ||
|
||
public function getPatrol(): Patrol | ||
{ | ||
return $this->patrol; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\User\Commands; | ||
|
||
use App\Model\User\Troop; | ||
|
||
class RemoveTroop | ||
{ | ||
public function __construct(private Troop $troop) | ||
{ | ||
} | ||
|
||
public function getTroop(): Troop | ||
{ | ||
return $this->troop; | ||
} | ||
} |
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
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