Ejemplo n.º 1
0
 private String renderListOfPosts(Page<Post> page, Model model, String activeCategory) {
   Page<PostView> postViewPage = PostView.pageOf(page, dateFactory);
   List<PostView> posts = postViewPage.getContent();
   model.addAttribute("activeCategory", activeCategory);
   model.addAttribute("categories", PostCategory.values());
   model.addAttribute("posts", posts);
   model.addAttribute("paginationInfo", new PaginationInfo(postViewPage));
   model.addAttribute("disqusShortname", service.getDisqusShortname());
   return "blog/index";
 }
Ejemplo n.º 2
0
 @RequestMapping(
     value = "/category/{category}",
     method = {GET, HEAD})
 public String listPublishedPostsForCategory(
     @PathVariable("category") PostCategory category,
     Model model,
     @RequestParam(defaultValue = "1", value = "page") int page) {
   Pageable pageRequest = PageableFactory.forLists(page);
   Page<Post> result = service.getPublishedPosts(category, pageRequest);
   return renderListOfPosts(result, model, category.getDisplayName());
 }
Ejemplo n.º 3
0
  @RequestMapping(
      value = "/{year:\\d+}/{month:\\d+}/{day:\\d+}/{slug}",
      method = {GET, HEAD})
  public String showPost(
      @PathVariable String year,
      @PathVariable String month,
      @PathVariable String day,
      @PathVariable String slug,
      Model model) {

    String publicSlug = String.format("%s/%s/%s/%s", year, month, day, slug);
    Post post = service.getPublishedPost(publicSlug);
    model.addAttribute("post", PostView.of(post, dateFactory));
    model.addAttribute("categories", PostCategory.values());
    model.addAttribute("activeCategory", post.getCategory().getDisplayName());
    model.addAttribute("disqusShortname", service.getDisqusShortname());
    return "blog/show";
  }