mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-19 04:24:00 +00:00
8a28eb1790
This reverts merge request !5
73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\ControllersLogic\Orders;
|
|
|
|
use App\Classes\Modules\Accounts\Exceptions\CannotListCompanyOrdersException;
|
|
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
|
|
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
|
use App\Classes\Modules\Orders\Services\ConfirmsOrder;
|
|
use App\Classes\Modules\Orders\Services\SetsOrderWarehouse;
|
|
use App\Classes\Modules\Orders\Services\UpdatesOrderSteps;
|
|
use App\Classes\ValueObjects\Constants\HttpStatus;
|
|
use App\Models\Order;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ConfirmOrderLogic
|
|
{
|
|
|
|
/** @var Order */
|
|
private $repository;
|
|
|
|
|
|
|
|
/** @var ConfirmsOrder */
|
|
private $confirmOrder;
|
|
|
|
/** @var UpdatesOrderSteps */
|
|
private $updatesOrderSteps;
|
|
|
|
/**
|
|
* ConfirmOrderLogic constructor.
|
|
* @param Order $repository
|
|
* @param SetsOrderWarehouse $setOrderWarehouse
|
|
* @param ConfirmsOrder $confirmOrder
|
|
* @param UpdatesOrderSteps $updatesOrderSteps
|
|
*/
|
|
public function __construct(Order $repository, SetsOrderWarehouse $setOrderWarehouse, ConfirmsOrder $confirmOrder, UpdatesOrderSteps $updatesOrderSteps)
|
|
{
|
|
$this->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()}");
|
|
}
|
|
}
|
|
} |