Skip to content

Commit

Permalink
core: handle administrators activation
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Feb 6, 2024
1 parent d43a46b commit ea34d63
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ security:
pattern: ^/token/refresh
stateless: true

activate_admin:
pattern: ^/activate_admin/\d+$
security: false

api:
pattern: ^/.+
stateless: true
Expand Down
5 changes: 5 additions & 0 deletions app/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ post_send_administrator_activation_email:
_api_item_operation_name: 'send_activacion_email'
_api_receive: false

get_activate_administrator:
path: '/activate_admin/{id}'
methods: ['GET']
defaults:
_controller: App\Controller\Administrator\Activate
25 changes: 25 additions & 0 deletions app/src/App/Controller/Administrator/Activate.php
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);
}
}
32 changes: 32 additions & 0 deletions app/src/Demo/Domain/Service/Administrator/SetActive.php
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);
}
}
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;
}

0 comments on commit ea34d63

Please sign in to comment.