mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
Merge branch '248_order_steps_apis' into 'master'
248 Remaining APIs See merge request CIEFWorldwideSdnBhd/shipping-portal!21
This commit is contained in:
+2
-1
@@ -19,7 +19,8 @@ public/.DS_Store
|
||||
public/images/.DS_Store
|
||||
gox.iml
|
||||
rebuild_docker.sh
|
||||
r.sh
|
||||
docker/*
|
||||
db/*
|
||||
docker-compose.yml
|
||||
package-lock.json
|
||||
package-lock.json
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanCreateBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesBank;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Http\Resources\BankResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateBankLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Bank',
|
||||
'message' => 'You have successfully created a new Bank'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateBank */
|
||||
private $canCreateBank;
|
||||
|
||||
/** @var CreatesBank */
|
||||
private $createsBank;
|
||||
|
||||
|
||||
/**
|
||||
* CreateBankLogic constructor.
|
||||
* @param CanCreateBank $canCreateBank
|
||||
* @param CreatesBank $createsBank
|
||||
*/
|
||||
public function __construct(
|
||||
CanCreateBank $canCreateBank,
|
||||
CreatesBank $createsBank
|
||||
)
|
||||
{
|
||||
$this->canCreateBank = $canCreateBank;
|
||||
$this->createsBank = $createsBank;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$bank_object = new BankObject($request->input('company_id'), $request->input('account_type'),
|
||||
$request->input('bank_name'), $request->input('holder_name'), $request->input('account_no'),
|
||||
$request->input('bank_branch'), $request->input('swift'), $request->input('snap'),
|
||||
$request->input('country_id'), $request->input('reference'));
|
||||
|
||||
$this->canCreateBank->passes($bank_object);
|
||||
|
||||
$bank = $this->createsBank->execute($bank_object);
|
||||
|
||||
return $this->resourceResponse(new BankResource($bank));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\RequestValidationException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Banks\Services\FetchesBank;
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanDeleteBank;
|
||||
use App\Classes\Modules\Banks\Services\DeletesBank;
|
||||
use App\Http\Resources\BankResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteBankLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Bank',
|
||||
'message' => 'You have successfully deleted the Bank'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanDeleteBank */
|
||||
private $canDeleteBank;
|
||||
|
||||
/** @var DeletesBank */
|
||||
private $deletesBank;
|
||||
|
||||
/** @var FetchesBank */
|
||||
private $fetchesBank;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteBankLogic constructor.
|
||||
* @param CanDeleteBank $canDeleteBank
|
||||
* @param DeletesBank $deletesBank
|
||||
* @param FetchesBank $fetchesBank
|
||||
*/
|
||||
public function __construct(
|
||||
CanDeleteBank $canDeleteBank,
|
||||
DeletesBank $deletesBank,
|
||||
FetchesBank $fetchesBank
|
||||
)
|
||||
{
|
||||
$this->canDeleteBank = $canDeleteBank;
|
||||
$this->deletesBank = $deletesBank;
|
||||
$this->fetchesBank = $fetchesBank;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$this->canDeleteBank->passes();
|
||||
|
||||
$bank = $this->fetchesBank->execute(['id' => $request->route('id')]);
|
||||
|
||||
if($bank->default){
|
||||
throw new RequestValidationException('You can\'t delete bank account when it set to default');
|
||||
}
|
||||
|
||||
$this->deletesBank->execute($bank);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Banks\Services\ListsBanks;
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanListBanks;
|
||||
use App\Http\Resources\BankResource;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListBanksLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieve Banks',
|
||||
'message' => 'You have successfully retrieved a list of Banks'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListBanks */
|
||||
private $canListBanks;
|
||||
|
||||
/** @var ListsBanks */
|
||||
private $listsBanks;
|
||||
|
||||
/**
|
||||
* ListBanksLogic constructor.
|
||||
* @param CanListBanks $canListBanks
|
||||
* @param ListsBanks $listsBanks
|
||||
*/
|
||||
public function __construct(CanListBanks $canListBanks, ListsBanks $listsBanks)
|
||||
{
|
||||
$this->canListBanks = $canListBanks;
|
||||
$this->listsBanks = $listsBanks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$this->canListBanks->passes();
|
||||
|
||||
$banks = $this->listsBanks->execute($this->listsBanks->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(BankResource::collection($banks));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\BankResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Banks\Services\FetchesBank;
|
||||
use App\Classes\Modules\Banks\Services\ListsBanks;
|
||||
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank;
|
||||
use App\Classes\Modules\Banks\Services\ResetsBanksDefault;
|
||||
use App\Classes\Modules\Banks\Services\SetsBankToDefault;
|
||||
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Classes\ValueObjects\Constants\DefaultType;
|
||||
|
||||
use App\Models\Bank;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SetBankToDefaultLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Bank',
|
||||
'message' => 'You have successfully updated the Bank'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ResetsBanksDefault */
|
||||
private $resetsBanksDefault;
|
||||
|
||||
/** @var FetchesBank */
|
||||
private $fetchesBank;
|
||||
|
||||
/** @var SetsBankToDefault*/
|
||||
private $setsBankToDefault ;
|
||||
|
||||
/**
|
||||
* SetBankToDefaultLogic constructor.
|
||||
* @param ResetsBanksDefault $resetsBanksDefault
|
||||
* @param FetchesBank $fetchesBank
|
||||
* @param SetsBankToDefault $setsBankToDefault
|
||||
*/
|
||||
public function __construct(ResetsBanksDefault $resetsBanksDefault, FetchesBank $fetchesBank, SetsBankToDefault $setsBankToDefault)
|
||||
{
|
||||
$this->resetsBanksDefault = $resetsBanksDefault;
|
||||
$this->fetchesBank = $fetchesBank;
|
||||
$this->setsBankToDefault = $setsBankToDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
/** @var Bank $bank */
|
||||
$bank = $this->fetchesBank->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->resetsBanksDefault->execute($bank);
|
||||
|
||||
$this->setsBankToDefault->execute($bank);
|
||||
|
||||
return $this->resourceResponse(new BankResource($this->setsBankToDefault->execute($bank)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\BankResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Banks\Services\FetchesBank;
|
||||
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank;
|
||||
use App\Classes\Modules\Banks\Services\UpdatesBank;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateBankLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Bank Account',
|
||||
'message' => 'You have successfully updated the Bank Account'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateBank */
|
||||
private $canUpdateBank;
|
||||
|
||||
/** @var UpdatesBank */
|
||||
private $updatesBank;
|
||||
|
||||
/** @var FetchesBank */
|
||||
private $fetchesBank;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateBankLogic constructor.
|
||||
* @param CanUpdateBank $canUpdateBank
|
||||
* @param UpdatesBank $updatesBank
|
||||
* @param FetchesBank $fetchesBank
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateBank $canUpdateBank,
|
||||
UpdatesBank $updatesBank,
|
||||
FetchesBank $fetchesBank
|
||||
)
|
||||
{
|
||||
$this->canUpdateBank = $canUpdateBank;
|
||||
$this->updatesBank = $updatesBank;
|
||||
$this->fetchesBank = $fetchesBank;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$bankObject = new BankObject($request->input('company_id'), $request->input('country_id'),
|
||||
$request->input('reference'), $request->input('bank_name'), $request->input('holder_name'),
|
||||
$request->input('account_no'));
|
||||
|
||||
|
||||
$bank = $this->fetchesBank->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->canUpdateBank->passes($bankObject);
|
||||
|
||||
$bank_query = $this->updatesBank->execute($bank, $bankObject);
|
||||
|
||||
return $this->resourceResponse(new BankResource($bank_query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class BankObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $company_id;
|
||||
|
||||
/** @var int */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
private $bank_name;
|
||||
|
||||
/** @var string */
|
||||
private $holder_name;
|
||||
|
||||
/** @var string */
|
||||
private $account_no;
|
||||
|
||||
/** @var int */
|
||||
private $country_id;
|
||||
|
||||
/** @var string|null */
|
||||
private $reference;
|
||||
|
||||
/**
|
||||
* BankObject constructor.
|
||||
* @param int $company_id
|
||||
* @param int $type
|
||||
* @param string $bank_name
|
||||
* @param string $holder_name
|
||||
* @param string $account_no
|
||||
* @param int $country_id
|
||||
* @param null|string $reference
|
||||
*/
|
||||
public function __construct(int $company_id, int $type, string $bank_name, string $holder_name, string $account_no, ?string $bank_branch = null, ?string $swift = null, ?string $snap = null, int $country_id, ?string $reference = null)
|
||||
{
|
||||
$this->company_id = $company_id;
|
||||
$this->type = $type;
|
||||
$this->bank_name = $bank_name;
|
||||
$this->holder_name = $holder_name;
|
||||
$this->account_no = $account_no;
|
||||
$this->bank_branch = $bank_branch;
|
||||
$this->swift = $swift;
|
||||
$this->snap = $snap;
|
||||
$this->country_id = $country_id;
|
||||
$this->reference = $reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): int
|
||||
{
|
||||
return $this->company_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBankName(): string
|
||||
{
|
||||
return $this->bank_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHolderName(): string
|
||||
{
|
||||
return $this->holder_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccountNo(): string
|
||||
{
|
||||
return $this->account_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getBankBranch(): ?string
|
||||
{
|
||||
return $this->bank_branch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getSwift(): ?string
|
||||
{
|
||||
return $this->swift;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getSnap(): ?string
|
||||
{
|
||||
return $this->snap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCountryId(): int
|
||||
{
|
||||
return $this->country_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Models\Bank;
|
||||
|
||||
class CreatesBank extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(BankObject $object) {
|
||||
|
||||
$model = new Bank();
|
||||
$model->company_id = $object->getCompanyId();
|
||||
$model->reference = $object->getReference();
|
||||
$model->bank_name = $object->getBankName();
|
||||
$model->holder_name = $object->getHolderName();
|
||||
$model->account_no = $object->getAccountNo();
|
||||
$model->bank_branch = $object->getBankBranch();
|
||||
$model->swift = $object->getSwift();
|
||||
$model->snap = $object->getSnap();
|
||||
$model->type = $object->getType();
|
||||
$model->country_id = $object->getCountryId();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Bank;
|
||||
|
||||
class DeletesBank extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bank $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Bank $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Bank;
|
||||
|
||||
class FetchesBank extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Bank */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesBank constructor.
|
||||
* @param Bank $repository
|
||||
*/
|
||||
public function __construct(Bank $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Bank;
|
||||
|
||||
class ListsBanks extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var Bank */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBank constructor.
|
||||
* @param Bank $repository
|
||||
*/
|
||||
public function __construct(Bank $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Bank;
|
||||
|
||||
class ResetsBanksDefault extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bank $bank
|
||||
* @return void
|
||||
*/
|
||||
public function execute(Bank $bank)
|
||||
{
|
||||
$bank->company->banks()->where('type', $bank->type)->update(['default' => false]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Bank;
|
||||
|
||||
class SetsBankToDefault extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bank $model
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Bank $model)
|
||||
{
|
||||
$model->default = true;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Models\Bank;
|
||||
|
||||
class UpdatesBank extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bank $model
|
||||
* @param BankObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Bank $model, BankObject $object)
|
||||
{
|
||||
$model->bank_name = $object->getBankName();
|
||||
$model->holder_name = $object->getHolderName();
|
||||
$model->account_no = $object->getAccountNo();
|
||||
$model->bank_branch = $object->getBankBranch();
|
||||
$model->swift = $object->getSwift();
|
||||
$model->snap = $object->getSnap();
|
||||
$model->default = $object->getDefault();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Banks\Standards\Validators\BankValidation;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
class CanCreateBank extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var BankValidation */
|
||||
private $BankValidation;
|
||||
|
||||
/**
|
||||
* CanCreateBank constructor.
|
||||
* @param BankValidation $BankValidation
|
||||
*/
|
||||
public function __construct(BankValidation $BankValidation)
|
||||
{
|
||||
$this->BankValidation = $BankValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->BankValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
|
||||
class CanDeleteBank extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Banks\Standards\Validators\BankValidation;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
class CanListBanks extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Classes\Modules\Banks\Standards\Validators\BankValidation;
|
||||
|
||||
class CanUpdateBank extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var BankValidation */
|
||||
private $BankValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanUpdateBank constructor.
|
||||
* @param BankValidation $BankValidation
|
||||
*/
|
||||
public function __construct(BankValidation $BankValidation)
|
||||
{
|
||||
$this->BankValidation = $BankValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->BankValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
|
||||
class BankValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'country_id' => $object->getCountryId(),
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'bank_name' => $object->getBankName(),
|
||||
'holder_name' => $object->getHolderName(),
|
||||
'account_no' => $object->getAccountNo()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'country_id' => 'required',
|
||||
'company_id' => 'required',
|
||||
'bank_name' => 'required',
|
||||
'holder_name' => 'required',
|
||||
'account_no' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
|
||||
use App\Classes\Modules\Companies\Processors\CreateCompanyModuleProcessor;
|
||||
@@ -15,15 +14,17 @@ use Illuminate\Http\Request;
|
||||
|
||||
class CreateCompanyLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* CreateCompanyLogic constructor.
|
||||
* @param CreateCompanyProcessor $createCompanyProcessor
|
||||
* @param CreateCompanyModuleProcessor $createCompanyModuleProcessor
|
||||
*/
|
||||
public function __construct(CreateCompanyProcessor $createCompanyProcessor ,CreateCompanyModuleProcessor $createCompanyModuleProcessor)
|
||||
public function __construct(CreateCompanyProcessor $createCompanyProcessor ,CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateEntityProcessor $createUnityEntityProcessor)
|
||||
{
|
||||
$this->createCompanyProcessor = $createCompanyProcessor;
|
||||
$this->createCompanyModuleProcessor = $createCompanyModuleProcessor;
|
||||
$this->createUnityEntityProcessor = $createUnityEntityProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,4 +57,4 @@ class CreateCompanyLogic extends AbstractControllerLogic
|
||||
return $this->resourceResponse(new CompanyResource($company));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,17 +15,21 @@ class CompanyModuleObject implements DataTransferObject
|
||||
/** @var int|null */
|
||||
private $status;
|
||||
|
||||
/** @var string */
|
||||
private $unity_hash_id;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param int $companyId
|
||||
* @param int|null $type
|
||||
* @param int|null $status
|
||||
*/
|
||||
public function __construct(int $companyId, int $type, int $status)
|
||||
public function __construct(int $companyId, int $type, int $status, ?string $unity_hash_id)
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
$this->unity_hash_id = $unity_hash_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,4 +55,12 @@ class CompanyModuleObject implements DataTransferObject
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUnityHashId(): string
|
||||
{
|
||||
return $this->unity_hash_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ class CompanyObject implements DataTransferObject
|
||||
/** @var int|null */
|
||||
private $status;
|
||||
|
||||
/** @var string */
|
||||
private $unity_hash_id;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param string $name
|
||||
@@ -71,7 +74,4 @@ class CompanyObject implements DataTransferObject
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntityProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyModuleObject;
|
||||
use App\Classes\Modules\Companies\Services\CreatesCompanyModule;
|
||||
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompanyModule;
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Models\Company;
|
||||
|
||||
class CreateCompanyModuleProcessor
|
||||
@@ -17,13 +16,19 @@ class CreateCompanyModuleProcessor
|
||||
/** @var CreatesCompanyModule */
|
||||
private $createsCompanyModule;
|
||||
|
||||
private $createUnityEntityProcessor;
|
||||
|
||||
private $canCreateCompanyModule;
|
||||
|
||||
/**
|
||||
* CreateCompanyModuleProcessor constructor.
|
||||
* @param CreatesCompanyModule $createsCompanyModule
|
||||
*/
|
||||
public function __construct(CreatesCompanyModule $createsCompanyModule)
|
||||
public function __construct(CanCreateCompanyModule $canCreateCompanyModule, CreatesCompanyModule $createsCompanyModule, CreateEntityProcessor $createUnityEntityProcessor)
|
||||
{
|
||||
$this->createsCompanyModule = $createsCompanyModule;
|
||||
$this->createUnityEntityProcessor = $createUnityEntityProcessor;
|
||||
$this->canCreateCompanyModule = $canCreateCompanyModule;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,12 +37,17 @@ class CreateCompanyModuleProcessor
|
||||
*/
|
||||
public function execute(Company $company , ?int $businessType): Model
|
||||
{
|
||||
$unityEntity = $this->createUnityEntityProcessor->execute($company->name);
|
||||
|
||||
$company_module_object = new CompanyModuleObject(
|
||||
$company->id,
|
||||
$businessType??BusinessType::IMPORTER,
|
||||
$company->status,
|
||||
$unityEntity->hash_id
|
||||
);
|
||||
|
||||
$this->canCreateCompanyModule->passes($company_module_object);
|
||||
|
||||
return $this->createsCompanyModule->execute($company_module_object);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ class CreateCompanyProcessor
|
||||
$companyName,
|
||||
mt_rand(1000, 9999).(new GeneratesInitials())->name($companyName)->length(3)->generate(),
|
||||
$companyType,
|
||||
$status);
|
||||
|
||||
$status
|
||||
);
|
||||
|
||||
$this->canCreateCompany->passes($company_object);
|
||||
|
||||
@@ -59,4 +59,4 @@ class CreateCompanyProcessor
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ class CreatesCompanyModule extends AbstractUpdateRecord
|
||||
$model->company_id = $object->getCompanyId();
|
||||
$model->type = $object->getType();
|
||||
$model->status = $object->getStatus();
|
||||
$model->unity_hash_id = $object->getUnityHashId();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Classes\Modules\Companies\Standards\Validators\CompanyModuleValidation;
|
||||
|
||||
class CanCreateCompanyModule extends AbstractRule
|
||||
{
|
||||
/** @var CompanyValidation */
|
||||
private $companyModuleValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanCreateCompany constructor.
|
||||
* @param CompanyValidation $companyValidation
|
||||
*/
|
||||
public function __construct(CompanyModuleValidation $companyModuleValidation)
|
||||
{
|
||||
$this->companyModuleValidation = $companyModuleValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->companyModuleValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
class CompanyModuleValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'unity_hash_id' => $object->getUnityHashId()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'unity_hash_id' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class CompanyValidation extends AbstractValidation
|
||||
{
|
||||
return [
|
||||
'company_name' => $object->getName(),
|
||||
'company_reference' => $object->getReference(),
|
||||
'company_reference' => $object->getReference()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\CreatesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanCreateContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Http\Resources\ContainerPackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateContainerPackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created PackingList',
|
||||
'message' => 'You have successfully created a new PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateContainerPackingList */
|
||||
private $canCreateContainerPackingList;
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/** @var CreatesPackingList */
|
||||
private $createsContainerPackingList;
|
||||
|
||||
public function __construct(CanCreateContainerPackingList $canCreateContainerPackingList, FetchesPackingList $fetchesPackingList, CreatesContainerPackingList $createsContainerPackingList)
|
||||
{
|
||||
$this->canCreateContainerPackingList = $canCreateContainerPackingList;
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
$this->createsContainerPackingList = $createsContainerPackingList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$packingList = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);
|
||||
|
||||
$object = new ContainerPackingListObject( $packingList->id , $request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
|
||||
|
||||
$this->canCreateContainerPackingList->passes($object);
|
||||
|
||||
$query = $this->createsContainerPackingList->execute($object);
|
||||
|
||||
return $this->resourceResponse(new ContainerPackingListResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\DeletesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanDeleteContainerPackingList;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteContainerPackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Deleted ContainerPackingList',
|
||||
'message' => 'You have successfully deleted a ContainerPackingList'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CanDeleteContainerPackingList */
|
||||
private $canDeleteContainerPackingList;
|
||||
|
||||
/** @var DeletesContainerPackingList */
|
||||
private $deletesContainerPackingList;
|
||||
|
||||
/** @var FetchesContainerPackingList */
|
||||
private $fetchesContainerPackingList;
|
||||
|
||||
/**
|
||||
* DeleteContainerPackingListControllersLogic constructor.
|
||||
* @param CanDeleteContainerPackingList $canDeleteContainerPackingList
|
||||
* @param DeletesContainerPackingList $deletesContainerPackingList
|
||||
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
||||
*/
|
||||
public function __construct(CanDeleteContainerPackingList $canDeleteContainerPackingList, DeletesContainerPackingList $deletesContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList)
|
||||
{
|
||||
$this->canDeleteContainerPackingList = $canDeleteContainerPackingList;
|
||||
$this->deletesContainerPackingList = $deletesContainerPackingList;
|
||||
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canDeleteContainerPackingList->passes();
|
||||
|
||||
$query = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesContainerPackingList->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanFetchContainerPackingList;
|
||||
use App\Http\Resources\ContainerPackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchContainerContainerPackingList extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved ContainerPackingList',
|
||||
'message' => 'You have successfully retrieved a ContainerPackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchContainerPackingList */
|
||||
private $canFetchContainerPackingList;
|
||||
|
||||
/** @var FetchesContainerPackingList */
|
||||
private $fetchesContainerPackingList;
|
||||
|
||||
/**
|
||||
* FetchContainerPackingListControllersLogic constructor.
|
||||
* @param CanFetchContainerPackingList $canFetchContainerPackingList
|
||||
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
||||
*/
|
||||
public function __construct(CanFetchContainerPackingList $canFetchContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList)
|
||||
{
|
||||
$this->canFetchContainerPackingList = $canFetchContainerPackingList;
|
||||
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchContainerPackingList->passes();
|
||||
|
||||
$query = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new ContainerPackingListResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\ListsContainerPackingLists;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanListContainerPackingLists;
|
||||
use App\Http\Resources\ContainerPackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListContainerPackingListsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved ContainerPackingLists',
|
||||
'message' => 'You have successfully retrieved a list of ContainerPackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListContainerPackingLists */
|
||||
private $canListContainerPackingLists;
|
||||
|
||||
/** @var ListsContainerPackingLists */
|
||||
private $listsContainerPackingLists;
|
||||
|
||||
/**
|
||||
* ListContainerPackingListsLogic constructor.
|
||||
* @param CanListContainerPackingLists $canListContainerPackingLists
|
||||
* @param ListsContainerPackingLists $listsContainerPackingLists
|
||||
*/
|
||||
public function __construct(CanListContainerPackingLists $canListContainerPackingLists, ListsContainerPackingLists $listsContainerPackingLists)
|
||||
{
|
||||
$this->canListContainerPackingLists = $canListContainerPackingLists;
|
||||
$this->listsContainerPackingLists = $listsContainerPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canListContainerPackingLists->passes();
|
||||
|
||||
$query = $this->listsContainerPackingLists->execute($this->listsContainerPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(ContainerPackingListResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\UpdatesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Services\FetchesContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Rules\CanUpdateContainerPackingList;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Http\Resources\ContainerPackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateContainerPackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated ContainerPackingList',
|
||||
'message' => 'You have successfully updated the ContainerPackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateContainerPackingList */
|
||||
private $canUpdateContainerPackingList;
|
||||
|
||||
/** @var UpdatesContainerPackingList */
|
||||
private $updatesContainerPackingList;
|
||||
|
||||
/** @var FetchesContainerPackingList */
|
||||
private $fetchesContainerPackingList;
|
||||
|
||||
/**
|
||||
* UpdateContainerPackingListLogic constructor.
|
||||
* @param CanUpdateContainerPackingList $canUpdateContainerPackingList
|
||||
* @param UpdatesContainerPackingList $updatesContainerPackingList
|
||||
* @param FetchesContainerPackingList $fetchesContainerPackingList
|
||||
*/
|
||||
public function __construct(CanUpdateContainerPackingList $canUpdateContainerPackingList, UpdatesContainerPackingList $updatesContainerPackingList, FetchesContainerPackingList $fetchesContainerPackingList)
|
||||
{
|
||||
$this->canUpdateContainerPackingList = $canUpdateContainerPackingList;
|
||||
$this->updatesContainerPackingList = $updatesContainerPackingList;
|
||||
$this->fetchesContainerPackingList = $fetchesContainerPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$container = $this->fetchesContainerPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
$object = new ContainerPackingListObject( $container->packing_list_id , $request->input('container_reference'), $request->input('container_type'), $request->input('seal_reference'));
|
||||
|
||||
$this->canUpdateContainerPackingList->passes($object);
|
||||
|
||||
$query = $this->updatesContainerPackingList->execute($container, $object);
|
||||
|
||||
return $this->resourceResponse(new ContainerPackingListResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ContainerPackingListObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $packingListId;
|
||||
|
||||
private $containerReference;
|
||||
|
||||
private $containerType;
|
||||
|
||||
private $sealReference;
|
||||
|
||||
public function __construct(int $packingListId, ?string $containerReference, int $containerType, ?String $sealReference)
|
||||
{
|
||||
$this->packingListId = $packingListId;
|
||||
$this->containerReference = $containerReference;
|
||||
$this->containerType = $containerType;
|
||||
$this->sealReference = $sealReference;
|
||||
}
|
||||
|
||||
public function getPackingListId(): int
|
||||
{
|
||||
return $this->packingListId;
|
||||
}
|
||||
|
||||
public function getContainerReference(): ?string
|
||||
{
|
||||
return $this->containerReference;
|
||||
}
|
||||
|
||||
public function getContainerType(): int
|
||||
{
|
||||
return $this->containerType;
|
||||
}
|
||||
|
||||
public function getSealReference(): ?string
|
||||
{
|
||||
return $this->sealReference;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Models\ContainerPackingList;
|
||||
|
||||
class CreatesContainerPackingList extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ContainerPackingListObject $object) {
|
||||
$model = new ContainerPackingList();
|
||||
|
||||
$model->packing_list_id = $object->getPackingListId();
|
||||
$model->container_reference = $object->getContainerReference();
|
||||
$model->container_type = $object->getContainerType();
|
||||
$model->seal_reference = $object->getSealReference();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\ContainerPackingList;
|
||||
|
||||
class DeletesContainerPackingList extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ContainerPackingList $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ContainerPackingList $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\ContainerPackingList;
|
||||
|
||||
class FetchesContainerPackingList extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var ContainerPackingList */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesContainerPackingList constructor.
|
||||
* @param ContainerPackingList $repository
|
||||
*/
|
||||
public function __construct(ContainerPackingList $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\ContainerPackingList;
|
||||
|
||||
class ListsContainerPackingLists extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var ContainerPackingList */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsContainerPackingLists constructor.
|
||||
* @param ContainerPackingList $repository
|
||||
*/
|
||||
public function __construct(ContainerPackingList $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Models\ContainerPackingList;
|
||||
|
||||
class UpdatesContainerPackingList extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ContainerPackingList $model
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ContainerPackingList $model, ContainerPackingListObject $object) {
|
||||
|
||||
$model->container_reference = $object->getContainerReference();
|
||||
$model->container_type = $object->getContainerType();
|
||||
$model->seal_reference = $object->getSealReference();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Classes\Modules\PackingLists\Standards\Validators\ContainerPackingListValidation;
|
||||
|
||||
class CanCreateContainerPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackingListValidation */
|
||||
private $containerPackingListValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackingList constructor.
|
||||
* @param PackingListValidation $PackingListValidation
|
||||
*/
|
||||
public function __construct(ContainerPackingListValidation $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;
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
|
||||
class CanDeleteContainerPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
|
||||
class CanFetchContainerPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
|
||||
class CanListContainerPackingLists extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\ContainerPackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
use App\Classes\Modules\ContainerPackingLists\Standards\Validators\ContainerPackingListValidation;
|
||||
|
||||
class CanUpdateContainerPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ContainerPackingListValidation */
|
||||
private $ContainerPackingListValidation;
|
||||
|
||||
/**
|
||||
* CanUpdateContainerPackingList constructor.
|
||||
* @param ContainerPackingListValidation $ContainerPackingListValidation
|
||||
*/
|
||||
public function __construct(ContainerPackingListValidation $ContainerPackingListValidation)
|
||||
{
|
||||
$this->ContainerPackingListValidation = $ContainerPackingListValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->ContainerPackingListValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ContainerPackingLists\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\ContainerPackingListObject;
|
||||
|
||||
class ContainerPackingListValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
/**
|
||||
* @param ContainerPackingListObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'packing_list_id' => $object->getPackingListId(),
|
||||
'container_reference' => $object->getContainerReference(),
|
||||
'container_type' => $object->getContainerType(),
|
||||
'seal_reference' => $object->getSealReference(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'packing_list_id' => 'required',
|
||||
'container_reference' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,9 +35,9 @@ class CreateOrderStepsProcessor
|
||||
$this->fetchesOrderSteps = $fetchesOrderSteps;
|
||||
}
|
||||
|
||||
public function execute(Model $order, string $currentStep){
|
||||
public function execute(Model $order, string $currentStep, $appointee_id){
|
||||
|
||||
$order_steps_object = new OrderStepsObject($order->id, $order->company_module_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null);
|
||||
$order_steps_object = new OrderStepsObject($order->id, $appointee_id, $currentStep, true, 0, OrderStatus::PROCESSING, 0, null);
|
||||
|
||||
$this->canCreateOrderStep->passes($order_steps_object);
|
||||
|
||||
|
||||
@@ -27,24 +27,23 @@ class GenerateOrderStepsProcessor
|
||||
|
||||
private $createsManyOrderStep;
|
||||
|
||||
private $unityConfig;
|
||||
|
||||
private $updateOrderStepProcessors;
|
||||
|
||||
private $getContractObligationsProcessor;
|
||||
private $getUnityContractObligationsProcessor;
|
||||
|
||||
public function __construct(UpdatesOrderCurrentStepProcessor $updatesOrderCurrentStep, CreatesManyOrderSteps $createsManyOrderStep, UpdateOrderStepsProcessor $updateOrderStepProcessors, GetContractObligationsProcessor $getContractObligationsProcessor)
|
||||
public function __construct(UpdatesOrderCurrentStepProcessor $updatesOrderCurrentStep, CreatesManyOrderSteps $createsManyOrderStep, UpdateOrderStepsProcessor $updateOrderStepProcessors, GetContractObligationsProcessor $getUnityContractObligationsProcessor)
|
||||
{
|
||||
$this->updatesOrderCurrentStep = $updatesOrderCurrentStep;
|
||||
$this->unityConfig = Config::get('unity');
|
||||
$this->createsManyOrderStep = $createsManyOrderStep;
|
||||
$this->updateOrderStepProcessors = $updateOrderStepProcessors;
|
||||
$this->getContractObligationsProcessor = $getContractObligationsProcessor;
|
||||
$this->getUnityContractObligationsProcessor = $getUnityContractObligationsProcessor;
|
||||
}
|
||||
|
||||
public function execute(Order $order){
|
||||
|
||||
$obligations = $this->getContractObligationsProcessor->execute();
|
||||
$obligations = $this->getUnityContractObligationsProcessor->execute();
|
||||
|
||||
//TODO: Update Appointee ID to Entity User base on hash key
|
||||
|
||||
foreach($obligations as $step){
|
||||
$orderSteps[] = new OrderStepsObject(
|
||||
|
||||
@@ -35,12 +35,6 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
|
||||
$order = $this->createOrderProcessor->execute($request);
|
||||
|
||||
//$order_object = new OrderObject($request->get('company_module_id'), '', '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
|
||||
|
||||
//$this->canCreateOrder->passes($order_object);
|
||||
|
||||
//$order = $this->createsOrder->execute($order_object);
|
||||
|
||||
return $this->resourceResponse(new OrderResource($order));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Orders\Services\Steps;
|
||||
namespace App\Classes\Modules\Orders\Processors;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
use App\Classes\Modules\Orders\Services\CreatesOrder;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\OrderSteps\Services\FetchesOrderSteps;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanUpdateCurrentStep;
|
||||
use App\Classes\Modules\OrderSteps\Processors\UpdateOrderStepsProcessor;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanConfirmOrder;
|
||||
use App\Classes\Modules\OrderSteps\Processors\GenerateOrderStepsProcessor;
|
||||
use App\Classes\ValueObjects\Constants\OrderStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderSteps;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderStep;
|
||||
use App\Classes\ValueObjects\Constants\OrderType;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ConfirmOrderProcessor
|
||||
{
|
||||
private $canUpdateCurrentStep;
|
||||
private $canConfirmOrder;
|
||||
|
||||
private $updatesCurrentStep;
|
||||
private $generateOrderStepsProcessor;
|
||||
|
||||
private $fetchesOrder;
|
||||
|
||||
private $fetchesOrderSteps;
|
||||
|
||||
private $updateOrderStepProcessors;
|
||||
|
||||
public function __construct(CanUpdateCurrentStep $canUpdateCurrentStep, FetchesOrder $fetchesOrder, FetchesOrderSteps $fetchesOrderSteps, UpdatesOrderCurrentStep $updatesCurrentStep, UpdateOrderStepsProcessor $updateOrderStepProcessors)
|
||||
public function __construct(CanConfirmOrder $canConfirmOrder, GenerateOrderStepsProcessor $generateOrderStepsProcessor, FetchesOrder $fetchesOrder)
|
||||
{
|
||||
$this->canUpdateCurrentStep = $canUpdateCurrentStep;
|
||||
$this->updatesCurrentStep = $updatesCurrentStep;
|
||||
$this->canConfirmOrder = $canConfirmOrder;
|
||||
$this->generateOrderStepsProcessor = $generateOrderStepsProcessor;
|
||||
$this->fetchesOrder = $fetchesOrder;
|
||||
$this->fetchesOrderSteps = $fetchesOrderSteps;
|
||||
$this->updateOrderStepProcessors = $updateOrderStepProcessors;
|
||||
}
|
||||
|
||||
public function execute(int $orderId, string $currentStep){
|
||||
public function execute(int $orderId){
|
||||
|
||||
$order_object = new OrderObject(0, '', '', 0, 0, $currentStep, $orderId);
|
||||
$order_object = new OrderObject(0,'','',0,0, '',$orderId);
|
||||
|
||||
$this->canUpdateCurrentStep->passes($order_object);
|
||||
$this->canConfirmOrder->passes($order_object);
|
||||
|
||||
$order = $this->fetchesOrder->execute(['id'=>$order_object->getId()]);
|
||||
|
||||
$order_steps = $this->fetchesOrderSteps->execute(['order_id'=>$order_object->getId(), 'status'=> OrderStatus::PROCESSING, 'order_by' => 'sequence', 'per_page' => 1]);
|
||||
|
||||
$order_object->setCurrentStep($currentStep);
|
||||
|
||||
$order = $this->updatesCurrentStep->execute($order, $order_object);
|
||||
|
||||
$this->updateOrderStepProcessors->execute($currentStep);
|
||||
$this->generateOrderStepsProcessor->execute($order);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Classes\Modules\Orders\Processors;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
use App\Classes\Modules\Orders\Services\CreatesOrder;
|
||||
use App\Classes\Modules\Orders\Standards\Rules\CanCreateOrder;
|
||||
use App\Classes\Modules\Orders\Processors\ConfirmOrderProcessor;
|
||||
use App\Classes\Modules\OrderSteps\Processors\CreateOrderStepsProcessor;
|
||||
use App\Classes\ValueObjects\Constants\OrderStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderSteps;
|
||||
@@ -17,26 +18,40 @@ class CreateOrderProcessor
|
||||
|
||||
private $createsOrder;
|
||||
|
||||
private $confirmOrderProcessor;
|
||||
|
||||
private $createOrderStepsProcessor;
|
||||
|
||||
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor)
|
||||
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor, ConfirmOrderProcessor $confirmOrderProcessor)
|
||||
{
|
||||
$this->canCreateOrder = $canCreateOrder;
|
||||
$this->createsOrder = $createsOrder;
|
||||
$this->confirmOrderProcessor = $confirmOrderProcessor;
|
||||
$this->createOrderStepsProcessor = $createOrderStepsProcessor;
|
||||
}
|
||||
|
||||
public function execute(Request $request){
|
||||
|
||||
$order_object = new OrderObject($request->get('company_module_id'), $request->get('reference'), '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
|
||||
$reference_no = rand(1000000, 9999999);
|
||||
|
||||
//TODO: Call Unity to create contract and get contract reference no (and all the obligations)
|
||||
//$contract_reference_no = 99;
|
||||
|
||||
$order_object = new OrderObject($request->get('company_module_id'), $reference_no, '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
|
||||
|
||||
$this->canCreateOrder->passes($order_object);
|
||||
|
||||
$order = $this->createsOrder->execute($order_object);
|
||||
|
||||
//Add processing to order step
|
||||
$this->createOrderStepsProcessor->execute($order, OrderSteps::PROCESSING);
|
||||
//Note: For processing apointee_id is CIEF Freight Forward , id is 1, reserved in company table
|
||||
$this->createOrderStepsProcessor->execute($order, OrderSteps::PROCESSING, 1);
|
||||
|
||||
//Pre-approved order, no need Admin to process it
|
||||
$this->confirmOrderProcessor->execute($order->id);
|
||||
|
||||
//TODO: Add order roles - Allow multiple entity to process this order
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\ControllersLogic;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackageItems\Services\CreatesPackageItem;
|
||||
use App\Classes\Modules\Orders\Services\FetchesOrder;
|
||||
use App\Classes\Modules\PackageItems\Standards\Rules\CanCreatePackageItem;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Packages\Services\FetchesPackage;
|
||||
use App\Http\Resources\PackageItemResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreatePackageItemLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created PackageItem',
|
||||
'message' => 'You have successfully created a new PackageItem'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreatePackageItem */
|
||||
private $canCreatePackageItem;
|
||||
|
||||
/** @var FetchesPackage */
|
||||
private $fetchesPackage;
|
||||
|
||||
/** @var CreatesPackageItem */
|
||||
private $createsPackageItem;
|
||||
|
||||
/**
|
||||
* CreatePackageItemLogic constructor.
|
||||
* @param CanCreatePackageItem $canCreatePackageItem
|
||||
* @param FetchesPackage $fetchesPackage
|
||||
* @param CreatesPackageItem $createsPackageItem
|
||||
*/
|
||||
public function __construct(CanCreatePackageItem $canCreatePackageItem, FetchesPackage $fetchesPackage, CreatesPackageItem $createsPackageItem)
|
||||
{
|
||||
$this->canCreatePackageItem = $canCreatePackageItem;
|
||||
$this->fetchesPackage = $fetchesPackage;
|
||||
$this->createsPackageItem = $createsPackageItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$package = $this->fetchesPackage->execute(['id' => $request->input('package_id')]);
|
||||
|
||||
$reference_no = rand(1000000, 9999999);
|
||||
|
||||
$object = new PackageItemObject(
|
||||
$package->id,
|
||||
$request->input('name'),
|
||||
$reference_no,
|
||||
$request->input('description'),
|
||||
$request->input('quantity'),
|
||||
$request->input('uom'),
|
||||
$request->input('price'),
|
||||
$request->input('total'),
|
||||
ApprovalStatus::PENDING_SUBMISSION);
|
||||
|
||||
$this->canCreatePackageItem->passes($object);
|
||||
|
||||
$query = $this->createsPackageItem->execute($object);
|
||||
|
||||
return $this->resourceResponse(new PackageItemResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackageItems\Services\DeletesPackageItem;
|
||||
use App\Classes\Modules\PackageItems\Services\FetchesPackageItem;
|
||||
use App\Classes\Modules\PackageItems\Standards\Rules\CanDeletePackageItem;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeletePackageItemLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Deleted PackageItem',
|
||||
'message' => 'You have successfully deleted a PackageItem'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CanDeletePackageItem */
|
||||
private $canDeletePackageItem;
|
||||
|
||||
/** @var DeletesPackageItem */
|
||||
private $deletesPackageItem;
|
||||
|
||||
/** @var FetchesPackageItem */
|
||||
private $fetchesPackageItem;
|
||||
|
||||
/**
|
||||
* DeletePackageItemControllersLogic constructor.
|
||||
* @param CanDeletePackageItem $canDeletePackageItem
|
||||
* @param DeletesPackageItem $deletesPackageItem
|
||||
* @param FetchesPackageItem $fetchesPackageItem
|
||||
*/
|
||||
public function __construct(CanDeletePackageItem $canDeletePackageItem, DeletesPackageItem $deletesPackageItem, FetchesPackageItem $fetchesPackageItem)
|
||||
{
|
||||
$this->canDeletePackageItem = $canDeletePackageItem;
|
||||
$this->deletesPackageItem = $deletesPackageItem;
|
||||
$this->fetchesPackageItem = $fetchesPackageItem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canDeletePackageItem->passes();
|
||||
|
||||
$query = $this->fetchesPackageItem->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesPackageItem->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackageItems\Services\FetchesPackageItem;
|
||||
use App\Classes\Modules\PackageItems\Standards\Rules\CanFetchPackageItem;
|
||||
use App\Http\Resources\PackageItemResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchPackageItemLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackageItem',
|
||||
'message' => 'You have successfully retrieved a PackageItem'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchPackageItem */
|
||||
private $canFetchPackageItem;
|
||||
|
||||
/** @var FetchesPackageItem */
|
||||
private $fetchesPackageItem;
|
||||
|
||||
/**
|
||||
* FetchPackageItemControllersLogic constructor.
|
||||
* @param CanFetchPackageItem $canFetchPackageItem
|
||||
* @param FetchesPackageItem $fetchesPackageItem
|
||||
*/
|
||||
public function __construct(CanFetchPackageItem $canFetchPackageItem, FetchesPackageItem $fetchesPackageItem)
|
||||
{
|
||||
$this->canFetchPackageItem = $canFetchPackageItem;
|
||||
$this->fetchesPackageItem = $fetchesPackageItem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchPackageItem->passes();
|
||||
|
||||
$query = $this->fetchesPackageItem->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new PackageItemResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackageItems\Services\ListsPackageItems;
|
||||
use App\Classes\Modules\PackageItems\Standards\Rules\CanListPackageItems;
|
||||
use App\Http\Resources\PackageItemResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListPackageItemsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackageItems',
|
||||
'message' => 'You have successfully retrieved a list of PackageItems'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackageItems */
|
||||
private $canListPackageItems;
|
||||
|
||||
/** @var ListsPackageItems */
|
||||
private $listsPackageItems;
|
||||
|
||||
/**
|
||||
* ListPackageItemsLogic constructor.
|
||||
* @param CanListPackageItems $canListPackageItems
|
||||
* @param ListsPackageItems $listsPackageItems
|
||||
*/
|
||||
public function __construct(CanListPackageItems $canListPackageItems, ListsPackageItems $listsPackageItems)
|
||||
{
|
||||
$this->canListPackageItems = $canListPackageItems;
|
||||
$this->listsPackageItems = $listsPackageItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canListPackageItems->passes();
|
||||
|
||||
$query = $this->listsPackageItems->execute($this->listsPackageItems->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(PackageItemResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackageItems\Services\UpdatesPackageItem;
|
||||
use App\Classes\Modules\PackageItems\Services\FetchesPackageItem;
|
||||
use App\Classes\Modules\PackageItems\Standards\Rules\CanUpdatePackageItem;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Http\Resources\PackageItemResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdatePackageItemLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated PackageItem',
|
||||
'message' => 'You have successfully updated the PackageItem'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdatePackageItem */
|
||||
private $canUpdatePackageItem;
|
||||
|
||||
/** @var UpdatesPackageItem */
|
||||
private $updatesPackageItem;
|
||||
|
||||
/** @var FetchesPackageItem */
|
||||
private $fetchesPackageItem;
|
||||
|
||||
/**
|
||||
* UpdatePackageItemLogic constructor.
|
||||
* @param CanUpdatePackageItem $canUpdatePackageItem
|
||||
* @param UpdatesPackageItem $updatesPackageItem
|
||||
* @param FetchesPackageItem $fetchesPackageItem
|
||||
*/
|
||||
public function __construct(CanUpdatePackageItem $canUpdatePackageItem, UpdatesPackageItem $updatesPackageItem, FetchesPackageItem $fetchesPackageItem)
|
||||
{
|
||||
$this->canUpdatePackageItem = $canUpdatePackageItem;
|
||||
$this->updatesPackageItem = $updatesPackageItem;
|
||||
$this->fetchesPackageItem = $fetchesPackageItem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$packageItem = $this->fetchesPackageItem->execute(['id' => $request->route('id')]);
|
||||
|
||||
$object = new PackageItemObject(
|
||||
$packageItem->package_id,
|
||||
$request->input('name'),
|
||||
$packageItem->reference,
|
||||
$request->input('description'),
|
||||
$request->input('quantity'),
|
||||
$request->input('uom'),
|
||||
$request->input('price'),
|
||||
$request->input('total'),
|
||||
$request->input('status'));
|
||||
|
||||
$this->canUpdatePackageItem->passes($object);
|
||||
|
||||
$query = $this->updatesPackageItem->execute($packageItem, $object);
|
||||
|
||||
return $this->resourceResponse(new PackageItemResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class PackageItemObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $packageId;
|
||||
|
||||
private $name;
|
||||
|
||||
private $reference;
|
||||
|
||||
private $description;
|
||||
|
||||
private $quantity;
|
||||
|
||||
private $uom;
|
||||
|
||||
private $price;
|
||||
|
||||
private $total;
|
||||
|
||||
private $status;
|
||||
|
||||
public function __construct(int $packageId, ?string $name, ?string $reference, ?string $description, int $quantity, ?string $uom, float $price, float $total, int $status)
|
||||
{
|
||||
$this->packageId = $packageId;
|
||||
$this->name = $name;
|
||||
$this->reference = $reference;
|
||||
$this->description = $description;
|
||||
$this->quantity = $quantity;
|
||||
$this->uom = $uom;
|
||||
$this->price = $price;
|
||||
$this->total = $total;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function getPackageId(): int
|
||||
{
|
||||
return $this->packageId;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function getQuantity(): int
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function getUom(): ?string
|
||||
{
|
||||
return $this->uom;
|
||||
}
|
||||
|
||||
public function getPrice(): float
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function getTotal(): float
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Models\PackageItem;
|
||||
|
||||
class CreatesPackageItem extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(PackageItemObject $object) {
|
||||
$model = new PackageItem();
|
||||
$model->package_id = $object->getPackageId();
|
||||
$model->name = $object->getName();
|
||||
$model->reference = $object->getReference();
|
||||
$model->description = $object->getDescription();
|
||||
$model->quantity = $object->getQuantity();
|
||||
$model->uom = $object->getUom();
|
||||
$model->price = $object->getPrice();
|
||||
$model->total = $object->getTotal();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\PackageItem;
|
||||
|
||||
class DeletesPackageItem extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PackageItem $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackageItem $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\PackageItem;
|
||||
|
||||
class FetchesPackageItem extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var PackageItem */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesPackageItem constructor.
|
||||
* @param PackageItem $repository
|
||||
*/
|
||||
public function __construct(PackageItem $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\PackageItem;
|
||||
|
||||
class ListsPackageItems extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var PackageItem */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsPackageItems constructor.
|
||||
* @param PackageItem $repository
|
||||
*/
|
||||
public function __construct(PackageItem $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Models\PackageItem;
|
||||
|
||||
class UpdatesPackageItem extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(PackageItem $model, PackageItemObject $object) {
|
||||
|
||||
$model->name = $object->getName();
|
||||
$model->reference = $object->getReference();
|
||||
$model->description = $object->getDescription();
|
||||
$model->quantity = $object->getQuantity();
|
||||
$model->uom = $object->getUom();
|
||||
$model->price = $object->getPrice();
|
||||
$model->total = $object->getTotal();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Classes\Modules\PackageItems\Standards\Validators\PackageItemValidation;
|
||||
|
||||
class CanCreatePackageItem extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackageItemValidation */
|
||||
private $packageItemValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackageItem 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 PackageItemObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->packageItemValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
|
||||
class CanDeletePackageItem extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
|
||||
class CanFetchPackageItem extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
|
||||
class CanListPackageItems extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
use App\Classes\Modules\PackageItems\Standards\Validators\PackageItemValidation;
|
||||
|
||||
class CanUpdatePackageItem extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackageItemValidation */
|
||||
private $PackageItemValidation;
|
||||
|
||||
/**
|
||||
* CanUpdatePackageItem 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 PackageItemObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->PackageItemValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackageItems\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\PackageItems\DataTransferObjects\PackageItemObject;
|
||||
|
||||
class PackageItemValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageItemObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'package_id' => $object->getPackageId(),
|
||||
'name' => $object->getName(),
|
||||
'reference' => $object->getReference(),
|
||||
'description' => $object->getDescription(),
|
||||
'quantity' => $object->getQuantity(),
|
||||
'uom' => $object->getUom(),
|
||||
'price' => $object->getPrice(),
|
||||
'total' => $object->getTotal(),
|
||||
'status' => $object->getStatus(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'package_id' => 'required',
|
||||
'name' => 'required',
|
||||
'reference' => 'required',
|
||||
'quantity' => 'required',
|
||||
'price' => 'required',
|
||||
'total' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\ControllersLogic;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
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 FetchesOrder */
|
||||
private $fetchesOrder;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CreatesPackage */
|
||||
private $createsPackage;
|
||||
|
||||
/**
|
||||
* CreatePackageLogic constructor.
|
||||
* @param CanCreatePackage $canCreatePackage
|
||||
* @param FetchesOrder $fetchesOrder
|
||||
* @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('description'),
|
||||
$request->input('width'),
|
||||
$request->input('height'),
|
||||
$request->input('length'),
|
||||
$request->input('weight'),
|
||||
$request->input('quantity'),
|
||||
ApprovalStatus::PENDING_SUBMISSION);
|
||||
|
||||
$this->canCreatePackage->passes($object);
|
||||
|
||||
$query = $this->createsPackage->execute($object);
|
||||
|
||||
return $this->resourceResponse(new PackageResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Packages\Services\DeletesPackage;
|
||||
use App\Classes\Modules\Packages\Services\FetchesPackage;
|
||||
use App\Classes\Modules\Packages\Standards\Rules\CanDeletePackage;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeletePackageLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Deleted Package',
|
||||
'message' => 'You have successfully deleted a Package'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CanDeletePackage */
|
||||
private $canDeletePackage;
|
||||
|
||||
/** @var DeletesPackage */
|
||||
private $deletesPackage;
|
||||
|
||||
/** @var FetchesPackage */
|
||||
private $fetchesPackage;
|
||||
|
||||
/**
|
||||
* DeletePackageControllersLogic constructor.
|
||||
* @param CanDeletePackage $canDeletePackage
|
||||
* @param DeletesPackage $deletesPackage
|
||||
* @param FetchesPackage $fetchesPackage
|
||||
*/
|
||||
public function __construct(CanDeletePackage $canDeletePackage, DeletesPackage $deletesPackage, FetchesPackage $fetchesPackage)
|
||||
{
|
||||
$this->canDeletePackage = $canDeletePackage;
|
||||
$this->deletesPackage = $deletesPackage;
|
||||
$this->fetchesPackage = $fetchesPackage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canDeletePackage->passes();
|
||||
|
||||
$query = $this->fetchesPackage->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesPackage->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Packages\Services\FetchesPackage;
|
||||
use App\Classes\Modules\Packages\Standards\Rules\CanFetchPackage;
|
||||
use App\Http\Resources\PackageResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchPackageLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Package',
|
||||
'message' => 'You have successfully retrieved a Package'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchPackage */
|
||||
private $canFetchPackage;
|
||||
|
||||
/** @var FetchesPackage */
|
||||
private $fetchesPackage;
|
||||
|
||||
/**
|
||||
* FetchPackageControllersLogic constructor.
|
||||
* @param CanFetchPackage $canFetchPackage
|
||||
* @param FetchesPackage $fetchesPackage
|
||||
*/
|
||||
public function __construct(CanFetchPackage $canFetchPackage, FetchesPackage $fetchesPackage)
|
||||
{
|
||||
$this->canFetchPackage = $canFetchPackage;
|
||||
$this->fetchesPackage = $fetchesPackage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchPackage->passes();
|
||||
|
||||
$query = $this->fetchesPackage->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new PackageResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Packages\Services\ListsPackages;
|
||||
use App\Classes\Modules\Packages\Standards\Rules\CanListPackages;
|
||||
use App\Http\Resources\PackageResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListPackagesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Packages',
|
||||
'message' => 'You have successfully retrieved a list of Packages'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackages */
|
||||
private $canListPackages;
|
||||
|
||||
/** @var ListsPackages */
|
||||
private $listsPackages;
|
||||
|
||||
/**
|
||||
* ListPackagesLogic constructor.
|
||||
* @param CanListPackages $canListPackages
|
||||
* @param ListsPackages $listsPackages
|
||||
*/
|
||||
public function __construct(CanListPackages $canListPackages, ListsPackages $listsPackages)
|
||||
{
|
||||
$this->canListPackages = $canListPackages;
|
||||
$this->listsPackages = $listsPackages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canListPackages->passes();
|
||||
|
||||
$query = $this->listsPackages->execute($this->listsPackages->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(PackageResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Packages\Services\UpdatesPackage;
|
||||
use App\Classes\Modules\Packages\Services\FetchesPackage;
|
||||
use App\Classes\Modules\Packages\Standards\Rules\CanUpdatePackage;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
use App\Http\Resources\PackageResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdatePackageLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Package',
|
||||
'message' => 'You have successfully updated the Package'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdatePackage */
|
||||
private $canUpdatePackage;
|
||||
|
||||
/** @var UpdatesPackage */
|
||||
private $updatesPackage;
|
||||
|
||||
/** @var FetchesPackage */
|
||||
private $fetchesPackage;
|
||||
|
||||
|
||||
/**
|
||||
* UpdatePackageLogic constructor.
|
||||
* @param CanUpdatePackage $canUpdatePackage
|
||||
* @param UpdatesPackage $updatesPackage
|
||||
* @param FetchesPackage $fetchesPackage
|
||||
*/
|
||||
public function __construct(CanUpdatePackage $canUpdatePackage, UpdatesPackage $updatesPackage, FetchesPackage $fetchesPackage)
|
||||
{
|
||||
$this->canUpdatePackage = $canUpdatePackage;
|
||||
$this->updatesPackage = $updatesPackage;
|
||||
$this->fetchesPackage = $fetchesPackage;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$package = $this->fetchesPackage->execute(['id' => $request->route('id')]);
|
||||
|
||||
$object = new PackageObject(
|
||||
$package->order_id,
|
||||
null,
|
||||
$request->input('type'),
|
||||
$request->input('description'),
|
||||
$request->input('width'),
|
||||
$request->input('height'),
|
||||
$request->input('length'),
|
||||
$request->input('weight'),
|
||||
$request->input('quantity'),
|
||||
$request->input('status'));
|
||||
|
||||
$this->canUpdatePackage->passes($object);
|
||||
|
||||
$query = $this->updatesPackage->execute($package, $object);
|
||||
|
||||
return $this->resourceResponse(new PackageResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class PackageObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $orderId;
|
||||
|
||||
private $claimantId;
|
||||
|
||||
private $type;
|
||||
|
||||
private $description;
|
||||
|
||||
private $width;
|
||||
|
||||
private $height;
|
||||
|
||||
private $length;
|
||||
|
||||
private $weight;
|
||||
|
||||
private $quantity;
|
||||
|
||||
private $status;
|
||||
|
||||
public function __construct(int $orderId, ?int $claimantId, int $type, ?string $description, float $width, float $height, float $length, float $weight, int $quantity, int $status)
|
||||
{
|
||||
$this->orderId = $orderId;
|
||||
$this->claimantId = $claimantId;
|
||||
$this->type = $type;
|
||||
$this->description = $description;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->length = $length;
|
||||
$this->weight = $weight;
|
||||
$this->quantity = $quantity;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function getOrderId(): int
|
||||
{
|
||||
return $this->orderId;
|
||||
}
|
||||
|
||||
public function getClaimantId(): ?int
|
||||
{
|
||||
return $this->claimantId;
|
||||
}
|
||||
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function getWidth(): float
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function getHeight(): float
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function getLength(): float
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
public function getWeight(): float
|
||||
{
|
||||
return $this->weight;
|
||||
}
|
||||
|
||||
public function getQuantity(): int
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
use App\Models\Package;
|
||||
|
||||
class CreatesPackage extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(PackageObject $object) {
|
||||
$model = new Package();
|
||||
$model->order_id = $object->getOrderId();
|
||||
$model->claimant_id = $object->getClaimantId();
|
||||
$model->type = $object->getType();
|
||||
$model->description = $object->getDescription();
|
||||
$model->width = $object->getWidth();
|
||||
$model->height = $object->getHeight();
|
||||
$model->length = $object->getLength();
|
||||
$model->weight = $object->getWeight();
|
||||
$model->quantity = $object->getQuantity();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Package;
|
||||
|
||||
class DeletesPackage extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Package $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Package $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Package;
|
||||
|
||||
class FetchesPackage extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Package */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesPackage constructor.
|
||||
* @param Package $repository
|
||||
*/
|
||||
public function __construct(Package $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Package;
|
||||
|
||||
class ListsPackages extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var Package */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsPackages constructor.
|
||||
* @param Package $repository
|
||||
*/
|
||||
public function __construct(Package $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
use App\Models\Package;
|
||||
|
||||
class UpdatesPackage extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(Package $model, PackageObject $object) {
|
||||
|
||||
$model->claimant_id = $object->getClaimantId();
|
||||
$model->type = $object->getType();
|
||||
$model->description = $object->getDescription();
|
||||
$model->width = $object->getWidth();
|
||||
$model->height = $object->getHeight();
|
||||
$model->length = $object->getLength();
|
||||
$model->weight = $object->getWeight();
|
||||
$model->quantity = $object->getQuantity();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
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\PackageValidation;
|
||||
|
||||
class CanCreatePackage extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackageValidation */
|
||||
private $PackageValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackage constructor.
|
||||
* @param PackageValidation $PackageValidation
|
||||
*/
|
||||
public function __construct(PackageValidation $PackageValidation)
|
||||
{
|
||||
$this->PackageValidation = $PackageValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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->PackageValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
|
||||
class CanDeletePackage extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
|
||||
class CanFetchPackage extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Packages\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Packages\DataTransferObjects\PackageObject;
|
||||
|
||||
class CanListPackages extends AbstractRule
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackageObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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\PackageValidation;
|
||||
|
||||
class CanUpdatePackage extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackageValidation */
|
||||
private $PackageValidation;
|
||||
|
||||
/**
|
||||
* CanUpdatePackage constructor.
|
||||
* @param PackageValidation $PackageValidation
|
||||
*/
|
||||
public function __construct(PackageValidation $PackageValidation)
|
||||
{
|
||||
$this->PackageValidation = $PackageValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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->PackageValidation->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 [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\CreatesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Services\CreatesPackingListPackage;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingListPackage;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListPackageObject;
|
||||
use App\Classes\Modules\Packages\Services\FetchesPackage;
|
||||
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;
|
||||
|
||||
private $canCreatePackingListPackage;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesPackage;
|
||||
|
||||
/** @var CreatesPackingList */
|
||||
private $createsPackingList;
|
||||
|
||||
private $createsPackingListPackage;
|
||||
|
||||
/**
|
||||
* CreatePackingListLogic constructor.
|
||||
* @param CanCreatePackingList $canCreatePackingList
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesPackingList $createsPackingList
|
||||
*/
|
||||
public function __construct(CanCreatePackingList $canCreatePackingList, CanCreatePackingListPackage $canCreatePackingListPackage, FetchesPackage $fetchesPackage, CreatesPackingList $createsPackingList, CreatesPackingListPackage $createsPackingListPackage)
|
||||
{
|
||||
$this->canCreatePackingList = $canCreatePackingList;
|
||||
$this->canCreatePackingListPackage = $canCreatePackingListPackage;
|
||||
$this->fetchesPackage = $fetchesPackage;
|
||||
$this->createsPackingList = $createsPackingList;
|
||||
$this->createsPackingListPackage = $createsPackingListPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
||||
$package = $this->fetchesPackage->execute(['id'=>$request->input('package_id')]);
|
||||
|
||||
$reference_no = rand(1000000, 9999999);
|
||||
|
||||
|
||||
$object = new PackingListObject($reference_no, ApprovalStatus::PENDING_SUBMISSION);
|
||||
|
||||
$this->canCreatePackingList->passes($object);
|
||||
|
||||
$packageList = $this->createsPackingList->execute( $object);
|
||||
|
||||
|
||||
$object = new PackingListPackageObject($packageList->id, $package->id);
|
||||
|
||||
$this->canCreatePackingListPackage->passes($object);
|
||||
|
||||
$query = $this->createsPackingListPackage->execute($object);
|
||||
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\DeletesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanDeletePackingList;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeletePackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Deleted PackingList',
|
||||
'message' => 'You have successfully deleted a PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var CanDeletePackingList */
|
||||
private $canDeletePackingList;
|
||||
|
||||
/** @var DeletesPackingList */
|
||||
private $deletesPackingList;
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/**
|
||||
* DeletePackingListControllersLogic constructor.
|
||||
* @param CanDeletePackingList $canDeletePackingList
|
||||
* @param DeletesPackingList $deletesPackingList
|
||||
* @param FetchesPackingList $fetchesPackingList
|
||||
*/
|
||||
public function __construct(CanDeletePackingList $canDeletePackingList, DeletesPackingList $deletesPackingList, FetchesPackingList $fetchesPackingList)
|
||||
{
|
||||
$this->canDeletePackingList = $canDeletePackingList;
|
||||
$this->deletesPackingList = $deletesPackingList;
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canDeletePackingList->passes();
|
||||
|
||||
$query = $this->fetchesPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesPackingList->execute($query);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanFetchPackingList;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchPackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingList',
|
||||
'message' => 'You have successfully retrieved a PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchPackingList */
|
||||
private $canFetchPackingList;
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/**
|
||||
* FetchPackingListControllersLogic constructor.
|
||||
* @param CanFetchPackingList $canFetchPackingList
|
||||
* @param FetchesPackingList $fetchesPackingList
|
||||
*/
|
||||
public function __construct(CanFetchPackingList $canFetchPackingList, FetchesPackingList $fetchesPackingList)
|
||||
{
|
||||
$this->canFetchPackingList = $canFetchPackingList;
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canFetchPackingList->passes();
|
||||
|
||||
$query = $this->fetchesPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListPackingListsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingLists',
|
||||
'message' => 'You have successfully retrieved a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListPackingLists */
|
||||
private $canListPackingLists;
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsLogic constructor.
|
||||
* @param CanListPackingLists $canListPackingLists
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
*/
|
||||
public function __construct(CanListPackingLists $canListPackingLists, ListsPackingLists $listsPackingLists)
|
||||
{
|
||||
$this->canListPackingLists = $canListPackingLists;
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$this->canListPackingLists->passes();
|
||||
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\UpdatesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanUpdatePackingList;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdatePackingListLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated PackingList',
|
||||
'message' => 'You have successfully updated the PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdatePackingList */
|
||||
private $canUpdatePackingList;
|
||||
|
||||
/** @var UpdatesPackingList */
|
||||
private $updatesPackingList;
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/**
|
||||
* UpdatePackingListLogic constructor.
|
||||
* @param CanUpdatePackingList $canUpdatePackingList
|
||||
* @param UpdatesPackingList $updatesPackingList
|
||||
* @param FetchesPackingList $fetchesPackingList
|
||||
*/
|
||||
public function __construct(CanUpdatePackingList $canUpdatePackingList, UpdatesPackingList $updatesPackingList, FetchesPackingList $fetchesPackingList)
|
||||
{
|
||||
$this->canUpdatePackingList = $canUpdatePackingList;
|
||||
$this->updatesPackingList = $updatesPackingList;
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$packingList = $this->fetchesPackingList->execute(['id' => $request->route('id')]);
|
||||
|
||||
$object = new PackingListObject($packingList->reference, $request->input('status'));
|
||||
|
||||
$this->canUpdatePackingList->passes($object);
|
||||
|
||||
$query = $this->updatesPackingList->execute($packingList, $object);
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class PackingListObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $reference;
|
||||
|
||||
private $status;
|
||||
|
||||
public function __construct(?string $reference, int $status)
|
||||
{
|
||||
$this->reference = $reference;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class PackingListPackageObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $packingListId;
|
||||
|
||||
private $packageId;
|
||||
|
||||
public function __construct(int $packingListId, int $packageId)
|
||||
{
|
||||
$this->packingListId = $packingListId;
|
||||
$this->packageId = $packageId;
|
||||
}
|
||||
|
||||
public function getPackingListId(): int
|
||||
{
|
||||
return $this->packingListId;
|
||||
}
|
||||
|
||||
public function getPackageId(): int
|
||||
{
|
||||
return $this->packageId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class CreatesPackingList extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(PackingListObject $object) {
|
||||
$model = new PackingList();
|
||||
|
||||
$model->reference = $object->getReference();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListPackageObject;
|
||||
use App\Models\PackingListPackage;
|
||||
|
||||
class CreatesPackingListPackage extends AbstractUpdateRecord
|
||||
{
|
||||
public function execute(PackingListPackageObject $object) {
|
||||
$model = new PackingListPackage();
|
||||
|
||||
$model->packing_list_id = $object->getPackingListId();
|
||||
$model->package_id = $object->getPackageId();
|
||||
|
||||
return $this->handler( $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class DeletesPackingList extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PackingList $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class FetchesPackingList extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var PackingList */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesPackingList constructor.
|
||||
* @param PackingList $repository
|
||||
*/
|
||||
public function __construct(PackingList $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class ListsPackingLists extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var PackingList */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsPackingLists constructor.
|
||||
* @param PackingList $repository
|
||||
*/
|
||||
public function __construct(PackingList $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Models\PackingList;
|
||||
|
||||
class UpdatesPackingList extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param PackingList $model
|
||||
* @param PackingListObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $model, PackingListObject $object) {
|
||||
|
||||
$model->reference = $object->getReference();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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\PackingListValidation;
|
||||
|
||||
class CanCreatePackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var PackingListValidation */
|
||||
private $packingListValidation;
|
||||
|
||||
/**
|
||||
* CanCreatePackingList constructor.
|
||||
* @param PackingListValidation $packingListValidation
|
||||
*/
|
||||
public function __construct(PackingListValidation $packingListValidation)
|
||||
{
|
||||
$this->packingListValidation = $packingListValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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->packingListValidation->validate($object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param PackingListObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user