mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-20 21:13:59 +00:00
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Addresses\DataTransferObjects\DistrictObject;
|
|
use App\Classes\Modules\Addresses\Services\FetchesState;
|
|
use App\Classes\Modules\Addresses\Services\CreatesDistrict;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Http\Resources\DistrictResource;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateDistrictLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created District',
|
|
'message' => 'You have successfully created a new District'
|
|
];
|
|
}
|
|
|
|
/** @var FetchesState */
|
|
private $fetchesState;
|
|
|
|
/** @var CreatesDistrict */
|
|
private $createsDistrict;
|
|
|
|
|
|
/**
|
|
* CreateDistrictLogic constructor.
|
|
* @param FetchesState $fetchesState
|
|
* @param CreatesDistrict $createsDistrict
|
|
*/
|
|
public function __construct(FetchesState $fetchesState, CreatesDistrict $createsDistrict)
|
|
{
|
|
$this->fetchesState = $fetchesState;
|
|
$this->createsDistrict = $createsDistrict;
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
{
|
|
$state = $this->fetchesState->execute(['id' => $request->input('state_id')]);
|
|
|
|
$district_object = new DistrictObject($request->input('name'), $state->country_id, $state->id, $request->input('post_codes'), ApprovalStatus::PENDING_VERIFICATION);
|
|
|
|
$query = $this->createsDistrict->execute($district_object);
|
|
|
|
return $this->resourceResponse(new DistrictResource($query));
|
|
|
|
}
|
|
} |