Files
shipping-portal/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyContactNumberLogic.php
T
2025-04-15 20:13:50 +08:00

68 lines
1.8 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\Contacts\Services\FetchesContact;
use App\Classes\Modules\Contacts\Services\UpdatesContact;
use App\Http\Resources\ContactResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyContactNumberLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated Company Contact Number',
'message' => 'You have successfully updated the Company Contact Number'
];
}
/** @var FetchesContact */
private $fetchesContact;
/** @var UpdatesContact */
private $updatesContact;
/**
* UpdateCompanyControllersLogic constructor.
* @param FetchesContact $fetchesContact
* @param UpdatesContact $updatesContact
*/
public function __construct(FetchesContact $fetchesContact, UpdatesContact $updatesContact)
{
$this->fetchesContact = $fetchesContact;
$this->updatesContact = $updatesContact;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
$query = $this->fetchesContact->execute(['id' => $request->input('id')]);
$contact = new ContactObject(
$query->reference,
$request->input('contactNumber'),
$query->email,
$query->wechat_id
);
$this->updatesContact->execute($query, $contact);
return $this->resourceResponse(new ContactResource($query));
}
}