Files
portal/app/Classes/Modules/Contacts/ControllersLogic/UpdateContactLogic.php
T
omair saleh 7f712e6ca8 bulk commit
2020-08-24 09:54:50 +08:00

78 lines
2.3 KiB
PHP

<?php
namespace App\Classes\Modules\Contacts\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Contacts\Services\UpdatesContact;
use App\Classes\Modules\Contacts\Services\FetchesContact;
use App\Classes\Modules\Contacts\Standards\Rules\CanUpdateContact;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Http\Resources\ContactResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateContactLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Updated Contact',
'message' => 'You have successfully updated the Contact'
];
}
/** @var CanUpdateContact */
private $canUpdateContact;
/** @var UpdatesContact */
private $updatesContact;
/** @var FetchesContact */
private $fetchesContact;
/**
* UpdateContactControllerLogic constructor.
* @param CanUpdateContact $canUpdateContact
* @param UpdatesContact $updatesContact
* @param FetchesContact $fetchesContact
*/
public function __construct(CanUpdateContact $canUpdateContact, UpdatesContact $updatesContact, FetchesContact $fetchesContact)
{
$this->canUpdateContact = $canUpdateContact;
$this->updatesContact = $updatesContact;
$this->fetchesContact = $fetchesContact;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
$object = new ContactObject($request->input('company_id'), $request->input('name'), $request->input('designation'), $request->input('email'), $request->input('phone'), $request->input('wechat_id'));
$this->canUpdateContact->passes($object);
$query = $this->fetchesContact->execute(['id' => $request->route('id')]);
$query = $this->updatesContact->execute($query, $object);
return $this->resourceResponse(new ContactResource($query));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}