mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
backend registration step 1
This commit is contained in:
@@ -29,7 +29,6 @@ abstract class AbstractValidation
|
||||
|
||||
abstract protected function messages(): array;
|
||||
|
||||
|
||||
/**
|
||||
* @param DataTransferObject $object
|
||||
* @return bool
|
||||
@@ -39,8 +38,8 @@ abstract class AbstractValidation
|
||||
|
||||
$validator = $this->validator::make($this->data($object), $this->rules(), $this->messages());
|
||||
|
||||
if($validator->fails()){
|
||||
throw new RequestValidationException($validator->messages()->first());
|
||||
if($validator->fails()) {
|
||||
throw new RequestValidationException($validator->messages());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,8 @@ abstract class AbstractUpdateRecord
|
||||
}
|
||||
|
||||
} catch (QueryException $exception){
|
||||
throw new MalformedRequestException('Unable to update the record due to unexpected error');
|
||||
throw new MalformedRequestException($exception);
|
||||
// throw new MalformedRequestException('Unable to update the record due to unexpected error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Accounts\Standards\Rules\CanCreateUser;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
use App\Http\Resources\UserResource;
|
||||
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompany;
|
||||
use App\Classes\Modules\Companies\Services\CreatesCompany;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
|
||||
use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact;
|
||||
use App\Classes\Modules\Contacts\Services\CreatesContact;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Http\Resources\ContactResource;
|
||||
|
||||
use App\Classes\Modules\CompanyEmployees\Standards\Rules\CanCreateCompanyEmployee;
|
||||
use App\Classes\Modules\CompanyEmployees\Services\CreatesCompanyEmployee;
|
||||
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
||||
use App\Http\Resources\CompanyEmployeeResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateUserLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created User',
|
||||
'message' => 'You have successfully created a new User'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanCreateUser */
|
||||
private $canCreateUser;
|
||||
|
||||
/** @var CreatesUser */
|
||||
private $createsUser;
|
||||
|
||||
/** @var CanCreateCompany */
|
||||
private $canCreateCompany;
|
||||
|
||||
/** @var CreatesCompany */
|
||||
private $createsCompany;
|
||||
|
||||
/** @var CanCreateContact */
|
||||
private $canCreateContact;
|
||||
|
||||
/** @var CreatesContact */
|
||||
private $createsContact;
|
||||
|
||||
/** @var CanCreateCompanyEmployee */
|
||||
private $canCreateCompanyEmployee;
|
||||
|
||||
/** @var CreatesCompanyEmployee */
|
||||
private $createsCompanyEmployee;
|
||||
|
||||
/**
|
||||
* CreateUserControllerLogic constructor.
|
||||
* @param CanCreateUser $canCreateUser
|
||||
* @param CreatesUser $createsUser
|
||||
* @param CanCreateCompany $canCreateCompany
|
||||
* @param CreatesCompany $createsCompany
|
||||
* @param CanCreateContact $canCreateContact
|
||||
* @param CreatesContact $createsContact
|
||||
* @param CanCreateCompanyEmployee $canCreateCompanyEmployee
|
||||
* @param CreatesCompanyEmployee $createsCompanyEmployee
|
||||
*/
|
||||
public function __construct(
|
||||
CanCreateUser $canCreateUser,
|
||||
CreatesUser $createsUser,
|
||||
CanCreateCompany $canCreateCompany,
|
||||
CreatesCompany $createsCompany,
|
||||
CanCreateContact $canCreateContact,
|
||||
CreatesContact $createsContact,
|
||||
CanCreateCompanyEmployee $canCreateCompanyEmployee,
|
||||
CreatesCompanyEmployee $createsCompanyEmployee
|
||||
)
|
||||
{
|
||||
$this->canCreateUser = $canCreateUser;
|
||||
$this->createsUser = $createsUser;
|
||||
$this->canCreateCompany = $canCreateCompany;
|
||||
$this->createsCompany = $createsCompany;
|
||||
$this->canCreateContact = $canCreateContact;
|
||||
$this->createsContact = $createsContact;
|
||||
$this->canCreateCompanyEmployee = $canCreateCompanyEmployee;
|
||||
$this->createsCompanyEmployee = $createsCompanyEmployee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$user_object = new UserObject(
|
||||
$request->input('name'),
|
||||
$request->input('email'),
|
||||
$request->input('password'),
|
||||
$request->input('password_confirmation'),
|
||||
2,
|
||||
9
|
||||
);
|
||||
|
||||
$this->canCreateUser->passes($user_object);
|
||||
$user_query = $this->createsUser->execute($user_object);
|
||||
|
||||
$company_object = new CompanyObject(
|
||||
$request->input('company_name'),
|
||||
$request->input('company_reference'),
|
||||
1
|
||||
);
|
||||
|
||||
$this->canCreateCompany->passes($company_object);
|
||||
$company_query = $this->createsCompany->execute($company_object);
|
||||
|
||||
$contact_object = new ContactObject(
|
||||
1,
|
||||
$company_query->id,
|
||||
$request->input('contact_reference'),
|
||||
$request->input('phone'),
|
||||
$request->input('contact_email'),
|
||||
$request->input('wechat_id')
|
||||
);
|
||||
|
||||
$this->canCreateContact->passes($contact_object);
|
||||
$contact_query = $this->createsContact->execute($contact_object);
|
||||
|
||||
|
||||
$company_employee_object = new CompanyEmployeeObject(
|
||||
$company_query->id,
|
||||
$user_query->id
|
||||
);
|
||||
|
||||
$this->canCreateCompanyEmployee->passes($company_employee_object);
|
||||
$company_employee_query = $this->createsCompanyEmployee->execute($user_query, $company_employee_object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new UserResource($user_query));
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class UserObject implements DataTransferObject
|
||||
{
|
||||
/** @var string|null */
|
||||
private $name;
|
||||
|
||||
/** @var string|null */
|
||||
private $email;
|
||||
|
||||
/** @var string|null */
|
||||
private $password;
|
||||
|
||||
/** @var string|null */
|
||||
private $password_confirmation;
|
||||
|
||||
/** @var int */
|
||||
private $type;
|
||||
|
||||
/** @var status */
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* UserObject constructor.
|
||||
* @param string|null $name
|
||||
* @param string|null $email
|
||||
* @param string|null $password
|
||||
* @param string|null $password_confirmation
|
||||
* @param int $type
|
||||
* @param int $status
|
||||
*/
|
||||
public function __construct(
|
||||
?string $name,
|
||||
?string $email,
|
||||
?string $password,
|
||||
?string $password_confirmation,
|
||||
int $type,
|
||||
int $status
|
||||
)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
$this->password = $password;
|
||||
$this->password_confirmation = $password_confirmation;
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPasswordConfirmation(): ?string
|
||||
{
|
||||
return $this->password_confirmation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreatesUser extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(UserObject $object) {
|
||||
$model = new User();
|
||||
$model->name = $object->getName();
|
||||
$model->email = $object->getEmail();
|
||||
$model->password = bcrypt($object->getPassword());
|
||||
$model->type = $object->getType();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
use App\Classes\Modules\Accounts\Standards\Validators\UserValidation;
|
||||
|
||||
class CanCreateUser extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var UserValidation */
|
||||
private $userValidation;
|
||||
|
||||
/**
|
||||
* CanCreateUser constructor.
|
||||
* @param UserValidation $userValidation
|
||||
*/
|
||||
public function __construct(UserValidation $userValidation)
|
||||
{
|
||||
$this->userValidation = $userValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->userValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
|
||||
class UserValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'name' => $object->getName(),
|
||||
'email' => $object->getEmail(),
|
||||
'password' => $object->getPassword(),
|
||||
'password_confirmation' => $object->getPasswordConfirmation(),
|
||||
'type' => $object->getType(),
|
||||
'status' => $object->getStatus(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|max:255|unique:users,email',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
'type' => 'required',
|
||||
'status' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class CompanyObject implements DataTransferObject
|
||||
{
|
||||
/** @var string|null */
|
||||
private $name;
|
||||
|
||||
/** @var string|null */
|
||||
private $reference;
|
||||
|
||||
/** @var int */
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param string|null $name
|
||||
* @param string|null $reference
|
||||
* @param string|null $type
|
||||
*/
|
||||
public function __construct(
|
||||
?string $name,
|
||||
?string $reference,
|
||||
?string $type
|
||||
)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->reference = $reference;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Models\Company;
|
||||
|
||||
class CreatesCompany extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyObject $object)
|
||||
{
|
||||
$model = new Company();
|
||||
$model->name = $object->getName();
|
||||
$model->reference = $object->getReference();
|
||||
$model->type = $object->getType();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\UserObject;
|
||||
use App\Classes\Modules\Companies\Standards\Validators\CompanyValidation;
|
||||
|
||||
class CanCreateCompany extends AbstractRule
|
||||
{
|
||||
/** @var CompanyValidation */
|
||||
private $companyValidation;
|
||||
|
||||
/**
|
||||
* CanCreateUser constructor.
|
||||
* @param CompanyValidation $companyValidation
|
||||
*/
|
||||
public function __construct(CompanyValidation $companyValidation)
|
||||
{
|
||||
$this->companyValidation = $companyValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->companyValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
class CompanyValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'company_name' => $object->getName(),
|
||||
'company_reference' => $object->getReference(),
|
||||
'type' => $object->getType()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'company_name' => 'required',
|
||||
'company_reference' => 'required',
|
||||
'type' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CompanyEmployees\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class CompanyEmployeeObject implements DataTransferObject
|
||||
{
|
||||
/** @var int|null */
|
||||
private $company_id;
|
||||
|
||||
/** @var int|null */
|
||||
private $user_id;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param int|null $company_id
|
||||
* @param int|null $user_id
|
||||
*/
|
||||
public function __construct(
|
||||
?int $company_id,
|
||||
?int $user_id
|
||||
)
|
||||
{
|
||||
$this->company_id = $company_id;
|
||||
$this->user_id = $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCompanyId(): ?int
|
||||
{
|
||||
return $this->company_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->user_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CompanyEmployees\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreatesCompanyEmployee extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param CompanyEmployeeObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(User $model, CompanyEmployeeObject $object)
|
||||
{
|
||||
$model->company()->sync($object->getCompanyId());
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CompanyEmployees\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
||||
use App\Classes\Modules\CompanyEmployees\Standards\Validators\CompanyEmployeeValidation;
|
||||
|
||||
class CanCreateCompanyEmployee extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var CompanyEmployeeValidation */
|
||||
private $companyEmployeeValidation;
|
||||
|
||||
/**
|
||||
* CanCreateAddress constructor.
|
||||
* @param CompanyEmployeeValidation $companyEmployeeValidation
|
||||
*/
|
||||
public function __construct(CompanyEmployeeValidation $companyEmployeeValidation)
|
||||
{
|
||||
$this->companyEmployeeValidation = $companyEmployeeValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyEmployeeObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->companyEmployeeValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyEmployeeObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\CompanyEmployees\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
||||
|
||||
class CompanyEmployeeValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param CompanyEmployeeObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'user_id' => $object->getUserId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'company_id' => 'required',
|
||||
'user_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Contacts\DataTransferObjects;
|
||||
|
||||
use App\Classes\Interfaces\DataTransferObject;
|
||||
|
||||
class ContactObject implements DataTransferObject
|
||||
{
|
||||
/** @var int|null */
|
||||
private $country_id;
|
||||
|
||||
/** @var int|null */
|
||||
private $company_id;
|
||||
|
||||
/** @var string|null */
|
||||
private $reference;
|
||||
|
||||
/** @var string|null */
|
||||
private $phone;
|
||||
|
||||
/** @var string|null */
|
||||
private $email;
|
||||
|
||||
/** @var string|null */
|
||||
private $wechat_id;
|
||||
|
||||
/**
|
||||
* CompanyObject constructor.
|
||||
* @param int|null $country_id
|
||||
* @param int|null $company_id
|
||||
* @param string|null $reference
|
||||
* @param string|null $phone
|
||||
* @param string|null $email
|
||||
* @param string|null $wechat_id
|
||||
*/
|
||||
public function __construct(
|
||||
?int $country_id,
|
||||
?int $company_id,
|
||||
?string $reference,
|
||||
?string $phone,
|
||||
?string $email,
|
||||
?string $wechat_id
|
||||
)
|
||||
{
|
||||
$this->country_id = $country_id;
|
||||
$this->company_id = $company_id;
|
||||
$this->reference = $reference;
|
||||
$this->phone = $phone;
|
||||
$this->email = $email;
|
||||
$this->wechat_id = $wechat_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCountryId(): ?int
|
||||
{
|
||||
return $this->country_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCompanyId(): ?int
|
||||
{
|
||||
return $this->company_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPhone(): ?string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWeChatId(): ?string
|
||||
{
|
||||
return $this->wechat_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Contacts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Models\Contact;
|
||||
|
||||
class CreatesContact extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param ContactObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ContactObject $object)
|
||||
{
|
||||
$model = new Contact();
|
||||
$model->country_id = $object->getCountryId();
|
||||
$model->company_id = $object->getCompanyId();
|
||||
$model->reference = $object->getReference();
|
||||
$model->phone = $object->getPhone();
|
||||
$model->email = $object->getEmail();
|
||||
$model->wechat_id = $object->getWechatId();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Contacts\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\Contacts\Standards\Validators\ContactValidation;
|
||||
|
||||
class CanCreateContact extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ContactValidation */
|
||||
private $contactValidation;
|
||||
|
||||
/**
|
||||
* CanCreateAddress constructor.
|
||||
* @param ContactValidation $contactValidation
|
||||
*/
|
||||
public function __construct(ContactValidation $contactValidation)
|
||||
{
|
||||
$this->contactValidation = $contactValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContactObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->contactValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContactObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Contacts\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
|
||||
class ContactValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param ContactObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'country_id' => $object->getCountryId(),
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'contact_reference' => $object->getReference(),
|
||||
'phone' => $object->getPhone(),
|
||||
'contact_email' => $object->getEmail(),
|
||||
'wechat_id' => $object->getWechatId()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'country_id' => 'required',
|
||||
'company_id' => 'required',
|
||||
'contact_reference' => 'required',
|
||||
'phone' => 'required',
|
||||
'contact_email' => '',
|
||||
'wechat_id' => ''
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user