mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
WIP - Order steps & remaining APIs
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
use App\Classes\Modules\Unity\Processors\CreateEntityProcessor;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
|
||||
use App\Classes\Modules\Companies\Processors\CreateCompanyModuleProcessor;
|
||||
@@ -16,8 +15,6 @@ use Illuminate\Http\Request;
|
||||
class CreateCompanyLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
private $createUnityEntityProcessor;
|
||||
|
||||
/**
|
||||
* CreateCompanyLogic constructor.
|
||||
* @param CreateCompanyProcessor $createCompanyProcessor
|
||||
@@ -57,11 +54,6 @@ class CreateCompanyLogic extends AbstractControllerLogic
|
||||
|
||||
$this->createCompanyModuleProcessor->execute($company , $request->input('business_type'));
|
||||
|
||||
$unityEntity = $this->createUnityEntityProcessor->execute($company->name);
|
||||
|
||||
//$company->unity_hash_id = $unityEntity->hash_id;
|
||||
//Update company table
|
||||
|
||||
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()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\GetContractObligations;
|
||||
|
||||
class CreateContractProcessor
|
||||
{
|
||||
private $getContractObligations;
|
||||
|
||||
public function __construct(GetContractObligations $getContractObligations)
|
||||
{
|
||||
$this->getContractObligations = $getContractObligations;
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
return $this->getContractObligations->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\GetContractObligations;
|
||||
|
||||
class UpdateObligationsProcessor
|
||||
{
|
||||
private $getContractObligations;
|
||||
|
||||
public function __construct(GetContractObligations $getContractObligations)
|
||||
{
|
||||
$this->getContractObligations = $getContractObligations;
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
return $this->getContractObligations->execute();
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class GetAccessToken
|
||||
$accesToken='';
|
||||
if($this->unityConfig['default_auth']=='login'){
|
||||
$loginDetails = $this->unityConfig['auth']['login'];
|
||||
$response = Http::post($this->unityConfig['url'].$loginDetails['endpoint'], [
|
||||
$response = Http::post($this->unityConfig['url'].$this->unityConfig['endpoint']['login'], [
|
||||
'email' => $loginDetails['username'],
|
||||
'password' => $loginDetails['password'],
|
||||
])->object();
|
||||
|
||||
+12
-10
@@ -7,6 +7,16 @@ return [
|
||||
|
||||
'url' => env('UNITY_API_URL', 'https://dev.unity.izyim.com/user-backsys/api/'),
|
||||
|
||||
'endpoint' => [
|
||||
'login' => env('UNITY_LOGIN_ENDPOINT','login'),
|
||||
'create_entity' => env('UNITY_CREATE_ENTITY_ENDPOINT','entity/store'),
|
||||
'get_contract_obligations' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
|
||||
'create_contract' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
|
||||
'update_obligation_status' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
|
||||
],
|
||||
|
||||
'default_auth' => env('UNITY_AUTH','login'),
|
||||
|
||||
'auth' => [
|
||||
|
||||
'api_key' => [
|
||||
@@ -16,7 +26,6 @@ return [
|
||||
'login' => [
|
||||
'username' => env('UNITY_LOGIN_USERNAME','one@izyim.com'),
|
||||
'password' => env('UNITY_LOGIN_PASSWORD','pass123'),
|
||||
'endpoint' => env('UNITY_LOGIN_ENDPOINT','login')
|
||||
],
|
||||
|
||||
],
|
||||
@@ -25,20 +34,13 @@ return [
|
||||
|
||||
'create_entity_endpoint' => env('UNITY_CREATE_ENTITY_ENDPOINT','entity/store'),
|
||||
|
||||
'default_auth' => env('UNITY_AUTH','login'),
|
||||
|
||||
'on_error_email' => env('UNITY_ON_ERROR_EMAIL','dev@shipping.com,dev@unity.com'),
|
||||
|
||||
'contract_template_id' => env('UNITY_CONTRACT_TEMPLATE_ID', 102),
|
||||
|
||||
'contract_template_cache' => env('UNITY_CONTRACT_TEMPLATE_CACHE','60'),
|
||||
'contract_template_hash_id' => env('UNITY_CONTRACT_TEMPLATE_HASH_ID', '5lpn70mA2VmgxoekgYrJ'),
|
||||
|
||||
'entities' => [
|
||||
'xxx_key' => Constant\OrderEntity::SUPPLIER,
|
||||
'zzz_key' => Constant\OrderEntity::WAREHOUSE_YIWU,
|
||||
'vvv_key' => Constant\OrderEntity::WAREHOUSE_GUANG_ZHOU,
|
||||
'wwww_key' => Constant\OrderEntity::SUPPLIER,
|
||||
],
|
||||
'contract_template_cache' => env('UNITY_CONTRACT_TEMPLATE_CACHE','60'),
|
||||
|
||||
'obligations' => [
|
||||
'PACKING' => Constant\OrderSteps::PACKING,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ModifyCompanyTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('company_modules', function (Blueprint $table) {
|
||||
$table->string('unity_hash_id',200)->nullable()->after('status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user