Commit f75396fd authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

STA-966 | Добавил второй метод контроллера

parent fcef8fb7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
        "symfony/uid": "7.0.*",
        "symfony/ux-turbo": "^2.16",
        "symfony/validator": "6.4.*",
        "symfony/var-exporter": "6.4.5",
        "symfony/web-link": "7.0.*",
        "symfony/yaml": "7.0.*",
        "twig/extra-bundle": "^2.12|^3.0",
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "b57c193bd8eed3bbe092186cd3648c51",
    "content-hash": "814cfe23efd2a11a49bcfec687d342ba",
    "packages": [
        {
            "name": "composer/semver",
+44 −14
Original line number Diff line number Diff line
@@ -6,9 +6,11 @@ namespace App\Controller;

use App\Service\RestaurantService;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
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;

@@ -17,22 +19,50 @@ class RestaurantController extends AbstractController
{
    public function __construct(private RestaurantService $restaurantService) {}

    /**
     @OA\OpenApi\Response(response=200, description="Листинг ресторанов")
     * @OA\Parameter(
     *     name="page",
     *     in="query",
     *     description="Номер страницы",
     *     @OA\Schema(type="integer")
     * )
     * @Model(type=RestaurantList::class)
     */
    #[Route('/restaurants', name: 'restaurants', methods: ['GET'])]
    public function index(int $page): Response
    #[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
    {
        $restaurantsList = $this->restaurantService->getRestaurants();
        $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);
    }
}
+52 −1
Original line number Diff line number Diff line
@@ -2,13 +2,20 @@

namespace App\Mapper;

use App\Entity\Address;
use App\Entity\Email;
use App\Entity\Kitchen;
use App\Entity\Phone;
use App\Entity\Restaurant;
use App\Entity\RestaurantType;
use App\Entity\Tags;
use App\Model\File;
use App\Model\KitchenType;
use App\Model\RestaurantDetailElement;
use App\Model\RestaurantListingElement;
use App\Model\RestaurantType as RestaurantTypeModel;
use App\Model\Tag;
use Ramsey\Collection\Collection;

class RestaurantMapper
{
@@ -36,12 +43,56 @@ class RestaurantMapper
        );
    }

    public static function mapToDetailElement(Restaurant $restaurant): RestaurantDetailElement
    {
        $file = new File(
            1,
            "name",
            "description",
            10,
            "jpg",
            $restaurant->getPreviewImage()
        );
        return new RestaurantDetailElement(
            $restaurant->getId(),
            $restaurant->getName(),
            $restaurant->getCode(),
            implode(',', $restaurant->getCoordinates()),
            //self::mapToRestaurantType($restaurant->getTypeId()),
            $restaurant->getCheckPrice(),
            $restaurant->getCheckInfo(),
            new Collection(
                KitchenType::class, array_map(
                function (Kitchen $kitchen) {
                    return self::mapToKitchenType($kitchen);
                }, $restaurant->getKitchen()->toArray()),
            ),
            new Collection(Phone::class, $restaurant->getPhone()->toArray()),
            new Collection(Email::class, $restaurant->getEmail()->toArray()),
            new Collection(Address::class, $restaurant->getAddress()->toArray()),
            new Collection(Tag::class, array_map(
                function (Tags $tag) {
                    return new Tag(
                        "группа тегов 1",
                        new Collection($tag->getName()),
                    );
                }, $restaurant->getTags()->toArray()
            )),
            $restaurant->getSite(),
            $file,
            new Collection(File::class, [$file]),
            "Отель Арктика",
            "otel arktika",
            "otel arktika"
        );
    }

    public static function mapToRestaurantType(RestaurantType $restaurantType): RestaurantTypeModel
    {
        return new RestaurantTypeModel(
            $restaurantType->getId(),
            $restaurantType->getName(),
            $restaurantType->getCode(),
            $restaurantType->getCode()
        );
    }

+7 −7
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ class RestaurantDetailElement
    private string $name;
    private string $code;
    private string $coordinates;
    private RestaurantType $type;
    //private RestaurantType $type;
    private string $check;
    private string $checkInfo;
    /**
@@ -48,7 +48,7 @@ class RestaurantDetailElement
        string $name,
        string $code,
        string $coordinates,
        RestaurantType $type,
        //RestaurantType $type,
        string $check,
        string $checkInfo,
        Collection $kitchen,
@@ -67,7 +67,7 @@ class RestaurantDetailElement
        $this->name = $name;
        $this->code = $code;
        $this->coordinates = $coordinates;
        $this->type = $type;
        //$this->type = $type;
        $this->check = $check;
        $this->checkInfo = $checkInfo;
        $this->kitchen = $kitchen;
@@ -103,10 +103,10 @@ class RestaurantDetailElement
        return $this->coordinates;
    }

    public function getType(): RestaurantType
    {
        return $this->type;
    }
//    public function getType(): RestaurantType
//    {
//        return $this->type;
//    }

    public function getCheck(): string
    {
Loading