mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-22 14:04:21 +00:00
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Packages\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Packages\Services\CreatesPackage;
|
|
use App\Classes\Modules\Packages\Standards\Rules\CanCreatePackage;
|
|
use App\Classes\Modules\Packages\DataTransferObjects\PackagesListObject;
|
|
use App\Http\Resources\PackageResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreatePackageLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Package',
|
|
'message' => 'You have successfully created a new Package'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreatePackage */
|
|
private $canCreatePackage;
|
|
|
|
/** @var CreatesPackage */
|
|
private $createsPackage;
|
|
|
|
/**
|
|
* CreatePackageControllerLogic constructor.
|
|
* @param CanCreatePackage $canCreatePackage
|
|
* @param CreatesPackage $createsPackage
|
|
*/
|
|
public function __construct(CanCreatePackage $canCreatePackage, CreatesPackage $createsPackage)
|
|
{
|
|
$this->canCreatePackage = $canCreatePackage;
|
|
$this->createsPackage = $createsPackage;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
$object = new PackagesListObject($request->input('order_id'),$request->input('packages'));
|
|
$this->canCreatePackage->passes($object);
|
|
|
|
$query = $this->createsPackage->execute($object);
|
|
|
|
return $this->resourceResponse(new PackageResource($query));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
|
|
} |