feat: api endpoints
This commit is contained in:
1 parent
7379f5ac93
commit
231aaaac9b
26 files changed
+606
-43
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\BusProNet\XmlLoader\HotelXmlLoader;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/api')]
|
||||
class HotelController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly HotelXmlLoader $xmlLoader)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/hotels', name: 'api_hotel_all')]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$hotels = $this->xmlLoader->loadAll();
|
||||
|
||||
return $this->json($hotels, Response::HTTP_OK, [], ['groups' => 'api:list']);
|
||||
}
|
||||
|
||||
#[Route('/hotels/{id}', name: 'api_hotels_single')]
|
||||
public function single(int $id): JsonResponse
|
||||
{
|
||||
$hotel = $this->xmlLoader->loadById($id);
|
||||
|
||||
if (null === $hotel) {
|
||||
return new JsonResponse(['message' => 'Not found'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $this->json($hotel, Response::HTTP_OK, [], ['groups' => 'api:single']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user