diff --git a/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php new file mode 100644 index 00000000..7dbfca9e --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/UpdateUserLogic.php @@ -0,0 +1,78 @@ + 'Updated User Profile', + 'message' => 'You have successfully updated the User Profile' + ]; + } + + /** @var CanUpdateUser */ + private $canUpdateUser; + + /** @var UpdatesUser */ + private $updatesUser; + + /** @var FetchesUser */ + private $fetchesUser; + + /** + * UpdateAddressLogic constructor. + * @param CanUpdateUser $canUpdateUser + * @param UpdatesUser $updatesUser + * @param FetchesUser $fetchesUSer + */ + public function __construct(CanUpdateUser $canUpdateUser, UpdatesUser $updatesUser, FetchesUser $fetchesUser) + { + $this->canUpdateUser = $canUpdateUser; + $this->updatesUser = $updatesUser; + $this->fetchesUser = $fetchesUser; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + + $object = new UserObject($request->input('name')); + + $this->canUpdateUser->passes($object); + + $query = $this->fetchesUser->execute(['id' => $request->route('id')]); + + $query = $this->updatesUser->execute($query, $object); + + return $this->resourceResponse(new UserResource($query)); + + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php b/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php new file mode 100644 index 00000000..b3988d3a --- /dev/null +++ b/app/Classes/Modules/Accounts/DataTransferObjects/UserObject.php @@ -0,0 +1,30 @@ +name = $name; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Services/UpdatesUser.php b/app/Classes/Modules/Accounts/Services/UpdatesUser.php new file mode 100644 index 00000000..ef2e8d1a --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/UpdatesUser.php @@ -0,0 +1,24 @@ +name = $object->getName(); + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Rules/CanUpdateUser.php b/app/Classes/Modules/Accounts/Standards/Rules/CanUpdateUser.php new file mode 100644 index 00000000..a523ac12 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Rules/CanUpdateUser.php @@ -0,0 +1,57 @@ +userUpdateValidation = $userUpdateValidation; + } + + + /** + * @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->userUpdateValidation->validate($object); + + } + + + /** + * @param AddressObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/Standards/Validators/UserUpdateValidation.php b/app/Classes/Modules/Accounts/Standards/Validators/UserUpdateValidation.php new file mode 100644 index 00000000..9b2f8177 --- /dev/null +++ b/app/Classes/Modules/Accounts/Standards/Validators/UserUpdateValidation.php @@ -0,0 +1,40 @@ + $object->getName(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'name' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file