mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-23 14:34:04 +00:00
80 lines
2.5 KiB
PHP
80 lines
2.5 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\Services\FetchesDistrict;
|
|
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 $fetchesDistrict;
|
|
|
|
/** @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, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesPackage $createsPackage)
|
|
{
|
|
$this->canCreatePackage = $canCreatePackage;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
$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
|
|
{
|
|
|
|
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
|
|
|
$object = new PackageObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
|
|
|
$this->canCreatePackage->passes($object);
|
|
|
|
$query = $this->createsPackage->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
|
|
|
return $this->resourceResponse(new PackageResource($query));
|
|
|
|
}
|
|
|
|
}
|