mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-29 17:33:58 +00:00
Merge remote-tracking branch 'origin/Order-Change-Address'
# Conflicts: # routes/api.php
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ControllersLogic\Orders;
|
||||
|
||||
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Orders\Services\UpdatesOrderAddress;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateOrderAddressLogic
|
||||
{
|
||||
/** @var UpdatesOrderAddress */
|
||||
private $UpdatesOrderAddress;
|
||||
|
||||
/**
|
||||
* UpdateOrderAddressLogic constructor.
|
||||
* @param UpdatesOrderAddress $UpdatesOrderAddress
|
||||
*/
|
||||
public function __construct(UpdatesOrderAddress $UpdatesOrderAddress)
|
||||
{
|
||||
$this->UpdatesOrderAddress = $UpdatesOrderAddress;
|
||||
}
|
||||
|
||||
public function execute(string $orderId, Request $request){
|
||||
try{
|
||||
|
||||
return $this->UpdatesOrderAddress->execute($orderId,$request->address_id);
|
||||
return new JsonResponse([],HttpStatus::REQUEST_ACCEPTED);
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new InternalServerErrorException("Failed to update address because{$exception->getMessage()}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services;
|
||||
|
||||
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\AddressObject;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class UpdatesOrderAddress
|
||||
{
|
||||
/** @var Order */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* UpdatesOrderAddress constructor.
|
||||
* @param Order $repository
|
||||
*/
|
||||
public function __construct(Order $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
public function execute(string $orderId,string $addressId){
|
||||
try{
|
||||
|
||||
$repository = $this->repository->findOrFail($orderId);
|
||||
$repository->address_id = $addressId;
|
||||
$repository->save();
|
||||
return new JsonResponse([],HttpStatus::OK);
|
||||
|
||||
}catch (\Exception $exception){
|
||||
|
||||
throw new InternalServerErrorException("Failed to update address because {$exception->getMessage()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Orders;
|
||||
|
||||
use App\Classes\Modules\ControllersLogic\Orders\UpdateOrderAddressLogic;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateOrderAddressController
|
||||
{
|
||||
public function update(string $orderId, Request $request, UpdateOrderAddressLogic $logic){
|
||||
return $logic->execute($orderId,$request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -140,6 +140,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
||||
|
||||
|
||||
|
||||
Route::post('/{orderId}/address','UpdateOrderAddressController@update')->name('address.order.update');
|
||||
|
||||
});
|
||||
|
||||
// Service Routes
|
||||
|
||||
Reference in New Issue
Block a user