use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class GeneralController method home.
// endregion
// region Pages
@RequestMapping(value = "/", method = GET)
public String home(Model model) {
String springVersion = webUI.parameterizedMessage("home.spring.version", SpringBootVersion.getVersion());
model.addAttribute("springVersion", springVersion);
GitHubStats gitHubStats = webUI.getCurrentGitHubStats();
if (gitHubStats != null) {
model.addAttribute("showGitHubStats", true);
model.addAttribute("gitHubStats", gitHubStats);
}
if (webUI.isNixMash()) {
SiteImage siteImage = siteService.getHomeBanner();
model.addAttribute("siteImage", siteImage);
}
Slice<Post> posts = postService.getPublishedPosts(0, 10);
if (posts.getContent().size() > 0)
model.addAttribute("posts", posts);
return HOME_VIEW;
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class PermaPostsController method post.
// endregion
@GetMapping(value = "/post/{postName}")
public String post(@PathVariable("postName") String postName, @RequestParam(value = "preview", required = false, defaultValue = "false") Boolean inPreviewMode, Model model, CurrentUser currentUser) throws PostNotFoundException {
Post post = postService.getPost(postName);
Date postCreated = Date.from(post.getPostDate().toInstant());
post.setIsOwner(PostUtils.isPostOwner(currentUser, post.getUserId()));
post.setPostContent(PostUtils.formatPostContent(post));
if (!inPreviewMode) {
if (applicationSettings.getMoreLikeThisDisplay()) {
// Solr must be active and number of postDocs retrieved must not be null
if (postDocService.getMoreLikeThis(post.getPostId()) != null) {
model.addAttribute("moreLikeThisDisplay", true);
model.addAttribute("postId", post.getPostId());
model.addAttribute("moreLikeThisHeading", webUI.getMessage(MORELIKETHIS_HEADING));
}
}
PostMeta postMeta = postService.buildTwitterMetaTagsForDisplay(post);
if (postMeta != null) {
model.addAttribute("twitterMetatags", fmService.getTwitterTemplate(postMeta));
}
}
model.addAttribute("post", post);
model.addAttribute("postCreated", postCreated);
model.addAttribute("shareSiteName", StringUtils.deleteWhitespace(applicationSettings.getSiteName()));
model.addAttribute("shareUrl", String.format("%s/post/%s", applicationSettings.getBaseUrl(), post.getPostName()));
return POSTS_PERMALINK_VIEW;
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method updatedPostUpdatesTwitterCardInfo.
@Test
public void updatedPostUpdatesTwitterCardInfo() throws Exception {
Post post = postService.getPostById(1L);
assert (post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY));
RequestBuilder request = post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", post.getPostTitle()).param("twitterCardType", TwitterCardType.SUMMARY_LARGE_IMAGE.name()).param("tags", "one, two").param("categoryId", "3").with(csrf());
mvc.perform(request);
post = postService.getPostById(1L);
assert (post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY_LARGE_IMAGE));
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method updatedPostTitleInAzIncludeFile.
@Test
public void updatedPostTitleInAzIncludeFile() throws Exception {
String newTitle = "New Title for updatedPostTitleInAzIncludeFile Test";
Post post = postService.getPostById(1L);
RequestBuilder request = post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", newTitle).param("twitterCardType", TWITTER_SUMMARY).param("tags", "one, two").with(csrf());
mvc.perform(request);
File azFile = new File(azTestFileName);
String contents = FileUtils.readFileToString(azFile);
assertTrue(contents.contains(newTitle));
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method removingTagFromPostDecreasesItsTagCount.
@Test
public void removingTagFromPostDecreasesItsTagCount() throws Exception {
Post post = postService.getPostById(1L);
int postTagStartCount = post.getTags().size();
// tag size of Post 1L is 3. Could be any value.
// We are assigning a new tag, so the postTagEndCount
// should be 2 less, or rather, always 1
mvc.perform(post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("postTitle", post.getPostTitle()).param("twitterCardType", TWITTER_SUMMARY).param("tags", "removingTag1").param("categoryId", "1").with(csrf()));
int postTagEndCount = post.getTags().size();
assertEquals(postTagEndCount, 1);
Post verifyPost = postService.getPostById(1L);
assertEquals(verifyPost.getTags().size(), postTagEndCount);
}
Aggregations