Newer
Older
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Service\RestaurantService;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
use OpenApi\Attributes\Schema;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use App\Model\RestaurantList;
#[Route("/api/v1")]
class RestaurantController extends AbstractController
{
public function __construct(private RestaurantService $restaurantService) {}
#[Route('/restaurants', name: 'restaurants', methods: ['GET'])]
#[OA\Response(response: 200, description: "Листинг ресторанов")]
#[OA\Parameter(
name: "page",
description: "Номер страницы",
in: "query",
schema: new Schema(type: "integer", default: 1, example: 1)
)]
#[OA\Parameter(
name: "limit",
description: "Лимит",
in: "query",
schema: new Schema(type: "integer", default: 12, example: 12)
)]
#[OA\Parameter(
name: "restaurant_type_id",
description: "Идентификатор типа ресторанов",
in: "query",
schema: new Schema(type: "integer")
)]
#[OA\Parameter(
name: "kitchen_id",
description: "Идентификатор кухни",
in: "query",
schema: new Schema(type: "integer")
)]
#[Model(type: RestaurantList::class)]
public function restaurants(Request $request): Response
$page = $request->query->getInt('page');
$limit = $request->query->getInt('limit');
$restaurantTypeId = $request->query->getInt('restaurant_type_id');
$kitchenId = $request->query->getInt('kitchen_id');
$restaurantsList = $this->restaurantService->getRestaurants(
$page, $limit, $restaurantTypeId, $kitchenId
);
return $this->json($restaurantsList);
}
#[Route('/restaurants/{restaurantId}', name: 'restaurant', methods: ['GET'])]
public function restaurant(Request $request): Response
{
$restaurantId = (int)$request->get('restaurantId');
$restaurant = $this->restaurantService->getRestaurant($restaurantId);
return $this->json($restaurant);
}