createOrder = $createOrder; $this->updatesOrderWarehouse = $updatesOrderWarehouse; $this->updateOrderSteps = $updateOrderSteps; } /** * @param int $companyId * @param Request $request * @return \Illuminate\Http\JsonResponse * @throws InternalServerErrorException * @throws \App\Classes\Modules\Accounts\Exceptions\CannotUpdateOrderWarehouseException */ public function execute(int $companyId, Request $request) { try { $order = new OrderObject($request->input('marking'), $companyId, 1); /** @var int $orderId */ $orderId = $this->createOrder->execute($order); $this->updatesOrderWarehouse->execute($orderId, $request->input('warehouse_id'), 0); $this->updatesOrderWarehouse->execute($orderId, $request->input('warehouse_id'), 1); $this->updateOrderSteps->execute($orderId, $request); return new JsonResponse(null, HttpStatus::REQUEST_ACCEPTED); } catch (CannotCreateOrderException $exception){ throw new InternalServerErrorException("Failed to create order because {$exception->getMessage()}"); } } }