@RequestMapping(value = "/users", method = RequestMethod.POST) public ResponseEntity<User> createUser(@RequestBody User user) { HttpStatus status = HttpStatus.OK; if (!userRepository.exists(user.getEmail())) { status = HttpStatus.CREATED; } User saved = userRepository.save(user); return new ResponseEntity<>(saved, status); }
@RequestMapping(value = "/user/{email}", method = RequestMethod.DELETE) public ResponseEntity<User> deleteUser(@PathVariable String email) throws EntityNotFoundException { userRepository.delete(email); return new ResponseEntity<>(HttpStatus.OK); }
@RequestMapping(value = "/user/{email}", method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String email, @RequestBody User user) throws EntityNotFoundException { User saved = userRepository.update(email, user); return new ResponseEntity<>(saved, HttpStatus.OK); }
@RequestMapping(value = "/users", method = RequestMethod.GET) public List<User> findAll() { return userRepository.findAll(); }
@Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).addFilter(springSecurityFilter).build(); userRepository.reset(new User("*****@*****.**")); }