Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ListTripMembersController | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
4.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| list | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Trip\Infrastructure\Controllers; |
| 6 | |
| 7 | use App\Identity\Infrastructure\Http\ResolvesAuthenticatedUser; |
| 8 | use App\Trip\Application\Query\GetTripMembersHandler; |
| 9 | use App\Trip\Application\Query\GetTripMembersQuery; |
| 10 | use App\Trip\Domain\Exceptions\TripNotFound; |
| 11 | use App\Trip\Infrastructure\Http\ValidatesTripId; |
| 12 | use OpenApi\Attributes as OA; |
| 13 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 14 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 15 | use Symfony\Component\Routing\Attribute\Route; |
| 16 | |
| 17 | #[OA\Tag(name: 'Trips')] |
| 18 | class ListTripMembersController extends AbstractController |
| 19 | { |
| 20 | use ResolvesAuthenticatedUser; |
| 21 | use ValidatesTripId; |
| 22 | |
| 23 | public function __construct( |
| 24 | private readonly GetTripMembersHandler $handler, |
| 25 | ) { |
| 26 | } |
| 27 | |
| 28 | #[Route('/trips/{tripId}/members', name: 'trips_list_members', methods: ['GET'])] |
| 29 | public function list(string $tripId): JsonResponse |
| 30 | { |
| 31 | $securityUser = $this->securityUser(); |
| 32 | |
| 33 | if ($this->parseTripId($tripId) === null) { |
| 34 | return new JsonResponse(['error' => 'Trip not found.'], 404); |
| 35 | } |
| 36 | |
| 37 | try { |
| 38 | $view = $this->handler->handle(new GetTripMembersQuery($tripId, $securityUser->userId())); |
| 39 | } catch (TripNotFound $e) { |
| 40 | return new JsonResponse(['error' => $e->getMessage()], 404); |
| 41 | } |
| 42 | |
| 43 | return new JsonResponse($view->toArray(), 200); |
| 44 | } |
| 45 | } |