-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: handle administrators activation
- Loading branch information
1 parent
d43a46b
commit ea34d63
Showing
5 changed files
with
74 additions
and
0 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,25 @@ | ||
<?php | ||
|
||
namespace App\Controller\Administrator; | ||
|
||
use Demo\Domain\Service\Administrator\SetActiveInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class Activate | ||
{ | ||
public function __construct( | ||
private SetActiveInterface $setActive | ||
) { | ||
} | ||
|
||
public function __invoke(Request $request): Response | ||
{ | ||
/** @var int $administratorId */ | ||
$administratorId = $request->get('id'); | ||
|
||
$this->setActive->execute($administratorId); | ||
|
||
return new Response('Administrator activated', 200); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Demo\Domain\Service\Administrator; | ||
|
||
use Demo\Domain\Model\Administrator\AdministratorDto; | ||
use Demo\Domain\Model\Administrator\AdministratorRepository; | ||
use Demo\Domain\Service\Administrator\SetActiveInterface; | ||
use Ivoz\Core\Domain\Service\EntityTools; | ||
|
||
class SetActive implements SetActiveInterface | ||
{ | ||
public function __construct( | ||
private AdministratorRepository $administratorRepository, | ||
private EntityTools $entityTools | ||
) { | ||
} | ||
|
||
public function execute(int $administratorId): void | ||
{ | ||
$administrator = $this->administratorRepository->find($administratorId); | ||
|
||
// I don’t think we should launch an exception in this case. | ||
if ($administrator === null) { | ||
return; | ||
} | ||
|
||
/** @var AdministratorDto $administratorDto */ | ||
$administratorDto = $this->entityTools->entityToDto($administrator); | ||
$administratorDto->setActive(1); | ||
$this->entityTools->persistDto($administratorDto); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/Demo/Domain/Service/Administrator/SetActiveInterface.php
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,8 @@ | ||
<?php | ||
|
||
namespace Demo\Domain\Service\Administrator; | ||
|
||
interface SetActiveInterface | ||
{ | ||
public function execute(int $administratorId): void; | ||
} |