<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-03-22
* Time: 15:26
*/
namespace App\Controller;
use App\Entity\Location\City;
use App\Dto\ProfileListSpecification;
use App\Service\ProfileListSpecificationService;
use Flagception\Bundle\FlagceptionBundle\Annotations\Feature;
use OpenApi\Attributes as OA;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Cache(maxage: 60, public: true)]
class MasseurListController extends AbstractController
{
private const RESULT_SOURCE_WITHOUT_INTERMEDIARIES = 'massagers_without_intermediaries';
private const RESULT_SOURCE_MATURE = 'massagers_mature';
private const RESULT_SOURCE_CHEAP = 'massagers_cheap';
private const RESULT_SOURCE_OUTCALL = 'massagers_outcall';
public function __construct(
private ProfileListSpecificationService $profileListSpecificationService,
) {}
/**
* @Feature("has_masseurs")
*/
#[ParamConverter("city", converter: "city_converter")]
#[Route("/api/profiles/listing/city/{city}/category/massagers", name: "api.profile_listing.massagers", methods: "GET", format: "json")]
#[OA\Parameter(name: "page", in: "query", schema: new OA\Schema(type: "integer", default: 1, minimum: 1))]
#[OA\Tag(name: "ProfileListing")]
#[OA\Response(response: 200, description: '', content: new OA\JsonContent(ref: "#/components/schemas/ProfileListingPage"))]
public function page(Request $request, City $city): Response
{
return $this->forward('App\Controller\ProfileListController::listForMasseur', [
'city' => $city,
'page' => $request->attributes->getInt('page', 1),
'_route' => $request->attributes->get('_route'),
]);
}
/** @Feature("massagers_without_intermediaries") */
#[ParamConverter("city", converter: "city_converter")]
#[Route("/api/profiles/listing/city/{city}/category/massagers/private", name: "api.profile_listing.massagers.private", methods: "GET", format: "json")]
#[OA\Parameter(name: "page", in: "query", schema: new OA\Schema(type: "integer", default: 1, minimum: 1))]
#[OA\Tag(name: "ProfileListing")]
#[OA\Response(response: 200, description: '', content: new OA\JsonContent(ref: "#/components/schemas/ProfileListingPage"))]
public function listWithoutIntermediaries(Request $request, City $city): Response
{
return $this->listing(
$request,
$city,
$this->profileListSpecificationService->listMassagersWithoutIntermediaries(),
self::RESULT_SOURCE_WITHOUT_INTERMEDIARIES,
'/city/{city}/category/massagers_private',
);
}
/** @Feature("massagers_checked") */
#[ParamConverter("city", converter: "city_converter")]
#[Route("/api/profiles/listing/city/{city}/category/massagers/mature", name: "api.profile_listing.massagers.mature", methods: "GET", format: "json")]
#[OA\Parameter(name: "page", in: "query", schema: new OA\Schema(type: "integer", default: 1, minimum: 1))]
#[OA\Tag(name: "ProfileListing")]
#[OA\Response(response: 200, description: '', content: new OA\JsonContent(ref: "#/components/schemas/ProfileListingPage"))]
public function listMature(Request $request, City $city): Response
{
return $this->listing(
$request,
$city,
$this->profileListSpecificationService->listMassagersMature($city),
self::RESULT_SOURCE_MATURE,
);
}
/** @Feature("massagers_cheap") */
#[ParamConverter("city", converter: "city_converter")]
#[Route("/api/profiles/listing/city/{city}/category/massagers/price-low", name: "api.profile_listing.massagers.price_low", methods: "GET", format: "json")]
#[OA\Parameter(name: "page", in: "query", schema: new OA\Schema(type: "integer", default: 1, minimum: 1))]
#[OA\Tag(name: "ProfileListing")]
#[OA\Response(response: 200, description: '', content: new OA\JsonContent(ref: "#/components/schemas/ProfileListingPage"))]
public function listCheap(Request $request, City $city): Response
{
return $this->listing(
$request,
$city,
$this->profileListSpecificationService->listMassagersCheap($city),
self::RESULT_SOURCE_CHEAP,
);
}
/** @Feature("massagers_outcall") */
#[ParamConverter("city", converter: "city_converter")]
#[Route("/api/profiles/listing/city/{city}/category/massagers/outcall", name: "api.profile_listing.massagers.outcall", methods: "GET", format: "json")]
#[OA\Parameter(name: "page", in: "query", schema: new OA\Schema(type: "integer", default: 1, minimum: 1))]
#[OA\Tag(name: "ProfileListing")]
#[OA\Response(response: 200, description: '', content: new OA\JsonContent(ref: "#/components/schemas/ProfileListingPage"))]
public function listOutcall(Request $request, City $city): Response
{
return $this->listing(
$request,
$city,
$this->profileListSpecificationService->listMassagersOutcall(),
self::RESULT_SOURCE_OUTCALL,
'/city/{city}/category/massagers_outcall',
);
}
private function listing(
Request $request,
City $city,
ProfileListSpecification $specs,
string $source,
?string $apiEndpoint = null,
): Response {
return $this->forward(ProfileListController::class.'::profileLandingListing', [
'city' => $city,
'specs' => $specs,
'source' => $source,
'apiEndpoint' => $apiEndpoint,
'masseur' => null,
'_route' => $request->attributes->get('_route'),
'_route_params' => $request->attributes->get('_route_params'),
'_format' => $request->attributes->get('_format'),
'page' => $request->attributes->getInt('page', 1),
], $request->query->all());
}
}