Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetMyEmailsAction
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __invoke
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Notification;
6
7use App\Domain\Notification\Data\SentEmailData;
8use App\Domain\Notification\Repository\SentEmailRepository;
9use App\Renderer\JsonRenderer;
10use App\Support\Row;
11use Psr\Http\Message\ResponseInterface;
12use Psr\Http\Message\ServerRequestInterface;
13
14/**
15 * GET /api/me/emails
16 *
17 * Returns the emails the app sent to the authenticated investor (FSC-110),
18 * newest first. Scoped strictly to the caller's investorId, so a user only
19 * ever sees their own mail. Non-investor callers (e.g. admins with no investor
20 * record) get an empty list.
21 */
22final readonly class GetMyEmailsAction
23{
24    public function __construct(
25        private SentEmailRepository $repository,
26        private JsonRenderer $renderer,
27    ) {}
28
29    public function __invoke(
30        ServerRequestInterface $request,
31        ResponseInterface $response,
32    ): ResponseInterface {
33        $investorId = Row::nullableInt($request->getAttributes(), 'investorId');
34
35        $emails = $investorId === null
36            ? []
37            : $this->repository->findByInvestorId($investorId);
38
39        return $this->renderer->json($response, [
40            'success' => true,
41            'data' => [
42                'emails' => array_map(
43                    static fn(SentEmailData $email): array => $email->toArray(),
44                    $emails,
45                ),
46            ],
47        ]);
48    }
49}