mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-21 13:34:08 +00:00
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Companies\ControllerLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Companies\Services\CreatesCompany;
|
|
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompany;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
|
use App\Http\Resources\CompanyResource;
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CreateCompanyControllerLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created Company',
|
|
'message' => 'You have successfully created a new Company'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateCompany */
|
|
private $canCreateCompany;
|
|
|
|
/** @var CreatesCompany */
|
|
private $createsCompany;
|
|
|
|
/**
|
|
* CreateCompanyControllerLogic constructor.
|
|
* @param CanCreateCompany $canCreateCompany
|
|
* @param CreatesCompany $createsCompany
|
|
*/
|
|
public function __construct(CanCreateCompany $canCreateCompany, CreatesCompany $createsCompany)
|
|
{
|
|
$this->canCreateCompany = $canCreateCompany;
|
|
$this->createsCompany = $createsCompany;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
|
|
$object = new CompanyObject($request->input('reference_no'), $request->input('name'), $request->input('type'));
|
|
|
|
$this->canCreateCompany->passes($object);
|
|
|
|
$query = $this->createsCompany->execute($object);
|
|
|
|
return $this->resourceResponse(new CompanyResource($query));
|
|
|
|
} catch (\Exception $exception){
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
|
|
} |