Created
June 17, 2012 10:16
-
-
Save matsev/2944122 to your computer and use it in GitHub Desktop.
Revisions
-
matsev revised this gist
Jun 17, 2012 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ @RequestMapping(method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) @ResponseStatus(HttpStatus.CREATED) void create(@RequestBody @Valid User user, HttpServletRequest request, HttpServletResponse response) { long userId = userService.create(user); String location = ServletUriComponentsBuilder.fromRequestUri(request).path("/{userid}") .build() .expand(userId).toUriString(); response.addHeader("Location", location); } -
matsev revised this gist
Jun 17, 2012 . 1 changed file with 34 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ @XmlRootElement public class User { @NotBlank @Length(min = 3, max = 30) private String name; @Email private String email; public User() { } public User(String name, String email) { this.name = name; this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } } -
matsev revised this gist
Jun 17, 2012 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ @RequestMapping(value = "/{userId}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) @ResponseBody User read(@PathVariable("userId") long userId) { return userService.read(userId); } -
matsev revised this gist
Jun 17, 2012 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ @RequestMapping(value = "/{userId}", method = RequestMethod.PUT, consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) @ResponseStatus(HttpStatus.NO_CONTENT) void update(@PathVariable("userId") long userId, @RequestBody @Valid User user) { userService.update(userId, user); } -
matsev revised this gist
Jun 17, 2012 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ @RequestMapping(value = "/{userId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) void delete(@PathVariable("userId") long userId) { userService.delete(userId); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,5 +9,5 @@ class UserController { this.userService = userService; } // TODO implement CRUD methods } -
matsev revised this gist
Jun 17, 2012 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ @RequestMapping(value = "/{userId}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) void delete(@PathVariable("userId") int userId) { userService.delete(userId); } -
matsev revised this gist
Jun 17, 2012 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ @Controller @RequestMapping("/user") class UserController { private final UserService userService; @Autowired UserController(UserService userService) { this.userService = userService; } // Add CRUD methods } -
matsev created this gist
Jun 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ public interface UserService { long create(User user); User read(long userId) throws UnknownUserException; void update(long userId, User user) throws UnknownUserException; void delete(long userId) throws UnknownUserException; }