mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-25 07:24:21 +00:00
WIP - Order steps & remaining APIs
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreatePackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created PackingList',
|
||||
'message' => 'You have successfully created a new PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreatePackingList */
|
||||
private $canCreatePackingList;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CreatesPackingList */
|
||||
private $createsPackingList;
|
||||
|
||||
/**
|
||||
* CreatePackingListLogic constructor.
|
||||
* @param CanCreatePackingList $canCreatePackingList
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesPackingList $createsPackingList
|
||||
*/
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, FetchesCompany $fetchesCompany, CreatesPackingList $createsPackingList)
|
||||
{
|
||||
$this->canCreatePackingList = $canCreatePackingList;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsPackingList = $createsPackingList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 PackingListObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
||||
|
||||
$this->canCreatePackingList->passes($object);
|
||||
|
||||
$query = $this->createsPackingList->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+10
-2
@@ -13,11 +13,14 @@ class PackingListObject implements DataTransferObject
|
||||
|
||||
private $containerType;
|
||||
|
||||
public function __construct(int $packingListId, ?string $containerReference, int $containerType)
|
||||
private $sealReference;
|
||||
|
||||
public function __construct(int $packingListId, ?string $containerReference, int $containerType, ?String $sealReference)
|
||||
{
|
||||
$this->packingListId = $packingListId;
|
||||
$this->containerReference = $containerReference;
|
||||
$this->containerType = $containerType
|
||||
$this->containerType = $containerType;
|
||||
$this->sealReference = $sealReference;
|
||||
}
|
||||
|
||||
public function getPackingListId(): int
|
||||
@@ -34,4 +37,9 @@ class PackingListObject implements DataTransferObject
|
||||
{
|
||||
return $this->containerType;
|
||||
}
|
||||
|
||||
public function getSealReference(): int
|
||||
{
|
||||
return $this->sealReference;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Company;
|
||||
|
||||
class CreatesPackingList extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param PackingListObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, PackingListObject $object) {
|
||||
$model = new PackingList();
|
||||
$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();
|
||||
|
||||
return $this->handler($company->PackingLists(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Company;
|
||||
|
||||
class CreatesPackingListPackages extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param PackingListObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, PackingListObject $object) {
|
||||
$model = new PackingList();
|
||||
$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();
|
||||
|
||||
return $this->handler($company->PackingLists(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\PackingLists\Standards\Validators\ContainerPackingListValidation;
|
||||
|
||||
class CanCreateContainerPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackingListValidation */
|
||||
private $containerPackingListValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackingList constructor.
|
||||
* @param PackingListValidation $PackingListValidation
|
||||
*/
|
||||
public function __construct(PackingListValidation $containerPackingListValidation)
|
||||
{
|
||||
$this->containerPackingListValidation = $containerPackingListValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->containerPackingListValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,15 +11,15 @@ class CanCreatePackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackingListValidation */
|
||||
private $PackingListValidation;
|
||||
private $packingListValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackingList constructor.
|
||||
* @param PackingListValidation $PackingListValidation
|
||||
* @param PackingListValidation $packingListValidation
|
||||
*/
|
||||
public function __construct(PackingListValidation $PackingListValidation)
|
||||
public function __construct(PackingListValidation $packingListValidation)
|
||||
{
|
||||
$this->PackingListValidation = $PackingListValidation;
|
||||
$this->packingListValidation = $packingListValidation;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class CanCreatePackingList extends AbstractRule
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->PackingListValidation->validate($object);
|
||||
return $this->packingListValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\PackingLists\Standards\Validators\PackingListPackageValidation;
|
||||
|
||||
class CanCreatePackingListPackage extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackingListValidationPackage */
|
||||
private $packingListPackageValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackingListPackage constructor.
|
||||
* @param PackingListValidationPackage $packingListPackageValidation
|
||||
*/
|
||||
public function __construct(PackingListValidationPackage $packingListPackageValidation)
|
||||
{
|
||||
$this->packingListPackageValidation = $packingListPackageValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->packingListPackageValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
|
||||
class ContainerPackingListValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'status' => $object->getPackingListId(),
|
||||
'reference' => $object->getContainerReference(),
|
||||
'container_type' => $object->getContainerType(),
|
||||
'seal_reference' => $object->getSealReference(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'status' => 'required',
|
||||
'reference' => 'required',
|
||||
'container_type' => 'required',
|
||||
'seal_reference' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
|
||||
class PackingListPackageValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'packing_list_id' => $object->getPackingListId(),
|
||||
'package_id' => $object->getPackageId()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'packing_list_id' => 'required',
|
||||
'package_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,9 +16,8 @@ class PackingListValidation extends AbstractValidation
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'street_one' => $object->getStreetOne(),
|
||||
'street_two' => $object->getStreetTwo(),
|
||||
'district_id' => $object->getDistrictId()
|
||||
'status' => $object->getStatus(),
|
||||
'reference' => $object->getReference()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -27,8 +26,8 @@ class PackingListValidation extends AbstractValidation
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'street_one' => 'required',
|
||||
'district_id' => 'required',
|
||||
'status' => 'required',
|
||||
'reference' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ class CreateContainerPackingListsTable extends Migration
|
||||
$table->bigInteger('packing_list_id')->unsigned()->index();
|
||||
$table->string('container_reference',45);
|
||||
$table->integer('container_type');
|
||||
$table->string('seal_reference',45);
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user