Files
shipping-portal/app/Classes/Modules/Companies/ControllersLogic/RemoveCompanyConnectionFromConnectionSegmentLogic.php
T

73 lines
2.7 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\FetchesCompanyConnection;
use App\Classes\Modules\Companies\Services\RemovesCompanyConnectionFromConnectionSegment;
use App\Classes\Modules\Segments\Services\FetchesSegment;
use App\Http\Resources\CompanyResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class RemoveCompanyConnectionFromConnectionSegmentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Detach Company Connection From Connection Segment',
'message' => 'You have successfully detached Company Connection from Connection segment'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var FetchesCompanyConnection */
private $fetchesCompanyConnection;
/** @var FetchesSegment */
private $fetchesSegment;
/** @var RemovesCompanyConnectionFromConnectionSegment */
private $removesCompanyConnectionFromConnectionSegment;
/**
* RemoveCompanyFromSegmentLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param FetchesCompanyConnection $fetchesCompanyConnection
* @param FetchesSegment $fetchesSegment
* @param RemovesCompanyConnectionFromConnectionSegment $removesCompanyConnectionFromConnectionSegment
*/
public function __construct(FetchesCompany $fetchesCompany, FetchesCompanyConnection $fetchesCompanyConnection, FetchesSegment $fetchesSegment, RemovesCompanyConnectionFromConnectionSegment $removesCompanyConnectionFromConnectionSegment)
{
$this->fetchesCompany = $fetchesCompany;
$this->fetchesCompanyConnection = $fetchesCompanyConnection;
$this->fetchesSegment = $fetchesSegment;
$this->removesCompanyConnectionFromConnectionSegment = $removesCompanyConnectionFromConnectionSegment;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$companyConnection = $this->fetchesCompanyConnection->execute(['id' => $request->route('company_connection_id')]);
$segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]);
$this->removesCompanyConnectionFromConnectionSegment->execute($companyConnection, $segment);
return $this->resourceResponse(new CompanyResource($company));
}
}