repository = $repository; $this->setOrderWarehouse = $setOrderWarehouse; $this->confirmOrder = $confirmOrder; $this->updatesOrderSteps = $updatesOrderSteps; } /** * @param int $orderId * @param Request $request * @return JsonResponse * @throws InternalServerErrorException * @throws \App\Classes\Modules\Accounts\Exceptions\CannotUpdateOrderWarehouseException */ public function execute(int $orderId, Request $request) { try { $order = $this->repository->findOrFail($orderId); $orderObject = new OrderObject($orderId, null, $request->input('warehouse_id')); if($orderObject->getWarehouseId()){ $this->setOrderWarehouse->execute($orderObject); } $this->confirmOrder->execute($orderObject); return new JsonResponse("Order has been confirmed", HttpStatus::OK); } catch (CannotListCompanyOrdersException $exception){ throw new InternalServerErrorException("Failed to confirm order because {$exception->getMessage()}"); } } }