mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
WIP - Order steps & remaining APIs
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?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));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ 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\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;
|
||||
@@ -31,7 +31,7 @@ class CreatePackageLogic extends AbstractControllerLogic
|
||||
private $canCreatePackage;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
private $fetchesOrder;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
@@ -46,10 +46,10 @@ class CreatePackageLogic extends AbstractControllerLogic
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesPackage $createsPackage
|
||||
*/
|
||||
public function __construct(CanCreatePackage $canCreatePackage, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesPackage $createsPackage)
|
||||
public function __construct(CanCreatePackage $canCreatePackage, FetchesOrder $fetchesOrder, FetchesCompany $fetchesCompany, CreatesPackage $createsPackage)
|
||||
{
|
||||
$this->canCreatePackage = $canCreatePackage;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsPackage = $createsPackage;
|
||||
}
|
||||
@@ -64,13 +64,22 @@ class CreatePackageLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
||||
$order = $this->fetchesOrder->execute(['id' => $request->input('order_id')]);
|
||||
|
||||
$object = new PackageObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
||||
$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($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
||||
$query = $this->createsPackage->execute($object);
|
||||
|
||||
return $this->resourceResponse(new PackageResource($query));
|
||||
|
||||
|
||||
@@ -10,23 +10,18 @@ use App\Models\Company;
|
||||
|
||||
class CreatesPackage extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param PackageObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, PackageObject $object) {
|
||||
public function execute(PackageObject $object) {
|
||||
$model = new Package();
|
||||
$model->street_one = $object->getStreetOne();
|
||||
$model->street_two = $object->getStreetTwo();
|
||||
$model->country_id = $object->getCountryId();
|
||||
$model->state_id = $object->getStateId();
|
||||
$model->district_id = $object->getDistrictId();
|
||||
$model->postcode = $object->getPostCode();
|
||||
$model->order_id = $object->orderId();
|
||||
$model->claimant_id = $object->claimantId();
|
||||
$model->type = $object->type();
|
||||
$model->width = $object->width();
|
||||
$model->height = $object->height();
|
||||
$model->length = $object->length();
|
||||
$model->length = $object->weight();
|
||||
$model->length = $object->quantity();
|
||||
|
||||
return $this->handler($company->Packages(), $model);
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
use App\Classes\Modules\Packages\Standards\Validators\PackageItemValidation;
|
||||
|
||||
class CanCreatePackageItem extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackageValidation */
|
||||
private $packageItemValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackage constructor.
|
||||
* @param PackageItemValidation $packageItemValidation
|
||||
*/
|
||||
public function __construct(PackageItemValidation $packageItemValidation)
|
||||
{
|
||||
$this->packageItemValidation = $packageItemValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->packageItemValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
|
||||
class PackageValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'order_id' => $object->getOrderId(),
|
||||
'type' => $object->getType(),
|
||||
'width' => $object->getWidth(),
|
||||
'height' => $object->getHeight(),
|
||||
'length' => $object->getLength(),
|
||||
'weight' => $object->getWeight(),
|
||||
'quantity' => $object->getQuantity(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'order_id' => 'required',
|
||||
'type' => 'required',
|
||||
'width' => 'required',
|
||||
'height' => 'required',
|
||||
'length' => 'required',
|
||||
'weight' => 'required',
|
||||
'quantity' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,9 +16,13 @@ class PackageValidation extends AbstractValidation
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'street_one' => $object->getStreetOne(),
|
||||
'street_two' => $object->getStreetTwo(),
|
||||
'district_id' => $object->getDistrictId()
|
||||
'order_id' => $object->getOrderId(),
|
||||
'type' => $object->getType(),
|
||||
'width' => $object->getWidth(),
|
||||
'height' => $object->getHeight(),
|
||||
'length' => $object->getLength(),
|
||||
'weight' => $object->getWeight(),
|
||||
'quantity' => $object->getQuantity(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -27,8 +31,13 @@ class PackageValidation extends AbstractValidation
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'street_one' => 'required',
|
||||
'district_id' => 'required',
|
||||
'order_id' => 'required',
|
||||
'type' => 'required',
|
||||
'width' => 'required',
|
||||
'height' => 'required',
|
||||
'length' => 'required',
|
||||
'weight' => 'required',
|
||||
'quantity' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
@@ -30,9 +29,6 @@ class CreatePackingListLogic extends AbstractControllerLogic
|
||||
/** @var CanCreatePackingList */
|
||||
private $canCreatePackingList;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
@@ -46,10 +42,9 @@ class CreatePackingListLogic extends AbstractControllerLogic
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesPackingList $createsPackingList
|
||||
*/
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList)
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList)
|
||||
{
|
||||
$this->canCreatePackingList = $canCreatePackingList;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsPackingList = $createsPackingList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user