Skip to content
Snippets Groups Projects
RestaurantController.php 1.35 KiB
Newer Older
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Exception\RestaurantNotFoundException;
use App\Service\RestaurantService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;

#[Route("/api/v1")]
class RestaurantController extends AbstractController
{
    public function __construct(private RestaurantService $restaurantService) {}

    #[Route('/restaurants', name: 'restaurants', methods: ['GET'])]
    public function restaurants(RestaurantListRequest $request): Response
        return $this->json($this->restaurantService->getRestaurantsByRequest($request));
    #[Route('/restaurants/{restaurantId}', name: 'restaurant', methods: ['GET'])]
    public function restaurant(Request $request): Response
            return new Response(
                $this->restaurantService->getRestaurantByRequest($request),
                Response::HTTP_OK,
                ['Content-Type' => 'application/json']
            );
        } catch (RestaurantNotFoundException $e) {
            return $this->json([
                'success' => false,
                'message' => $e->getMessage(),
            ], $e->getCode());