UsersService == null) { $this->UsersService = new UsersService(); } return $this->UsersService; } public function GetUsers(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { try { return $this->ApiResponse($this->getUsersService()->GetUsersAsDto()); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } public function CreateUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { $requestBody = $request->getParsedBody(); try { if ($requestBody === null) { throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)'); } $this->getUsersService()->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']); return $this->EmptyApiResponse($response); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } public function DeleteUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { try { $this->getUsersService()->DeleteUser($args['userId']); return $this->EmptyApiResponse($response); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } public function EditUser(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { $requestBody = $request->getParsedBody(); try { $this->getUsersService()->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']); return $this->EmptyApiResponse($response); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } public function GetUserSetting(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { try { $value = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, $args['settingKey']); return $this->ApiResponse(array('value' => $value)); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } public function SetUserSetting(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { try { $requestBody = $request->getParsedBody(); $value = $this->getUsersService()->SetUserSetting(GROCY_USER_ID, $args['settingKey'], $requestBody['value']); return $this->EmptyApiResponse($response); } catch (\Exception $ex) { return $this->GenericErrorResponse($response, $ex->getMessage()); } } }