-
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
c8c386a
commit 110a400
Showing
7 changed files
with
77 additions
and
18 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,28 @@ | ||
<?php | ||
|
||
namespace App\Controller\Administrator; | ||
|
||
use Demo\Application\Service\Administrator\ActivateAdministrator; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class Activate | ||
{ | ||
public function __construct( | ||
private ActivateAdministrator $activateAdministrator | ||
) { | ||
} | ||
|
||
public function __invoke(Request $request): Response | ||
{ | ||
$administratorId = (int) $request->get('id'); | ||
|
||
try { | ||
$this->activateAdministrator->execute($administratorId); | ||
} catch(\DomainException $e) { | ||
return new Response($e->getMessage(), $e->getCode()); | ||
} | ||
|
||
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
30 changes: 30 additions & 0 deletions
30
app/src/Demo/Application/Service/Administrator/ActivateAdministrator.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,30 @@ | ||
<?php | ||
|
||
namespace Demo\Application\Service\Administrator; | ||
|
||
use Demo\Domain\Model\Administrator\AdministratorDto; | ||
use Demo\Domain\Model\Administrator\AdministratorRepository; | ||
use Ivoz\Core\Domain\Service\EntityTools; | ||
|
||
class ActivateAdministrator | ||
{ | ||
public function __construct( | ||
private AdministratorRepository $administratorRepository, | ||
private EntityTools $entityTools | ||
) { | ||
} | ||
|
||
public function execute(int $administratorId): void | ||
{ | ||
$administrator = $this->administratorRepository->find($administratorId); | ||
|
||
if ($administrator === null) { | ||
throw new \DomainException('Administrator not found.', 404); | ||
} | ||
|
||
/** @var AdministratorDto $administratorDto */ | ||
$administratorDto = $this->entityTools->entityToDto($administrator); | ||
$administratorDto->setActive(1); | ||
$this->entityTools->persistDto($administratorDto, $administrator); | ||
} | ||
} |
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