From 47b38821d4d5ce9622837fb10fc541eac2868676 Mon Sep 17 00:00:00 2001 From: n3wborn Date: Wed, 1 Nov 2023 12:48:31 +0100 Subject: [PATCH] feat(user): add UserFinder see: #30 --- src/Service/User/UserFinder.php | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Service/User/UserFinder.php diff --git a/src/Service/User/UserFinder.php b/src/Service/User/UserFinder.php new file mode 100644 index 0000000..c503521 --- /dev/null +++ b/src/Service/User/UserFinder.php @@ -0,0 +1,52 @@ +isArchived() + && throw new NotFoundException(ApiMessages::translate(ApiMessages::USER_UNKNOWN)); + + return + ( + null !== ($result = $this->userRepository->find($user)) + ) + ? $result + : null; + } + + public function getAll(): array + { + return $this->userRepository->findAll(); + } + + public function getAllNotArchived(): array + { + return $this->userRepository->findAllNotArchived(); + } + + /** @throws NotFoundException */ + public function getUserProjects(?User $user): array + { + (!UserHelper::userExists($user)) + && throw new NotFoundException(ApiMessages::translate(ApiMessages::USER_UNKNOWN)); + + return array_filter( + $user->getProjects()->toArray(), + fn (Project $project) => !$project->isArchived() + ); + } +}