| @@ 13-45 (lines=33) @@ | ||
| 10 | use Symfony\Component\HttpFoundation\Response; |
|
| 11 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
| 12 | ||
| 13 | final class ShowLatestProductAction |
|
| 14 | { |
|
| 15 | /** @var ViewHandlerInterface */ |
|
| 16 | private $viewHandler; |
|
| 17 | ||
| 18 | /** @var ProductLatestViewRepositoryInterface */ |
|
| 19 | private $productLatestQuery; |
|
| 20 | ||
| 21 | public function __construct( |
|
| 22 | ViewHandlerInterface $viewHandler, |
|
| 23 | ProductLatestViewRepositoryInterface $productLatestQuery |
|
| 24 | ) { |
|
| 25 | $this->viewHandler = $viewHandler; |
|
| 26 | $this->productLatestQuery = $productLatestQuery; |
|
| 27 | } |
|
| 28 | ||
| 29 | public function __invoke(Request $request): Response |
|
| 30 | { |
|
| 31 | if (!$request->query->has('channel')) { |
|
| 32 | throw new NotFoundHttpException('Cannot find product without channel provided'); |
|
| 33 | } |
|
| 34 | ||
| 35 | try { |
|
| 36 | return $this->viewHandler->handle(View::create($this->productLatestQuery->getLatestProducts( |
|
| 37 | $request->query->get('channel'), |
|
| 38 | $request->query->get('locale'), |
|
| 39 | $request->query->getInt('limit', 4) |
|
| 40 | ), Response::HTTP_OK)); |
|
| 41 | } catch (\InvalidArgumentException $exception) { |
|
| 42 | throw new NotFoundHttpException($exception->getMessage()); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| @@ 14-46 (lines=33) @@ | ||
| 11 | use Symfony\Component\HttpFoundation\Response; |
|
| 12 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
| 13 | ||
| 14 | final class ShowProductDetailsByCodeAction |
|
| 15 | { |
|
| 16 | /** @var ProductDetailsViewRepositoryInterface */ |
|
| 17 | private $productCatalog; |
|
| 18 | ||
| 19 | /** @var ViewHandlerInterface */ |
|
| 20 | private $viewHandler; |
|
| 21 | ||
| 22 | public function __construct( |
|
| 23 | ProductDetailsViewRepositoryInterface $productCatalog, |
|
| 24 | ViewHandlerInterface $viewHandler |
|
| 25 | ) { |
|
| 26 | $this->productCatalog = $productCatalog; |
|
| 27 | $this->viewHandler = $viewHandler; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke(Request $request): Response |
|
| 31 | { |
|
| 32 | if (!$request->query->has('channel')) { |
|
| 33 | throw new NotFoundHttpException('Cannot find product without channel provided'); |
|
| 34 | } |
|
| 35 | ||
| 36 | try { |
|
| 37 | return $this->viewHandler->handle(View::create($this->productCatalog->findOneByCode( |
|
| 38 | $request->attributes->get('code'), |
|
| 39 | $request->query->get('channel'), |
|
| 40 | $request->query->get('locale') |
|
| 41 | ), Response::HTTP_OK)); |
|
| 42 | } catch (\InvalidArgumentException $exception) { |
|
| 43 | throw new NotFoundHttpException($exception->getMessage()); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||
| @@ 14-46 (lines=33) @@ | ||
| 11 | use Symfony\Component\HttpFoundation\Response; |
|
| 12 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
| 13 | ||
| 14 | final class ShowProductDetailsBySlugAction |
|
| 15 | { |
|
| 16 | /** @var ProductDetailsViewRepositoryInterface */ |
|
| 17 | private $productCatalog; |
|
| 18 | ||
| 19 | /** @var ViewHandlerInterface */ |
|
| 20 | private $viewHandler; |
|
| 21 | ||
| 22 | public function __construct( |
|
| 23 | ProductDetailsViewRepositoryInterface $productCatalog, |
|
| 24 | ViewHandlerInterface $viewHandler |
|
| 25 | ) { |
|
| 26 | $this->productCatalog = $productCatalog; |
|
| 27 | $this->viewHandler = $viewHandler; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function __invoke(Request $request): Response |
|
| 31 | { |
|
| 32 | if (!$request->query->has('channel')) { |
|
| 33 | throw new NotFoundHttpException('Cannot find product without channel provided'); |
|
| 34 | } |
|
| 35 | ||
| 36 | try { |
|
| 37 | return $this->viewHandler->handle(View::create($this->productCatalog->findOneBySlug( |
|
| 38 | $request->attributes->get('slug'), |
|
| 39 | $request->query->get('channel'), |
|
| 40 | $request->query->get('locale') |
|
| 41 | ), Response::HTTP_OK)); |
|
| 42 | } catch (\InvalidArgumentException $exception) { |
|
| 43 | throw new NotFoundHttpException($exception->getMessage()); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||