mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
large commit
This commit is contained in:
@@ -3,16 +3,18 @@
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\CreatesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateAddressLogic extends AbstractControllersLogic
|
||||
class CreateAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -28,41 +30,49 @@ class CreateAddressLogic extends AbstractControllersLogic
|
||||
/** @var CanCreateAddress */
|
||||
private $canCreateAddress;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CreatesAddress */
|
||||
private $createsAddress;
|
||||
|
||||
/**
|
||||
* CreateAddressControllersLogic constructor.
|
||||
* CreateAddressLogic constructor.
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesAddress $createsAddress
|
||||
*/
|
||||
public function __construct(CanCreateAddress $canCreateAddress, CreatesAddress $createsAddress)
|
||||
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress)
|
||||
{
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsAddress = $createsAddress;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$object = new AddressObject($request->input('company_id'), $request->input('street_one'), $request->input('street_two'), $request->input('city'), $request->input('state'), $request->input('post_code'), $request->input('country'), $request->input('default'), $request->input('billing'));
|
||||
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
||||
|
||||
$this->canCreateAddress->passes($object);
|
||||
$object = new AddressObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
||||
|
||||
$query = $this->createsAddress->execute($object);
|
||||
$this->canCreateAddress->passes($object);
|
||||
|
||||
return $this->resourceResponse(new AddressResource($query));
|
||||
$query = $this->createsAddress->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
return $this->resourceResponse(new AddressResource($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\DeletesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanDeleteAddress;
|
||||
@@ -11,7 +11,7 @@ use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteAddressLogic extends AbstractControllersLogic
|
||||
class DeleteAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanFetchAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchAddressLogic extends AbstractControllersLogic
|
||||
class FetchAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\ListsAddresses;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
|
||||
use App\Http\Resources\AddressResource;
|
||||
@@ -11,7 +11,7 @@ use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListAddressesLogic extends AbstractControllersLogic
|
||||
class ListAddressesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\ListsAddresses;
|
||||
use App\Classes\Modules\Addresses\Services\ListsDistricts;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Http\Resources\DistrictResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListDistrictsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Addresses',
|
||||
'message' => 'You have successfully retrieved a list of Addresses'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsDistricts */
|
||||
private $listDistricts;
|
||||
|
||||
/**
|
||||
* ListDistrictsLogic constructor.
|
||||
* @param ListsDistricts $listDistricts
|
||||
*/
|
||||
public function __construct(ListsDistricts $listDistricts)
|
||||
{
|
||||
$this->listDistricts = $listDistricts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listDistricts->execute($this->listDistricts->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(DistrictResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\UpdatesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanUpdateAddress;
|
||||
@@ -13,7 +13,7 @@ use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateAddressLogic extends AbstractControllersLogic
|
||||
class UpdateAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,69 +2,46 @@
|
||||
|
||||
namespace App\Classes\Modules\Addresses\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class AddressObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $companyId;
|
||||
|
||||
/** @var string */
|
||||
private $streetOne;
|
||||
|
||||
/** @var string|null */
|
||||
private $streetTwo;
|
||||
|
||||
/** @var string */
|
||||
private $city;
|
||||
/** @var int */
|
||||
private $countryId;
|
||||
|
||||
/** @var string */
|
||||
private $state;
|
||||
/** @var int */
|
||||
private $stateId;
|
||||
|
||||
/** @var string */
|
||||
/** @var int */
|
||||
private $districtId;
|
||||
|
||||
/** @var int */
|
||||
private $postCode;
|
||||
|
||||
/** @var string */
|
||||
private $country;
|
||||
|
||||
/** @var int */
|
||||
private $default;
|
||||
|
||||
/** @var int */
|
||||
private $billing;
|
||||
|
||||
/**
|
||||
* AddressObject constructor.
|
||||
* @param int $companyId
|
||||
* @param string $streetOne
|
||||
* @param null|string $streetTwo
|
||||
* @param string $city
|
||||
* @param string $state
|
||||
* @param string $postCode
|
||||
* @param string $country
|
||||
* @param int $default
|
||||
* @param int $billing
|
||||
* @param int $countryId
|
||||
* @param int $stateId
|
||||
* @param int $districtId
|
||||
* @param int $postCode
|
||||
*/
|
||||
public function __construct(int $companyId, string $streetOne, ?string $streetTwo, string $city, string $state, string $postCode, string $country, int $default, int $billing)
|
||||
public function __construct(string $streetOne, ?string $streetTwo, int $countryId, int $stateId, int $districtId, int $postCode)
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->streetOne = $streetOne;
|
||||
$this->streetTwo = $streetTwo;
|
||||
$this->city = $city;
|
||||
$this->state = $state;
|
||||
$this->countryId = $countryId;
|
||||
$this->stateId = $stateId;
|
||||
$this->districtId = $districtId;
|
||||
$this->postCode = $postCode;
|
||||
$this->country = $country;
|
||||
$this->default = $default;
|
||||
$this->billing = $billing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): int
|
||||
{
|
||||
return $this->companyId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,52 +61,36 @@ class AddressObject implements DataTransferObject
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getCity(): string
|
||||
public function getCountryId(): int
|
||||
{
|
||||
return $this->city;
|
||||
return $this->countryId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getState(): string
|
||||
public function getStateId(): int
|
||||
{
|
||||
return $this->state;
|
||||
return $this->stateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getPostCode(): string
|
||||
public function getDistrictId(): int
|
||||
{
|
||||
return $this->districtId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPostCode(): int
|
||||
{
|
||||
return $this->postCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCountry(): string
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDefault(): int
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBilling(): int
|
||||
{
|
||||
return $this->billing;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,30 +3,30 @@
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Models\Address;
|
||||
use App\Models\Company;
|
||||
|
||||
class CreatesAddress extends AbstractUpdateRecord
|
||||
class CreatesAddress extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param AddressObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(AddressObject $object) {
|
||||
public function execute(Company $company, AddressObject $object) {
|
||||
$model = new Address();
|
||||
$model->company_id = $object->getCompanyId();
|
||||
$model->street_one = $object->getStreetOne();
|
||||
$model->street_two = $object->getStreetTwo();
|
||||
$model->city = $object->getCity();
|
||||
$model->state = $object->getState();
|
||||
$model->post_code = $object->getPostCode();
|
||||
$model->country = $object->getCountry();
|
||||
$model->default = $object->getDefault();
|
||||
$model->billing = $object->getBilling();
|
||||
$model->country_id = $object->getCountryId();
|
||||
$model->state_id = $object->getStateId();
|
||||
$model->district_id = $object->getDistrictId();
|
||||
$model->postcode = $object->getPostCode();
|
||||
|
||||
return $this->handler($model);
|
||||
return $this->handler($company->addresses(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,16 @@
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Models\Address;
|
||||
|
||||
class DeletesAddress extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Address $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Address $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use App\Models\District;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Address;
|
||||
|
||||
class FetchesDistrict extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var District */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesDistrict constructor.
|
||||
* @param District $repository
|
||||
*/
|
||||
public function __construct(District $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use App\Models\District;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListsDistricts extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var District */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsDistricts constructor.
|
||||
* @param District $repository
|
||||
*/
|
||||
public function __construct(District $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,9 @@ class AddressValidation extends AbstractValidation
|
||||
*/
|
||||
protected function data($object): array {
|
||||
return [
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'street_one' => $object->getStreetOne(),
|
||||
'street_two' => $object->getStreetTwo(),
|
||||
'city' => $object->getCity(),
|
||||
'state' => $object->getState(),
|
||||
'post_code' => $object->getPostCode(),
|
||||
'country' => $object->getCountry(),
|
||||
'default' => $object->getDefault(),
|
||||
'billing' => $object->getBilling()
|
||||
'district_id' => $object->getDistrictId()
|
||||
];
|
||||
}
|
||||
|
||||
@@ -33,14 +27,8 @@ class AddressValidation extends AbstractValidation
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'company_id' => 'required',
|
||||
'street_one' => 'required',
|
||||
'city' => 'required',
|
||||
'state' => 'required',
|
||||
'post_code' => 'required',
|
||||
'country' => 'required',
|
||||
'default' => 'required',
|
||||
'billing' => 'required'
|
||||
'district_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user