Search in sources :

Example 6 with TagDTO

use of com.nixmash.blog.jpa.dto.TagDTO in project nixmash-blog by mintster.

the class PostServiceImpl method saveNewTagsToDataBase.

@Transactional
private void saveNewTagsToDataBase(PostDTO postDTO) {
    for (TagDTO tagDTO : postDTO.getTags()) {
        Tag tag = tagRepository.findByTagValueIgnoreCase(tagDTO.getTagValue());
        if (tag == null) {
            tag = new Tag(tagDTO.getTagValue());
            tagRepository.save(tag);
        }
    }
}
Also used : TagDTO(com.nixmash.blog.jpa.dto.TagDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TagDTO (com.nixmash.blog.jpa.dto.TagDTO)6 Transactional (org.springframework.transaction.annotation.Transactional)3 CachePostUpdate (com.nixmash.blog.jpa.annotations.CachePostUpdate)2 PostDTO (com.nixmash.blog.jpa.dto.PostDTO)2 Post (com.nixmash.blog.jpa.model.Post)2 PostUtils.postDtoToPost (com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost)2 Test (org.junit.Test)2 CategoryNotFoundException (com.nixmash.blog.jpa.exceptions.CategoryNotFoundException)1 DuplicatePostNameException (com.nixmash.blog.jpa.exceptions.DuplicatePostNameException)1 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)1 TagNotFoundException (com.nixmash.blog.jpa.exceptions.TagNotFoundException)1 JsonRequestMapping (com.nixmash.blog.mvc.annotations.JsonRequestMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1