mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
new: assign segment to company created. #1
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use App\Classes\Modules\Companies\Services\AssignsCompanyToSegment;
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanAssignSegment;
|
||||
use App\Classes\Modules\Segments\Services\FetchesSegment;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AssignSegmentProcessor
|
||||
{
|
||||
|
||||
/** @var CanAssignSegment */
|
||||
private $canAssignSegment;
|
||||
|
||||
/** @var AssignsCompanyToSegment */
|
||||
private $assignsSegment;
|
||||
|
||||
/** @var FetchesSegment */
|
||||
private $fetchesSegment;
|
||||
|
||||
/**
|
||||
* AssignCompanyToSegmentProcessor constructor.
|
||||
* @param CanAssignSegment $canAssignSegment
|
||||
* @param AssignsCompanyToSegment $assignsSegment
|
||||
* @param FetchesSegment $fetchesSegment
|
||||
*/
|
||||
public function __construct(CanAssignSegment $canAssignSegment, AssignsCompanyToSegment $assignsSegment, FetchesSegment $fetchesSegment)
|
||||
{
|
||||
$this->canAssignSegment = $canAssignSegment;
|
||||
$this->assignsSegment = $assignsSegment;
|
||||
$this->fetchesSegment = $fetchesSegment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param int|null $segmentId
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Company $company, ?int $segmentId = SegmentConstants::STANDARD_SEGMENT): Model {
|
||||
|
||||
$segment = $this->fetchesSegment->execute(['id' => $segmentId]);
|
||||
|
||||
$this->canAssignSegment->passes();
|
||||
|
||||
return $this->assignsSegment->execute($company, $segment);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Company;
|
||||
use App\Models\Segment;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class AssignsCompanyToSegment extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param Segment $segment
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, Segment $segment)
|
||||
{
|
||||
try {
|
||||
|
||||
$company->segments()->attach($segment);
|
||||
|
||||
return $company;
|
||||
|
||||
} catch (QueryException $exception){
|
||||
throw new MalformedRequestException($exception);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\SegmentConstants\DataTransferObjects\SegmentConstantObject;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\ConstantObject;
|
||||
|
||||
class CanAssignSegment extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConstantObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ConstantObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var string */
|
||||
private $reference;
|
||||
|
||||
/** @var array */
|
||||
private $detail;
|
||||
|
||||
/**
|
||||
* ConstantObject constructor.
|
||||
* @param string $name
|
||||
* @param string $reference
|
||||
* @param array $detail
|
||||
*/
|
||||
public function __construct(string $name, string $reference, array $detail)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->reference = $reference;
|
||||
$this->detail = $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReference(): string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDetail(): array
|
||||
{
|
||||
return $this->detail;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Segments\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Segment;
|
||||
|
||||
class FetchesSegment extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Segment */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesSegment constructor.
|
||||
* @param Segment $repository
|
||||
*/
|
||||
public function __construct(Segment $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\ServiceTypes\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\Modules\ServiceTypes\Services\FetchesServiceCurrenciesConfigurations;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Models\ServiceType;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ServiceConfigurationsObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var ServiceType */
|
||||
private $service;
|
||||
|
||||
/** @var SegmentConstant */
|
||||
private $configurations;
|
||||
|
||||
/** @var Collection */
|
||||
private $customOptions;
|
||||
|
||||
/**
|
||||
* ServiceConfigurationsObject constructor.
|
||||
* @param ServiceType $service
|
||||
* @param SegmentConstant $configurations
|
||||
* @param Collection $customOptions
|
||||
*/
|
||||
public function __construct(ServiceType $service, SegmentConstant $configurations, Collection $customOptions)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->configurations = $configurations;
|
||||
$this->customOptions = $customOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ServiceType
|
||||
*/
|
||||
public function getService(): ServiceType
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return SegmentConstant
|
||||
*/
|
||||
public function getConfigurations(): SegmentConstant
|
||||
{
|
||||
return $this->configurations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCustomOptions(): Collection
|
||||
{
|
||||
return $this->customOptions->map(function($value){
|
||||
return new CustomConfigurationsObject($this->getConfigurations(), $value);
|
||||
});
|
||||
}
|
||||
|
||||
public function getBaseCurrencyRates(){
|
||||
return (App()->make(FetchesServiceCurrenciesConfigurations::class))->execute($this->configurations, SegmentConstants::SERVICE_TYPE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
|
||||
class SegmentConstants
|
||||
{
|
||||
|
||||
public const STANDARD_SEGMENT = 1;
|
||||
|
||||
public const CUSTOM_SEGMENT = 2;
|
||||
|
||||
public const SYSTEM_PRIMARY_CURRENCY = 'SYSTEM_PRIMARY_CURRENCY';
|
||||
|
||||
public const SUPPLIER_CURRENCIES = 'SUPPLIER_CURRENCIES';
|
||||
|
||||
public const PAYMENT_ATTEMPT_DURATION_LIMIT = 'PAYMENT_ATTEMPT_DURATION_LIMIT';
|
||||
|
||||
public const SERVICE_TYPE = 'SERVICE_TYPE';
|
||||
|
||||
public const CUSTOM_SERVICE_TYPE = 'CUSTOM_SERVICE_TYPE';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* Class CompanyEmployee
|
||||
* @package App\Models
|
||||
*
|
||||
* @property \App\Models\Company company_id
|
||||
* @property \App\Models\User user_id
|
||||
*/
|
||||
class Employee extends AbstractModel
|
||||
{
|
||||
protected $table = 'employees';
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
public function company(): HasMany
|
||||
{
|
||||
return $this->HasMany(Company::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
**/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Class Segment
|
||||
* @package App\Models
|
||||
*
|
||||
* @property string name
|
||||
* @property string reference
|
||||
*/
|
||||
class Segment extends AbstractModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'segments';
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
public function constants(): HasMany
|
||||
{
|
||||
return $this->HasMany(SegmentConstant::class, 'segment_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user