コード例 #1
0
 @RequestMapping(method = RequestMethod.GET)
 @PreAuthorize("permitAll")
 public ResponseEntity<BlogListResource> findAllBlogs() {
   BlogList blogList = blogService.findAllBlogs();
   BlogListResource blogListRes = new BlogListResourceAsm().toResource(blogList);
   return new ResponseEntity<BlogListResource>(blogListRes, HttpStatus.OK);
 }
コード例 #2
0
 @RequestMapping(value = "/{blogId}/blog-entries")
 public ResponseEntity<BlogEntryListResource> findAllBlogEntries(@PathVariable Long blogId) {
   try {
     BlogEntryList list = blogService.findAllBlogEntries(blogId);
     BlogEntryListResource res = new BlogEntryListResourceAsm().toResource(list);
     return new ResponseEntity<BlogEntryListResource>(res, HttpStatus.OK);
   } catch (BlogNotFoundException exception) {
     throw new NotFoundException(exception);
   }
 }
コード例 #3
0
 @RequestMapping(value = "/{blogId}", method = RequestMethod.GET)
 public ResponseEntity<BlogResource> getBlog(@PathVariable Long blogId) {
   Blog blog = blogService.findBlog(blogId);
   if (blog != null) {
     BlogResource res = new BlogResourceAsm().toResource(blog);
     return new ResponseEntity<BlogResource>(res, HttpStatus.OK);
   } else {
     return new ResponseEntity<BlogResource>(HttpStatus.NOT_FOUND);
   }
 }
コード例 #4
0
 @RequestMapping(value = "/{blogId}/blog-entries", method = RequestMethod.POST)
 public ResponseEntity<BlogEntryResource> createBlogEntry(
     @PathVariable Long blogId, @RequestBody BlogEntryResource sentBlogEntry) {
   BlogEntry createdBlogEntry = null;
   try {
     createdBlogEntry = blogService.createBlogEntry(blogId, sentBlogEntry.toBlogEntry());
     BlogEntryResource createdResource = new BlogEntryResourceAsm().toResource(createdBlogEntry);
     HttpHeaders headers = new HttpHeaders();
     headers.setLocation(URI.create(createdResource.getLink("self").getHref()));
     return new ResponseEntity<BlogEntryResource>(createdResource, headers, HttpStatus.CREATED);
   } catch (BlogNotFoundException e) {
     throw new NotFoundException(e);
   }
 }