Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetTripController | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 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\GetTripHandler; |
| 9 | use App\Trip\Application\Query\GetTripQuery; |
| 10 | use App\Trip\Infrastructure\Http\ValidatesTripId; |
| 11 | use OpenApi\Attributes as OA; |
| 12 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 13 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 14 | use Symfony\Component\Routing\Attribute\Route; |
| 15 | |
| 16 | #[OA\Tag(name: 'Trips')] |
| 17 | class 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 | } |