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