use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.
the class PostsController method tags.
@RequestMapping(value = "/tag/{tagValue}", method = GET)
public String tags(@PathVariable("tagValue") String tagValue, Model model) throws TagNotFoundException, UnsupportedEncodingException {
Tag tag = postService.getTag(URLDecoder.decode(tagValue, "UTF-8"));
boolean showMore = postService.getPublishedPostsByTagId(tag.getTagId()).size() > POST_PAGING_SIZE;
model.addAttribute("tag", tag);
model.addAttribute("showmore", showMore);
return POSTS_TAGS_VIEW;
}
use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.
the class PostRepoTests method savePostWithTags.
@Test
public void savePostWithTags() {
Post post = Post.getBuilder(1L, "Post With Tags", "post-with-tags", null, "New post with tags!", PostType.POST, PostDisplayType.POST).build();
Tag tag1 = new Tag("third tag");
tag1 = tagRepository.save(tag1);
Tag tag2 = new Tag("fourth tag");
tag2 = tagRepository.save(tag2);
Post saved = postRepository.save(post);
saved.setTags(new HashSet<>());
saved.getTags().add(tag1);
saved.getTags().add(tag2);
assertEquals(saved.getTags().size(), 2);
postRepository.save(saved);
List<Post> posts = postRepository.findAllWithDetail();
Optional<Post> found = posts.stream().filter(p -> p.getPostId().equals(saved.getPostId())).findFirst();
if (found.isPresent()) {
assertEquals(found.get().getTags().size(), 2);
}
}
use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.
the class PostRepoTests method addTags.
@Test
public void addTags() {
Integer startTagCount = tagRepository.findAll().size();
Tag tag = new Tag("tag one");
tagRepository.save(tag);
tag = new Tag("tag two ");
tagRepository.save(tag);
Set<Tag> found = tagRepository.findAll();
assertEquals(found.size(), startTagCount + 2);
}
Aggregations