Files
exchange-2.0/app/Classes/Modules/Companies/ControllersLogic/AssignCompanyToSegmentLogic.php
T
omair saleh 05401f6bbc large commit
2021-03-11 13:06:40 +08:00

59 lines
1.8 KiB
PHP

<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AssignCompanyToSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Assign Company To Segment',
'message' => 'You have successfully assigned Company to segment'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var AssignSegmentProcessor */
private $assignCompanyToSegmentProcessor;
/**
* AssignCompanyToSegmentLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param AssignSegmentProcessor $assignCompanyToSegmentProcessor
*/
public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor)
{
$this->fetchesCompany = $fetchesCompany;
$this->assignCompanyToSegmentProcessor = $assignCompanyToSegmentProcessor;
}
/**
* @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
{
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$this->assignCompanyToSegmentProcessor->execute($company, $request->input('segment_id'));
return $this->resourceResponse(new CompanyResource($company));
}
}