Files
exchange-2.0/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyFromSegmentLogic.php
T
2023-03-18 23:00:02 +08:00

68 lines
2.2 KiB
PHP

<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\RemovesCompanyFromSegment;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class RemoveCompanyFromSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Detach Company From Segment',
'message' => 'You have successfully detached Company from segment'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var FetchesSegment */
private $fetchesSegment;
/** @var RemovesCompanyFromSegment */
private $removesCompanyFromSegment;
/**
* RemoveCompanyFromSegmentLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param FetchesSegment $fetchesSegment
* @param RemovesCompanyFromSegment $removesCompanyFromSegment
*/
public function __construct(FetchesCompany $fetchesCompany, FetchesSegment $fetchesSegment, RemovesCompanyFromSegment $removesCompanyFromSegment)
{
$this->fetchesCompany = $fetchesCompany;
$this->fetchesSegment = $fetchesSegment;
$this->removesCompanyFromSegment = $removesCompanyFromSegment;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]);
if (env('HONEY_TRAP_SEGMENT_ID') && env('HONEY_TRAP_SEGMENT_ID') == $request->route('segment_id')) {
$company->seasonalSegments->first()->delete();
}
$this->removesCompanyFromSegment->execute($company, $segment);
return $this->resourceResponse(new CompanyResource($company));
}
}