Files
izyim/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php
T
2019-03-05 15:23:11 +08:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Modules\ControllerLogic\Contacts;
use App\Classes\Constants;
use App\Classes\Modules\Contacts\Exceptions\CannotCreateContactException;
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Modules\Contacts\Services\CreatesContact;
use Illuminate\Http\Request;
class CreateContactLogic
{
/** @var CreatesContact */
private $createsContact;
/**
* CreateContactLogic constructor.
* @param CreatesContact $createsContact
*/
public function __construct(CreatesContact $createsContact)
{
$this->createsContact = $createsContact;
}
public function execute(int $type, int $referenceId, Request $request){
try {
$object = new ContactObject($type, $referenceId, $request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email'));
return $this->createsContact->execute($object);
} catch (CannotCreateContactException $exception){
throw new InternalServerErrorException("Failed to create contact because {$exception->getMessage()}");
}
}
}