Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetMyConsentsAction
87.50% covered (warning)
87.50%
7 / 8
50.00% covered (danger)
50.00%
1 / 2
3.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Consent;
6
7use App\Domain\Auth\Data\UserAuthData;
8use App\Domain\Consent\Service\ConsentService;
9use App\Domain\Exception\AuthenticationException;
10use App\Renderer\JsonRenderer;
11use Psr\Http\Message\ResponseInterface;
12use Psr\Http\Message\ServerRequestInterface;
13
14/**
15 * GET /api/me/consents
16 *
17 * Returns the requester's current TCPA consent state — every known consent
18 * type with its granted flag, whether it is required, the copy version, and
19 * when it was last changed (FSC-87).
20 */
21final readonly class GetMyConsentsAction
22{
23    public function __construct(
24        private ConsentService $consentService,
25        private JsonRenderer $renderer,
26    ) {}
27
28    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
29    {
30        $user = $request->getAttribute('user');
31        if (!$user instanceof UserAuthData) {
32            throw new AuthenticationException('User not authenticated');
33        }
34
35        return $this->renderer->json($response, [
36            'success' => true,
37            'data' => ['consents' => $this->consentService->getCurrentForUser($user->userId)],
38        ]);
39    }
40}