diff --git a/app/composer.json b/app/composer.json index be399e99a066e779e3015ba3f581ad72061505b3..a785c5a8ce0aac79064866f9b72a32151e2726d3 100644 --- a/app/composer.json +++ b/app/composer.json @@ -13,6 +13,7 @@ "doctrine/orm": "^3.1", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpdoc-parser": "^1.28", + "ramsey/uuid": "^4.7", "symfony/asset": "6.4.*", "symfony/asset-mapper": "6.4.*", "symfony/console": "6.4.*", diff --git a/app/src/News/Request/NewsCreateRequest.php b/app/src/News/Request/NewsCreateRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..084d87468120165a0977620b8440df592a448853 --- /dev/null +++ b/app/src/News/Request/NewsCreateRequest.php @@ -0,0 +1,50 @@ + */ + #[All( + new Uuid() + )] + public $categories_uuid; + + #[Uuid] + public $detail_image; + + #[Uuid] + public $preview_image; +} diff --git a/app/src/News/Request/NewsPartUpdateRequest.php b/app/src/News/Request/NewsPartUpdateRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..b0a14239ee66efd3599f9c0252ca07ad107dfbb0 --- /dev/null +++ b/app/src/News/Request/NewsPartUpdateRequest.php @@ -0,0 +1,48 @@ +populate(); + + if ($this->autoValidate) { + $this->validate(); + } + } + + protected function populate(): void + { + foreach ($this->getRequest()->toArray() as $property => $value) { + if (property_exists($this, $property)) { + $this->{$property} = $value; + } + } + } + + public function validate(): void + { + $errors = $this->validator->validate($this); + + $messages = new ValidationErrorCollection(); + + foreach ($errors as $error) { + $messages->add($this->errorDtoFactory->create($error)); + } + + if ($messages->count() > 0) { + $response = new JsonResponse($messages, 422); + $response->send(); + + throw new ValidatorException('Validation failed'); + } + } + + public function getRequest(): Request + { + return Request::createFromGlobals(); + } +} \ No newline at end of file diff --git a/app/src/Shared/Collection/ValidationErrorCollection.php b/app/src/Shared/Collection/ValidationErrorCollection.php new file mode 100644 index 0000000000000000000000000000000000000000..346ae1ad35c8ec3f010e529a94da36f4cdb913a0 --- /dev/null +++ b/app/src/Shared/Collection/ValidationErrorCollection.php @@ -0,0 +1,16 @@ +collectionType, $data); + } +} \ No newline at end of file