/**
   * Handles a JSON request send to the path for adding a new {@link User}.
   *
   * @param req the request as {@link UserJSONWrapper}
   * @return a {@link ResponseEntity} with a {@link HttpStatus} giving information about success or
   *     failure
   */
  @RequestMapping(
      path = "/backend/nutzerinnen/add",
      method = RequestMethod.POST,
      consumes = "application/json",
      produces = "application/json")
  public ResponseEntity<UserJSONWrapper> addUser(@RequestBody final UserJSONWrapper req) {
    if (req == null) {
      return new ResponseEntity<UserJSONWrapper>(HttpStatus.BAD_REQUEST);
    }
    Map<Userfields, String> userMap = new HashMap<Userfields, String>();
    userMap.put(Userfields.email, req.getEmail());
    userMap.put(Userfields.name, req.getName());
    userMap.put(Userfields.surname, req.getSurname());
    userMap.put(Userfields.password, "magic");
    userMap.put(Userfields.plzId, req.getPlz());
    userMap.put(
        Userfields.role,
        req.getRole().equals("ADMIN") ? UserRoles.ADMIN.toString() : UserRoles.USER.toString());
    userMap.put(Userfields.street, req.getStreet());
    userMap.put(Userfields.streetnumber, req.getStreetnumber());

    UserJSONWrapper returnWrapper = req;
    returnWrapper.setPassword("");
    try {
      userService.createAccount(userMap);
      return new ResponseEntity<UserJSONWrapper>(returnWrapper, HttpStatus.CREATED);
    } catch (DatabaseException e) {
      System.err.println(e.getMessage());
      return returnUnprocessableEntity(returnWrapper);
    }
  }
  /**
   * Responsible for editing data of a {@link User}, consumes data as a {@link UserJSONWrapper}.
   *
   * @param req the request as {@link UserJSONWrapper}
   * @return a {@link ResponseEntity} with a {@link HttpStatus} giving information about success or
   *     failure
   */
  @RequestMapping(
      path = "/backend/nutzerinnen/edit",
      method = RequestMethod.POST,
      consumes = "application/json",
      produces = "application/json")
  public ResponseEntity<UserJSONWrapper> editUser(@RequestBody final UserJSONWrapper req) {
    if (req == null) {
      return new ResponseEntity<UserJSONWrapper>(HttpStatus.BAD_REQUEST);
    }

    Map<Userfields, String> userMap = new HashMap<Userfields, String>();
    if (req.getName().isEmpty()) {
      userMap.put(Userfields.name, req.getName());
    } else if (!req.getSurname().isEmpty()) {
      userMap.put(Userfields.surname, req.getSurname());
    } else if (!req.getStreet().isEmpty()) {
      userMap.put(Userfields.street, req.getStreet());
    } else if (!req.getStreetnumber().isEmpty()) {
      userMap.put(Userfields.streetnumber, req.getStreetnumber());
    } else if (!req.getPlz().isEmpty()) {
      userMap.put(Userfields.plzId, req.getPlz());
    } else if (!req.getEmail().isEmpty()) {
      userMap.put(Userfields.email, req.getEmail());
    } else if (!req.getRole().isEmpty()) {
      userMap.put(Userfields.role, req.getRole());
    } else if (!req.getPassword().isEmpty()) {
      userMap.put(Userfields.password, req.getPassword());
    }

    UserJSONWrapper returnWrapper = req;
    returnWrapper.setPassword("");

    try {
      if (!userService.updateAccount(Integer.parseInt(req.getId()), userMap)) {
        return returnUnprocessableEntity(returnWrapper);
      }
      return new ResponseEntity<UserJSONWrapper>(returnWrapper, HttpStatus.OK);
    } catch (DatabaseException e) {
      e.printStackTrace();
      return returnUnprocessableEntity(returnWrapper);
    }
  }