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