CollectionRepo.java 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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.time.LocalDateTime;
  9. import java.util.List;
  10. import java.util.Optional;
  11. public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
  12. @Query("update Collection t set t.del = true where t.id = ?1")
  13. @Modifying
  14. @Transactional
  15. void softDelete(Long id);
  16. Optional<Collection> findByIdAndDelFalse(Long id);
  17. @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
  18. @Modifying
  19. @Transactional
  20. void addLike(Long id, int num);
  21. @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
  22. "where l.userId = ?1 and l.del = false and c.del = false")
  23. List<Collection> userLikes(Long userId);
  24. List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
  25. }