mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
66 lines
2.1 KiB
PHP
66 lines
2.1 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')]);
|
|
|
|
$company->seasonalSegments()->where('segment_id', $request->route('segment_id'))->delete();
|
|
|
|
$this->removesCompanyFromSegment->execute($company, $segment);
|
|
|
|
return $this->resourceResponse(new CompanyResource($company));
|
|
}
|
|
} |