mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
89 lines
2.6 KiB
PHP
89 lines
2.6 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\Orders\Services\FetchesOrder;
|
|
use App\Classes\Modules\Packages\Standards\Rules\CanCreatePackage;
|
|
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
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 FetchesDistrict */
|
|
private $fetchesOrder;
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/** @var CreatesPackage */
|
|
private $createsPackage;
|
|
|
|
/**
|
|
* CreatePackageLogic constructor.
|
|
* @param CanCreatePackage $canCreatePackage
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
* @param FetchesCompany $fetchesCompany
|
|
* @param CreatesPackage $createsPackage
|
|
*/
|
|
public function __construct(CanCreatePackage $canCreatePackage, FetchesOrder $fetchesOrder, FetchesCompany $fetchesCompany, CreatesPackage $createsPackage)
|
|
{
|
|
$this->canCreatePackage = $canCreatePackage;
|
|
$this->fetchesOrder = $fetchesOrder;
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
$this->createsPackage = $createsPackage;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
|
|
$order = $this->fetchesOrder->execute(['id' => $request->input('order_id')]);
|
|
|
|
$object = new PackageObject(
|
|
$order->id,
|
|
null,
|
|
$request->input('type'),
|
|
$request->input('width'),
|
|
$request->input('height'),
|
|
$request->input('length'),
|
|
$request->input('weight'),
|
|
$request->input('quantity'),
|
|
0);
|
|
|
|
$this->canCreatePackage->passes($object);
|
|
|
|
$query = $this->createsPackage->execute($object);
|
|
|
|
return $this->resourceResponse(new PackageResource($query));
|
|
|
|
}
|
|
|
|
}
|