Exemplo n.º 1
0
 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "application/json")
 public @ResponseBody ResponseEntity delete(@PathVariable("id") int id) {
   if (userService.getUser(id) == null) {
     return new ResponseEntity<APIMessage>(
         new APIMessage("User not exists"), HttpStatus.BAD_REQUEST);
   } else {
     userService.delete(id);
     return new ResponseEntity(HttpStatus.OK);
   }
 }
Exemplo n.º 2
0
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = "application/json")
  public @ResponseBody ResponseEntity update(
      @PathVariable("id") int id, HttpServletRequest request) {
    String username = request.getParameter("username");
    String city = request.getParameter("city");
    String email = request.getParameter("email");
    String telephone = request.getParameter("telephone");
    String avatar = request.getParameter("avatar");

    User user = userService.getUser(id);

    user.setUsername(username)
        .setCity(city)
        .setAvatar(avatar)
        .setEmail(email)
        .setTelephone(telephone);

    userService.update(user);
    return new ResponseEntity<APIMessage>(new APIMessage("Update success"), HttpStatus.OK);
  }