From 74cb1477bb921a2378ea22a552b71a48c11e0931 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 20 Jul 2018 16:34:32 +0200 Subject: Better API (integrated oauth completely) --- api/Users/Services/UserService.php | 88 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 api/Users/Services/UserService.php (limited to 'api/Users/Services') diff --git a/api/Users/Services/UserService.php b/api/Users/Services/UserService.php new file mode 100644 index 0000000..923acd0 --- /dev/null +++ b/api/Users/Services/UserService.php @@ -0,0 +1,88 @@ +auth = $auth; + $this->database = $database; + $this->dispatcher = $dispatcher; + $this->userRepository = $userRepository; + } + + public function getAll($options = []) + { + return $this->userRepository->get($options); + } + + public function getById($userId, array $options = []) + { + $user = $this->getRequestedUser($userId); + + return $user; + } + + public function create($data) + { + $user = $this->userRepository->create($data); + + $this->dispatcher->fire(new UserWasCreated($user)); + + return $user; + } + + public function update($userId, array $data) + { + $user = $this->getRequestedUser($userId); + + $this->userRepository->update($user, $data); + + $this->dispatcher->fire(new UserWasUpdated($user)); + + return $user; + } + + public function delete($userId) + { + $user = $this->getRequestedUser($userId); + + $this->userRepository->delete($userId); + + $this->dispatcher->fire(new UserWasDeleted($user)); + } + + private function getRequestedUser($userId) + { + $user = $this->userRepository->getById($userId); + + if (is_null($user)) { + throw new UserNotFoundException(); + } + + return $user; + } +} -- cgit v1.2.3