CollectionRepo.java 1.1 KB

1234567891011121314151617181920212223242526272829
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.Collection;
  3. import org.springframework.data.jpa.repository.JpaRepository;
  4. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  5. import org.springframework.data.jpa.repository.Modifying;
  6. import org.springframework.data.jpa.repository.Query;
  7. import javax.transaction.Transactional;
  8. import java.util.List;
  9. import java.util.Optional;
  10. public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
  11. @Query("update Collection t set t.del = true where t.id = ?1")
  12. @Modifying
  13. @Transactional
  14. void softDelete(Long id);
  15. Optional<Collection> findByIdAndDelFalse(Long id);
  16. @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
  17. @Modifying
  18. @Transactional
  19. void addLike(Long id, int num);
  20. @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
  21. "where l.userId = ?1 and l.del = false and c.del = false")
  22. List<Collection> userLikes(Long userId);
  23. }