| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package com.izouma.nineth.repo;
- import com.izouma.nineth.domain.Collection;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.CachePut;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.data.jpa.repository.JpaRepository;
- import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
- import org.springframework.data.jpa.repository.Modifying;
- import org.springframework.data.jpa.repository.Query;
- import javax.annotation.Nonnull;
- import javax.transaction.Transactional;
- import java.time.LocalDateTime;
- import java.util.List;
- import java.util.Optional;
- public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
- @Query("update Collection t set t.del = true where t.id = ?1")
- @Modifying
- @Transactional
- @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
- void softDelete(Long id);
- @Cacheable("collection")
- Optional<Collection> findById(Long id);
- Optional<Collection> findByIdAndDelFalse(Long id);
- @Query("update Collection t set t.likes = t.likes + ?2 where t.id = ?1")
- @Modifying
- @Transactional
- void addLike(Long id, int num);
- @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
- "where l.userId = ?1 and l.del = false and c.del = false")
- List<Collection> userLikes(Long userId);
- List<Collection> findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime time);
- @Nonnull
- @CachePut(value = "collection", key = "#collection.id")
- @CacheEvict(value = {"recommend"})
- Collection save(@Nonnull Collection collection);
- @Query("select c from Collection c join Recommend r on c.id = r.collectionId " +
- "where c.del = false and c.onShelf = true order by r.sort desc")
- @Cacheable("recommend")
- List<Collection> recommend(String type);
- }
|