NewsRepo.java 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.News;
  3. import com.izouma.nineth.dto.RecommendCollection;
  4. import com.izouma.nineth.dto.RecommendNews;
  5. import org.springframework.cache.annotation.CacheEvict;
  6. import org.springframework.data.jpa.repository.JpaRepository;
  7. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  8. import org.springframework.data.jpa.repository.Modifying;
  9. import org.springframework.data.jpa.repository.Query;
  10. import javax.transaction.Transactional;
  11. import java.util.List;
  12. public interface NewsRepo extends JpaRepository<News, Long>, JpaSpecificationExecutor<News> {
  13. @Query("update News t set t.del = true where t.id = ?1")
  14. @Modifying
  15. @Transactional
  16. void softDelete(Long id);
  17. @Query("update News t set t.likes = t.likes + ?2 where t.id = ?1")
  18. @Modifying
  19. @Transactional
  20. @CacheEvict(value = "news", key = "#id")
  21. void addLike(Long id, int num);
  22. @Query("select new com.izouma.nineth.dto.RecommendNews(n,r) from News n join Recommend r on n.id = r.collectionId " +
  23. "where n.del = false and r.type = ?1 and r.category = 'NEWS' order by r.sort desc")
  24. List<RecommendNews> recommend(String type);
  25. }