RiceRepo.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.izouma.nineth.repo;
  2. import com.izouma.nineth.domain.Rice;
  3. import io.lettuce.core.dynamic.annotation.Param;
  4. import org.springframework.data.jpa.repository.JpaRepository;
  5. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  6. import org.springframework.data.jpa.repository.Modifying;
  7. import org.springframework.data.jpa.repository.Query;
  8. import javax.transaction.Transactional;
  9. import java.util.List;
  10. import java.util.Optional;
  11. public interface RiceRepo extends JpaRepository<Rice, Long>, JpaSpecificationExecutor<Rice> {
  12. @Query("update Rice t set t.del = true where t.id = ?1")
  13. @Modifying
  14. @Transactional
  15. void softDelete(Long id);
  16. @Query(value = "select * from rice where user_id = ?1 ", nativeQuery = true)
  17. Optional<Rice> findByUserId(Long userId);
  18. @Query("update Rice t set t.nickname = ?2 where t.userId = ?1")
  19. @Modifying
  20. @Transactional
  21. void updateNickName(String userId, String nickname);
  22. @Query("SELECT COUNT(r) + 1 FROM Rice r WHERE r.selfScore > :score")
  23. Integer findRankByScore(@Param("score") Long score);
  24. List<Rice> findTop100ByOrderBySelfScoreDesc();
  25. }