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

55 lines
1.4 KiB
PHP

<?php
namespace App\Classes\Modules\Contacts\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Http\Resources\ContactResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateContactLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Contact',
'message' => 'You have successfully created a new Contact'
];
}
/** @var CreateContactProcessor */
private $createContactProcessor;
/**
* CreateContactLogic constructor.
* @param CreateContactProcessor $createContactProcessor
*/
public function __construct(CreateContactProcessor $createContactProcessor)
{
$this->createContactProcessor = $createContactProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
return $this->resourceResponse(new ContactResource($this->createContactProcessor->execute($request)));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}