diff --git a/src/Helper/ApiMessages.php b/src/Helper/ApiMessages.php index b7724c5..5feae4d 100644 --- a/src/Helper/ApiMessages.php +++ b/src/Helper/ApiMessages.php @@ -19,6 +19,7 @@ final class ApiMessages public const INDEX_STATUS = 'status'; public const INDEX_SUCCESS = 'success'; public const INDEX_WARNING = 'warning'; + public const LISTING_ERROR = 'Une erreur est survenue durant la récupération du listing'; public const MESSAGE_OK = 'OK'; public const PROJECT_CREATE_ERROR_MESSAGE = 'An error occurred while persisting project'; public const PROJECT_CREATE_SUCCESS_MESSAGE = 'Le project a bien été créé'; diff --git a/src/Service/Category/CategoryDTO.php b/src/Service/Category/CategoryDTO.php new file mode 100644 index 0000000..b77ab40 --- /dev/null +++ b/src/Service/Category/CategoryDTO.php @@ -0,0 +1,36 @@ +name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + public function getSlug(): ?string + { + return $this->slug; + } + + public function setSlug(string $slug): self + { + $this->slug = $slug; + + return $this; + } +} diff --git a/src/Service/Category/CategoryFinder.php b/src/Service/Category/CategoryFinder.php new file mode 100644 index 0000000..2791ec7 --- /dev/null +++ b/src/Service/Category/CategoryFinder.php @@ -0,0 +1,41 @@ + CategoryMapper::fromEntityToJson($category), $data); + $response = ApiResponse::createAndFormat($result); + } catch (ExceptionInterface|NotFoundException $exception) { + $this->logger->logNotice($exception); + $response = ApiResponse::createWarningMessage(ApiMessages::LISTING_ERROR); + } catch (\Exception $exception) { + $this->logger->logCriticalAndTrace($exception); + $response = ApiResponse::createErrorMessage(ApiMessages::DEFAULT_ERROR_MESSAGE, exception: $exception); + } + + return $response; + } +} diff --git a/src/Service/Category/CategoryHandler.php b/src/Service/Category/CategoryHandler.php new file mode 100644 index 0000000..b85fd3f --- /dev/null +++ b/src/Service/Category/CategoryHandler.php @@ -0,0 +1,10 @@ + !$category->isArchived() ? $category : null, + $project->getCategories()->toArray() + ); + } +} diff --git a/src/Service/Category/CategoryMapper.php b/src/Service/Category/CategoryMapper.php new file mode 100644 index 0000000..020c75a --- /dev/null +++ b/src/Service/Category/CategoryMapper.php @@ -0,0 +1,29 @@ +normalize($dto, JsonEncoder::FORMAT); + } + + public static function fromEntityToDTO(Category $category): CategoryDTO + { + return new CategoryDTO( + $category->getName(), + $category->getSlug(), + ); + } +} diff --git a/src/Service/Category/CategoryPersister.php b/src/Service/Category/CategoryPersister.php new file mode 100644 index 0000000..8b2c311 --- /dev/null +++ b/src/Service/Category/CategoryPersister.php @@ -0,0 +1,10 @@ +