src/Controller/MobileApi/V2/WorkExample/GetWorkExamplesAction.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Controller\MobileApi\V2\WorkExample;
  4. use OpenApi\Annotations as OA;
  5. use Nelmio\ApiDocBundle\Annotation\Model;
  6. use Slivki\Message\Query\WorkExample\Factory\GetWorkExamplesQueryFactory;
  7. use Slivki\Messenger\Query\QueryBusInterface;
  8. use Slivki\Request\WorkExample\GetWorkExamplesRequest;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Slivki\Dto\WorkExample\WorkExampleWithAddressesDto;
  12. final class GetWorkExamplesAction
  13. {
  14.     public GetWorkExamplesQueryFactory $queryFactory;
  15.     public QueryBusInterface $queryBus;
  16.     public function __construct(GetWorkExamplesQueryFactory $queryFactoryQueryBusInterface $queryBus)
  17.     {
  18.         $this->queryFactory $queryFactory;
  19.         $this->queryBus $queryBus;
  20.     }
  21.     /**
  22.      * @Route("/mobile/api/v2/work_examples", methods={"GET"}, name="mobile_api_v2_work_examples_get"),
  23.      * @OA\Tag(name="Work examples"),
  24.      * @OA\Response(
  25.      *     response=200,
  26.      *     description="Примеры работ",
  27.      *     @OA\JsonContent(
  28.      *         type="array",
  29.      *         @OA\Items(
  30.      *             @OA\Property(
  31.      *                 property="items",
  32.      *                 type="array",
  33.      *                 description="Примеры работ",
  34.      *                 @OA\Items(ref=@Model(type=WorkExampleWithAddressesDto::class)),
  35.      *             ),
  36.      *             @OA\Property(
  37.      *                 property="total",
  38.      *                 description="Общее количество примеров работ",
  39.      *                 example=185,
  40.      *             ),
  41.      *         ),
  42.      *     ),
  43.      * ),
  44.      * @OA\Parameter(
  45.      *     name="page",
  46.      *     in="query",
  47.      *     description="The page number to retrieve",
  48.      *     @OA\Schema(type="integer", example=2, default=1, nullable=true),
  49.      * ),
  50.      * @OA\Parameter(
  51.      *     name="perPage",
  52.      *     in="query",
  53.      *     description="The number of results per page",
  54.      *     @OA\Schema(type="integer", example=24, default=24, nullable=true),
  55.      * ),
  56.      * @OA\Parameter(
  57.      *     name="sortField",
  58.      *     in="query",
  59.      *     description="The field to sort by",
  60.      *     @OA\Schema(
  61.      *         type="string",
  62.      *         example="distance",
  63.      *         default="workExample.id",
  64.      *         nullable=true,
  65.      *         enum={"workExample.id", "distance", "workExample.created_at", "workExample.price"},
  66.      *     ),
  67.      * ),
  68.      * @OA\Parameter(
  69.      *     name="sortDirection",
  70.      *     in="query",
  71.      *     description="The direction to sort by",
  72.      *     @OA\Schema(
  73.      *         type="string",
  74.      *         example="asc",
  75.      *         default="asc",
  76.      *         nullable=true,
  77.      *         enum={"asc", "desc"},
  78.      *     ),
  79.      * ),
  80.      * @OA\Parameter(
  81.      *     name="categoryId",
  82.      *     in="query",
  83.      *     description="The ID of the category to filter by",
  84.      *     @OA\Schema(type="integer", example=8, default=null, nullable=true),
  85.      * ),
  86.      * @OA\Parameter(
  87.      *     name="offerId",
  88.      *     in="query",
  89.      *     description="The ID of the offer to filter by",
  90.      *     @OA\Schema(type="integer", example=12345, default=null, nullable=true),
  91.      * ),
  92.      * @OA\Parameter(
  93.      *     name="longitude",
  94.      *     in="query",
  95.      *     description="The user's longitude",
  96.      *     @OA\Schema(type="float", example=27.557008, default=null, nullable=true),
  97.      * ),
  98.      * @OA\Parameter(
  99.      *     name="latitude",
  100.      *     in="query",
  101.      *     description="The user's latitude",
  102.      *     @OA\Schema(type="float", example=53.911724, default=null, nullable=true),
  103.      * ),
  104.      * @OA\Parameter(
  105.      *     name="minPrice",
  106.      *     in="query",
  107.      *     description="Minimal price",
  108.      *     @OA\Schema(type="float", example=1.00, default=null, nullable=true),
  109.      * ),
  110.      * @OA\Parameter(
  111.      *     name="maxPrice",
  112.      *     in="query",
  113.      *     description="Maximum price",
  114.      *     @OA\Schema(type="float", example=100.00, default=null, nullable=true),
  115.      * ),
  116.      */
  117.     public function __invoke(GetWorkExamplesRequest $request): JsonResponse
  118.     {
  119.         return new JsonResponse($this->queryBus->handle($this->queryFactory->create($request)));
  120.     }
  121. }