| @@ 25-57 (lines=33) @@ | ||
| 22 | /** |
|
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | */ |
|
| 25 | class AjaxManageMenuAction |
|
| 26 | { |
|
| 27 | private $commandBus; |
|
| 28 | ||
| 29 | public function __construct(CommandBus $commandBus) |
|
| 30 | { |
|
| 31 | $this->commandBus = $commandBus; |
|
| 32 | } |
|
| 33 | ||
| 34 | public function __invoke(Request $request) |
|
| 35 | { |
|
| 36 | if (false === $request->isXmlHttpRequest()) { |
|
| 37 | throw new NotFoundHttpException(); |
|
| 38 | } |
|
| 39 | ||
| 40 | try { |
|
| 41 | $this->commandBus->handle( |
|
| 42 | new ManageMenuCommand( |
|
| 43 | $request->request->get('locale'), |
|
| 44 | $request->request->get('name'), |
|
| 45 | $request->request->get('items'), |
|
| 46 | $request->request->get('menu_id') |
|
| 47 | ) |
|
| 48 | ); |
|
| 49 | ||
| 50 | return new JsonResponse(null, 200); |
|
| 51 | } catch (TranslationDoesNotExistException $exception) { |
|
| 52 | return new JsonResponse('The given translation does not exist', 404); |
|
| 53 | } catch (MenuDoesNotExistException $exception) { |
|
| 54 | return new JsonResponse('The given menu does not exist', 404); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 25-57 (lines=33) @@ | ||
| 22 | /** |
|
| 23 | * @author Beñat Espiña <[email protected]> |
|
| 24 | */ |
|
| 25 | class AjaxManageMenuTranslationAction |
|
| 26 | { |
|
| 27 | private $commandBus; |
|
| 28 | ||
| 29 | public function __construct(CommandBus $commandBus) |
|
| 30 | { |
|
| 31 | $this->commandBus = $commandBus; |
|
| 32 | } |
|
| 33 | ||
| 34 | public function __invoke(Request $request) |
|
| 35 | { |
|
| 36 | if (false === $request->isXmlHttpRequest()) { |
|
| 37 | throw new NotFoundHttpException(); |
|
| 38 | } |
|
| 39 | ||
| 40 | try { |
|
| 41 | $this->commandBus->handle( |
|
| 42 | new ManageMenuTranslationCommand( |
|
| 43 | $request->request->get('menu_id'), |
|
| 44 | $request->request->get('name'), |
|
| 45 | $request->request->get('locale'), |
|
| 46 | $request->request->get('items') |
|
| 47 | ) |
|
| 48 | ); |
|
| 49 | ||
| 50 | return new JsonResponse(null, 200); |
|
| 51 | } catch (TranslationDoesNotExistException $exception) { |
|
| 52 | return new JsonResponse('The given translation does not exist', 404); |
|
| 53 | } catch (MenuDoesNotExistException $exception) { |
|
| 54 | return new JsonResponse('The given menu does not exist', 404); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||