src/Controller/MobileApi/V2/Beauty/Appointment/SearchAvailableAppointmentWithOfferInfoAction.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Slivki\Controller\MobileApi\V2\Beauty\Appointment;
  4. use OpenApi\Annotations as OA;
  5. use Nelmio\ApiDocBundle\Annotation\Model;
  6. use DateTimeImmutable;
  7. use Slivki\BusinessFeature\Yclients\Message\Query\SearchAvailableAppointmentWithOfferInfoQuery;
  8. use Slivki\BusinessFeature\Yclients\Request\SearchAvailableAppointmentRequest;
  9. use Slivki\BusinessFeature\Yclients\Response\OfferWithInfoAppointmentsResponse;
  10. use Slivki\Messenger\Query\QueryBusInterface;
  11. use Slivki\ValueObject\Coordinate;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. final class SearchAvailableAppointmentWithOfferInfoAction
  15. {
  16.     private QueryBusInterface $queryBus;
  17.     public function __construct(QueryBusInterface $queryBus)
  18.     {
  19.         $this->queryBus $queryBus;
  20.     }
  21.     /**
  22.      * @Route("/mobile/api/v2/beauty/appointment/search_with_offer", methods={"GET"}, name="mobile_api_v2_beauty_appointment_search_with_offer_get"),
  23.      * @OA\Tag(name="Beauty"),
  24.      * @OA\Response(
  25.      *      response=200,
  26.      *      description="Список доступных дат и времени для записи с информацией окции",
  27.      *      @OA\JsonContent(
  28.      *          type="array",
  29.      *          description="Доступные даты и время для записи",
  30.      *          @OA\Items(ref=@Model(type=OfferWithInfoAppointmentsResponse::class)),
  31.      *      ),
  32.      *  ),
  33.      *
  34.      * @OA\Parameter(
  35.      *    name="categoryId",
  36.      *    in="query",
  37.      *    description="The ID of the category",
  38.      *    @OA\Schema(type="integer", example=12345, nullable=false),
  39.      *  ),
  40.      * @OA\Parameter(
  41.      *    name="date",
  42.      *    in="query",
  43.      *    description="Дата",
  44.      *    required=true,
  45.      *  ),
  46.      * @OA\Parameter(
  47.      *    name="rangeTime",
  48.      *    in="query",
  49.      *    description="Диапазон времени",
  50.      *    required=true,
  51.      *    @OA\Schema(type="string", example="10:00-18:00", nullable=false),
  52.      *  ),
  53.      * @OA\Parameter(
  54.      *     name="latitude",
  55.      *     in="query",
  56.      *     description="Широта",
  57.      *     @OA\Schema(type="number", format="float", example=55.7558, nullable=true),
  58.      *     required=false,
  59.      *  ),
  60.      *  @OA\Parameter(
  61.      *     name="longitude",
  62.      *     in="query",
  63.      *     description="Долгота",
  64.      *     @OA\Schema(type="number", format="float", example=37.6173, nullable=true),
  65.      *     required=false,
  66.      *  ),
  67.      * @OA\Parameter(
  68.      *     name="sortBy",
  69.      *     in="query",
  70.      *     description="Сортировка",
  71.      *     @OA\Schema(type="string", example="rating", nullable=true),
  72.      *     required=false,
  73.      * ),
  74.      */
  75.     public function __invoke(SearchAvailableAppointmentRequest $request): JsonResponse
  76.     {
  77.         return new JsonResponse(
  78.             $this->queryBus->handle(
  79.                 new SearchAvailableAppointmentWithOfferInfoQuery(
  80.                     $request->getCategoryId(),
  81.                     new DateTimeImmutable($request->getDate()),
  82.                     $request->getRangeTime(),
  83.                     $request->getLatitude() === null || $request->getLongitude() === null
  84.                         null
  85.                         : new Coordinate($request->getLatitude(), $request->getLongitude()),
  86.                     $request->getSortBy(),
  87.                 ),
  88.             ),
  89.         );
  90.     }
  91. }