@RequestMapping(value = "/users", method = RequestMethod.POST) public User userCreate(@RequestHeader("x-token") String securitytoken, @RequestBody User user) { User authUser = userService.pass(securitytoken); if (authUser.getId() > 0 && authUser.getLevel() > 0) { userService.create(user); } return user; }
@RequestMapping(value = "/users/{userId}", method = RequestMethod.GET) public User userObject( @PathVariable("userId") int id, @RequestHeader("x-token") String securitytoken) { User user = new User(); User authUser = userService.pass(securitytoken); if (authUser.getId() > 0) { user = userService.findById(id); } return user; }
@RequestMapping(value = "/users", method = RequestMethod.GET) public List<User> userList(@RequestHeader("x-token") String securitytoken) { List<User> userList = new ArrayList<>(); User authUser = userService.pass(securitytoken); if (authUser.getId() > 0) { userList = userService.findAll(); } return userList; }
@RequestMapping(value = "/users/logout", method = RequestMethod.DELETE) public User logoutUser(@RequestHeader("x-token") String securitytoken) { User user = userService.logout(securitytoken); return user; }
@RequestMapping(value = "/users/{userId}", method = RequestMethod.DELETE) public User userDelete( @PathVariable("userId") int id, @RequestHeader("x-token") String securitytoken) { User deletedUser = new User(); User authUser = userService.pass(securitytoken); if (authUser.getId() > 0 && authUser.getLevel() > 10) { deletedUser = userService.findById(id); if (deletedUser.getId() > 0) { deletedUser = userService.delete(id); } } return deletedUser; }
@RequestMapping(value = "/users/login", method = RequestMethod.POST) public User loginUser( @RequestParam(value = "login") String login, @RequestParam(value = "passwd") String passwd) { User user = userService.login(login, passwd); return user; }
@RequestMapping(value = "/users/{userId}", method = RequestMethod.POST) public User userUpdate( @PathVariable("userId") int id, @RequestBody User user, @RequestHeader("x-token") String securitytoken) { User updatedUser = user; User authUser = userService.pass(securitytoken); if (authUser.getId() > 0) { updatedUser = userService.findById(id); if (updatedUser.getId() > 0 && authUser.getLevel() > 0) { updatedUser.setLogin(user.getLogin()); updatedUser.setPasswd(user.getPasswd()); updatedUser.setFirstName(user.getFirstName()); updatedUser.setLastName(user.getLastName()); updatedUser.setLevel(user.getLevel()); updatedUser = userService.update(updatedUser); } } return updatedUser; }
@RequestMapping(value = "/users/pingpong", method = RequestMethod.GET) public User userPing(@RequestHeader("x-token") String securitytoken) { User user = new User(); try { User authUser = userService.pass(securitytoken); if (authUser.getId() > 0) { user = authUser; } } catch (Exception e) { } return user; }