<?php
declare(strict_types=1);
namespace Slivki\Controller\MobileApi\V2\WorkExample;
use OpenApi\Annotations as OA;
use Nelmio\ApiDocBundle\Annotation\Model;
use Slivki\Message\Query\WorkExample\Factory\GetWorkExamplesQueryFactory;
use Slivki\Messenger\Query\QueryBusInterface;
use Slivki\Request\WorkExample\GetWorkExamplesRequest;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Slivki\Dto\WorkExample\WorkExampleWithAddressesDto;
final class GetWorkExamplesAction
{
public GetWorkExamplesQueryFactory $queryFactory;
public QueryBusInterface $queryBus;
public function __construct(GetWorkExamplesQueryFactory $queryFactory, QueryBusInterface $queryBus)
{
$this->queryFactory = $queryFactory;
$this->queryBus = $queryBus;
}
/**
* @Route("/mobile/api/v2/work_examples", methods={"GET"}, name="mobile_api_v2_work_examples_get"),
* @OA\Tag(name="Work examples"),
* @OA\Response(
* response=200,
* description="Примеры работ",
* @OA\JsonContent(
* type="array",
* @OA\Items(
* @OA\Property(
* property="items",
* type="array",
* description="Примеры работ",
* @OA\Items(ref=@Model(type=WorkExampleWithAddressesDto::class)),
* ),
* @OA\Property(
* property="total",
* description="Общее количество примеров работ",
* example=185,
* ),
* ),
* ),
* ),
* @OA\Parameter(
* name="page",
* in="query",
* description="The page number to retrieve",
* @OA\Schema(type="integer", example=2, default=1, nullable=true),
* ),
* @OA\Parameter(
* name="perPage",
* in="query",
* description="The number of results per page",
* @OA\Schema(type="integer", example=24, default=24, nullable=true),
* ),
* @OA\Parameter(
* name="sortField",
* in="query",
* description="The field to sort by",
* @OA\Schema(
* type="string",
* example="distance",
* default="workExample.id",
* nullable=true,
* enum={"workExample.id", "distance", "workExample.created_at", "workExample.price"},
* ),
* ),
* @OA\Parameter(
* name="sortDirection",
* in="query",
* description="The direction to sort by",
* @OA\Schema(
* type="string",
* example="asc",
* default="asc",
* nullable=true,
* enum={"asc", "desc"},
* ),
* ),
* @OA\Parameter(
* name="categoryId",
* in="query",
* description="The ID of the category to filter by",
* @OA\Schema(type="integer", example=8, default=null, nullable=true),
* ),
* @OA\Parameter(
* name="offerId",
* in="query",
* description="The ID of the offer to filter by",
* @OA\Schema(type="integer", example=12345, default=null, nullable=true),
* ),
* @OA\Parameter(
* name="longitude",
* in="query",
* description="The user's longitude",
* @OA\Schema(type="float", example=27.557008, default=null, nullable=true),
* ),
* @OA\Parameter(
* name="latitude",
* in="query",
* description="The user's latitude",
* @OA\Schema(type="float", example=53.911724, default=null, nullable=true),
* ),
* @OA\Parameter(
* name="minPrice",
* in="query",
* description="Minimal price",
* @OA\Schema(type="float", example=1.00, default=null, nullable=true),
* ),
* @OA\Parameter(
* name="maxPrice",
* in="query",
* description="Maximum price",
* @OA\Schema(type="float", example=100.00, default=null, nullable=true),
* ),
*/
public function __invoke(GetWorkExamplesRequest $request): JsonResponse
{
return new JsonResponse($this->queryBus->handle($this->queryFactory->create($request)));
}
}