use of com.nixmash.blog.jpa.annotations.CachePostUpdate in project nixmash-blog by mintster.
the class PostServiceImpl method add.
// endregion
// region Add / UpdatePost
@Transactional(rollbackFor = DuplicatePostNameException.class)
@Override
@CachePostUpdate
public Post add(PostDTO postDTO) throws DuplicatePostNameException {
Post post;
try {
post = postRepository.save(PostUtils.postDtoToPost(postDTO));
em.refresh(post);
} catch (Exception e) {
throw new DuplicatePostNameException("Duplicate Post Name for Post Title: " + postDTO.getPostTitle());
}
if (postDTO.getTags() != null) {
saveNewTagsToDataBase(postDTO);
post.setTags(new HashSet<>());
for (TagDTO tagDTO : postDTO.getTags()) {
Tag tag = tagRepository.findByTagValueIgnoreCase(tagDTO.getTagValue());
post.getTags().add(tag);
}
}
Category category = categoryRepository.findByCategoryId(postDTO.getCategoryId());
post.setCategory(category);
return post;
}
use of com.nixmash.blog.jpa.annotations.CachePostUpdate in project nixmash-blog by mintster.
the class PostServiceImpl method update.
@Transactional(rollbackFor = PostNotFoundException.class)
@Override
@CachePostUpdate
public Post update(PostDTO postDTO) throws PostNotFoundException {
Post post = postRepository.findByPostId(postDTO.getPostId());
post.update(postDTO.getPostTitle(), postDTO.getPostContent(), postDTO.getIsPublished(), postDTO.getDisplayType());
saveNewTagsToDataBase(postDTO);
post.getTags().clear();
for (TagDTO tagDTO : postDTO.getTags()) {
Tag tag = tagRepository.findByTagValueIgnoreCase(tagDTO.getTagValue());
if (!post.getTags().contains(tag))
post.getTags().add(tag);
}
Category category = categoryRepository.findByCategoryId(postDTO.getCategoryId());
post.setCategory(category);
return post;
}
Aggregations