Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetMyNotificationPreferencesAction
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
3.01
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
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
2.01
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Notification;
6
7use App\Domain\Auth\Data\UserAuthData;
8use App\Domain\Exception\AuthenticationException;
9use App\Domain\Notification\Service\NotificationPreferenceService;
10use App\Renderer\JsonRenderer;
11use Psr\Http\Message\ResponseInterface;
12use Psr\Http\Message\ServerRequestInterface;
13
14/**
15 * GET /api/me/notification-preferences
16 *
17 * Returns every notification type applicable to the requester's role,
18 * with `enabled` reflecting their stored preference (default false for
19 * types they haven't toggled). Admins see admin.* types; investor types
20 * are not yet implemented (FSC-113 PR A — see project memory).
21 */
22final readonly class GetMyNotificationPreferencesAction
23{
24    public function __construct(
25        private NotificationPreferenceService $preferences,
26        private JsonRenderer $renderer,
27    ) {}
28
29    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
30    {
31        $user = $request->getAttribute('user');
32        if (!$user instanceof UserAuthData) {
33            throw new AuthenticationException('User not authenticated');
34        }
35
36        $items = $this->preferences->getPreferencesForUser($user->userId, $user->role);
37
38        return $this->renderer->json($response, [
39            'success' => true,
40            'data' => ['preferences' => $items],
41        ]);
42    }
43}