mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-27 16:34:27 +00:00
80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Schedules\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
|
use App\Classes\Modules\Schedules\Services\FetchesDistrict;
|
|
use App\Classes\Modules\Schedules\Standards\Rules\CanCreateSchedule;
|
|
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
|
use App\Http\Resources\ScheduleResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateScheduleLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Schedule',
|
|
'message' => 'You have successfully created a new Schedule'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateSchedule */
|
|
private $canCreateSchedule;
|
|
|
|
/** @var FetchesDistrict */
|
|
private $fetchesDistrict;
|
|
|
|
/** @var FetchesCompany */
|
|
private $fetchesCompany;
|
|
|
|
/** @var CreatesSchedule */
|
|
private $createsSchedule;
|
|
|
|
/**
|
|
* CreateScheduleLogic constructor.
|
|
* @param CanCreateSchedule $canCreateSchedule
|
|
* @param FetchesDistrict $fetchesDistrict
|
|
* @param FetchesCompany $fetchesCompany
|
|
* @param CreatesSchedule $createsSchedule
|
|
*/
|
|
public function __construct(CanCreateSchedule $canCreateSchedule, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesSchedule $createsSchedule)
|
|
{
|
|
$this->canCreateSchedule = $canCreateSchedule;
|
|
$this->fetchesDistrict = $fetchesDistrict;
|
|
$this->fetchesCompany = $fetchesCompany;
|
|
$this->createsSchedule = $createsSchedule;
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
{
|
|
|
|
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
|
|
|
$object = new ScheduleObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'));
|
|
|
|
$this->canCreateSchedule->passes($object);
|
|
|
|
$query = $this->createsSchedule->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
|
|
|
return $this->resourceResponse(new ScheduleResource($query));
|
|
|
|
}
|
|
|
|
}
|