<?php
declare(strict_types=1);
namespace Slivki\Controller\Beauty;
use Slivki\Repository\Beauty\Masters\BeautyMasterRepositoryInterface;
use Slivki\Response\Beauty\Offer\Factory\MasterResponseFactory;
use Slivki\Services\CategoryBoxCacheService;
use Slivki\Services\DeviceTypeService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
final class GetMasterAction extends AbstractController
{
private MasterResponseFactory $masterResponseFactory;
private BeautyMasterRepositoryInterface $beautyMasterRepository;
private CategoryBoxCacheService $categoryBoxCacheService;
private DeviceTypeService $deviceTypeService;
public function __construct(
BeautyMasterRepositoryInterface $beautyMasterRepository,
MasterResponseFactory $masterResponseFactory,
CategoryBoxCacheService $categoryBoxCacheService,
DeviceTypeService $deviceTypeService
) {
$this->masterResponseFactory = $masterResponseFactory;
$this->beautyMasterRepository = $beautyMasterRepository;
$this->categoryBoxCacheService = $categoryBoxCacheService;
$this->deviceTypeService = $deviceTypeService;
}
/**
* @Route("/offer/master/{masterId}", name="offer_master_get", methods={"GET"})
*/
public function __invoke(Request $request, int $masterId): Response
{
$master = $this->masterResponseFactory->create(
$this->beautyMasterRepository->getById($masterId),
);
$view = $this->deviceTypeService->isMobileDevice($request)
? 'Slivki/mobile/beauty/master.html.twig'
: 'Slivki/beauty/offer/master.html.twig';
return $this->render($view, [
'master' => $master,
'offers' => $this->categoryBoxCacheService->getCategoryBoxByOfferIDList(
$master->getOfferIds(),
$this->deviceTypeService->isMobileDevice($request),
),
]);
}
}