Files
shipping-portal/app/Classes/Modules/Companies/ControllersLogic/CreateCompanyContactNumberLogic.php
T
2025-05-06 11:16:06 +08:00

75 lines
2.2 KiB
PHP

<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Contacts\Services\CreatesContact;
use App\Http\Resources\ContactResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Http\Resources\CompanyResource;
class CreateCompanyContactNumberLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Company Contact Number',
'message' => 'You have successfully created the Company Contact Number'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreatesContact */
private $createsContact;
/** @var CreateContactProcessor */
private $createContactProcessor;
/**
* UpdateCompanyControllersLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param CreatesContact $createsContact
* @param CreateContactProcessor $createContactProcessor
*/
public function __construct(FetchesCompany $fetchesCompany, CreatesContact $createsContact, CreateContactProcessor $createContactProcessor)
{
$this->fetchesCompany = $fetchesCompany;
$this->createsContact = $createsContact;
$this->createContactProcessor = $createContactProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$company = $this->fetchesCompany->execute(['id' => $request->input('companyId')]);
$contact = new ContactObject(
$company->reference,
$request->input('contactNumber'),
$company->email,
$company->wechat_id
);
$this->createContactProcessor->execute($contact, $company);
return $this->resourceResponse(new CompanyResource($company));
}
}