Beispiel #1
0
  @Override
  public void define(Service service) {
    service.get(USERS, (request, response) -> userService.getUsers(), jsonTransformer);

    service.put(USERS + SEPARATOR + USER_NAME, this::upsertUser);

    service.delete(USERS + SEPARATOR + USER_NAME, this::removeUser);
  }
Beispiel #2
0
 private String upsertUser(Request request, Response response) throws UsersRepositoryException {
   try {
     return userService.upsertUser(
         request.params(USER_NAME), jsonExtractor.parse(request.body()).getPassword(), response);
   } catch (JsonExtractException e) {
     LOGGER.info("Error while deserializing addUser request", e);
     response.status(400);
     return Constants.EMPTY_BODY;
   } catch (IllegalArgumentException e) {
     LOGGER.info("Invalid user path", e);
     response.status(400);
     return Constants.EMPTY_BODY;
   }
 }
Beispiel #3
0
 private String removeUser(Request request, Response response) {
   String username = request.params(USER_NAME);
   try {
     userService.removeUser(username);
     response.status(204);
     return Constants.EMPTY_BODY;
   } catch (UsersRepositoryException e) {
     response.status(204);
     return "The user " + username + " does not exists";
   } catch (IllegalArgumentException e) {
     LOGGER.info("Invalid user path", e);
     response.status(400);
     return Constants.EMPTY_BODY;
   }
 }