Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DeleteUserController | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| delete | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Infrastructure\Controllers; |
| 6 | |
| 7 | use App\Identity\Application\Command\DeleteUserCommand; |
| 8 | use App\Identity\Application\Command\DeleteUserHandler; |
| 9 | use App\Identity\Domain\Exceptions\UserNotFound; |
| 10 | use App\Identity\Infrastructure\Http\ResolvesAuthenticatedUser; |
| 11 | use OpenApi\Attributes as OA; |
| 12 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 13 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 14 | use Symfony\Component\HttpFoundation\Response; |
| 15 | use Symfony\Component\Routing\Attribute\Route; |
| 16 | |
| 17 | #[OA\Tag(name: 'Users')] |
| 18 | class DeleteUserController extends AbstractController |
| 19 | { |
| 20 | use ResolvesAuthenticatedUser; |
| 21 | |
| 22 | public function __construct( |
| 23 | private readonly DeleteUserHandler $handler, |
| 24 | ) { |
| 25 | } |
| 26 | |
| 27 | #[Route('/users/me', name: 'users_delete', methods: ['DELETE'])] |
| 28 | public function delete(): Response |
| 29 | { |
| 30 | $securityUser = $this->securityUser(); |
| 31 | |
| 32 | try { |
| 33 | $this->handler->handle(new DeleteUserCommand($securityUser->userId())); |
| 34 | } catch (UserNotFound $e) { |
| 35 | return new JsonResponse(['error' => $e->getMessage()], 404); |
| 36 | } |
| 37 | |
| 38 | return new Response(null, Response::HTTP_NO_CONTENT); |
| 39 | } |
| 40 | } |