diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php new file mode 100644 index 00000000..09b0e153 --- /dev/null +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php @@ -0,0 +1,86 @@ +name = $name; + $this->reference = $reference; + $this->businessType = $businessType; + $this->type = $type; + $this->status = $status; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getReference(): string + { + return $this->reference; + } + + /** + * @return int + */ + public function getBusinessType(): int + { + return $this->businessType; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php new file mode 100644 index 00000000..fc84e9cc --- /dev/null +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php @@ -0,0 +1,60 @@ +canCreateCompany = $canCreateCompany; + $this->createsCompany = $createsCompany; + } + + + /** + * @param Request $request + * @param int $businessType + * @param int|null $companyType + * @param int|null $status + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Request $request, int $businessType = BusinessType::IMPORTER, ?int $companyType = CompanyType::COMPANY_BUSINESS, ?int $status = ApprovalStatus::PENDING_SUBMISSION): Model { + + $companyName = $companyType === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name'); + $company_object = new CompanyObject( + $companyName, + mt_rand(1000, 9999).(new GeneratesInitials())->name($companyName)->length(3)->generate(), + $businessType, $companyType, $status); + + $this->canCreateCompany->passes($company_object); + + return $this->createsCompany->execute($company_object); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/CreatesCompany.php b/app/Classes/Modules/Companies/Services/CreatesCompany.php new file mode 100644 index 00000000..a6f71632 --- /dev/null +++ b/app/Classes/Modules/Companies/Services/CreatesCompany.php @@ -0,0 +1,27 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->type = $object->getType(); + $model->business_type = $object->getBusinessType(); + + return $this->handler($model); + } +} diff --git a/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompany.php b/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompany.php new file mode 100644 index 00000000..75015ff0 --- /dev/null +++ b/app/Classes/Modules/Companies/Standards/Rules/CanCreateCompany.php @@ -0,0 +1,51 @@ +companyValidation = $companyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param CompanyObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->companyValidation->validate($object); + } + + /** + * @param CompanyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php new file mode 100644 index 00000000..173dc0bd --- /dev/null +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php @@ -0,0 +1,49 @@ + $object->getName(), + 'company_reference' => $object->getReference(), + 'type' => $object->getBusinessType() + ]; + } + + /** + * @param string $type + * @return array + */ + protected function rules(?string $type = 'POST'): array + { + if ($type == 'POST') { + return [ + 'company_name' => 'required', + 'company_reference' => '', + 'type' => '' + ]; + } elseif ($type == 'PUT') { + return [ + 'type' => 'required' + ]; + } + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} diff --git a/app/Classes/ValueObjects/Constants/BusinessType.php b/app/Classes/ValueObjects/Constants/BusinessType.php new file mode 100644 index 00000000..d24b975d --- /dev/null +++ b/app/Classes/ValueObjects/Constants/BusinessType.php @@ -0,0 +1,13 @@ +