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

SYM-3 | Реализован фильтр по одному/нескольким вариантам

parent 852008ff
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -20,6 +20,42 @@ fos_elastica:
                            type: text
                        parent_id:
                            type: integer
                product_attributes:
                    type: object
                    properties:
                        id:
                            type: integer
                        product:
                            type: object
                            properties:
                                id:
                                    type: integer
                                name:
                                    type: text
                                price:
                                    type: float
                        attribute:
                            type: object
                            properties:
                                id:
                                    type: integer
                                name:
                                    type: text
                                type:
                                    type: text
                        value_item:
                            type: object
                            properties:
                                id:
                                    type: integer
                                name:
                                    type: text
                        value_int:
                            type: integer
                        value_date:
                            type: date
                        value_bool:
                            type: boolean
            persistence:
                driver: orm
                model: App\Entity\Product
@@ -85,7 +121,7 @@ fos_elastica:
                            type: text
                        type:
                            type: text
                attribute_item:
                value_item:
                    type: object
                    properties:
                        id:
+4 −1
Original line number Diff line number Diff line
@@ -22,3 +22,6 @@ services:

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

    App\Service\FilterService:
        $finder: '@fos_elastica.finder.product'
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Attribute;

#[\Attribute(\Attribute::TARGET_PARAMETER)]
class RequestQuery
{
}
+34 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Attribute\RequestQuery;
use App\Request\GetFilteredProductsRequest;
use App\Service\FilterService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class FilterController extends AbstractController
{
    public function __construct(private FilterService $filterService)
    {
    }

    #[Route('/products/filters', methods: ['GET'])]
    public function getFilters(): Response
    {
        return $this->json($this->filterService->getFilters());
    }

    #[Route('/products/filters', methods: ['POST'])]
    public function getProducts(#[RequestQuery] GetFilteredProductsRequest $request): Response
    {
        return $this->json($this->filterService->getProducts($request), context: [
            'circular_reference_handler' => function ($object) { return $object->getId(); },
            'groups' => ['product_attribute', 'product', 'category', 'attribute_item', 'attribute']
        ]);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -6,8 +6,10 @@ namespace App\Entity;

use App\Repository\AttributeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ORM\Entity(repositoryClass: AttributeRepository::class)]
#[Groups('attribute')]
class Attribute
{
    #[ORM\Id]
Loading