Skip to content

Commit f475dc5

Browse files
authored
refactor: 쿼리 관련 리팩토링 (#172)
1 parent 3466e76 commit f475dc5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/com/threestar/trainus/domain/payment/repository/PaymentRepository.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ List<Long> findPaymentIdsByUserAndStatus(
3535
@Param("limit") int limit
3636
);
3737

38+
@Query(value = """
39+
SELECT p.id FROM payments p
40+
WHERE p.user_id = :userId
41+
AND p.status = :status
42+
ORDER BY p.cancelled_at DESC
43+
LIMIT :limit OFFSET :offset
44+
""", nativeQuery = true)
45+
List<Long> findCancelledPaymentIdsByUserAndStatus(
46+
@Param("userId") Long userId,
47+
@Param("status") String status,
48+
@Param("offset") int offset,
49+
@Param("limit") int limit
50+
);
51+
3852
@Query("""
3953
SELECT p FROM Payment p
4054
LEFT JOIN FETCH p.lesson
41-
LEFT JOIN FETCH p.userCoupon
4255
WHERE p.id IN :ids
4356
""")
4457
List<Payment> findAllWithAssociationsByIds(@Param("ids") List<Long> ids);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package com.threestar.trainus.domain.payment.repository;
22

3+
import java.util.List;
34
import java.util.Optional;
45

56
import org.springframework.data.jpa.repository.JpaRepository;
7+
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.data.repository.query.Param;
69

710
import com.threestar.trainus.domain.payment.entity.TossPayment;
811

912
public interface TossPaymentRepository extends JpaRepository<TossPayment, Long> {
1013

1114
Optional<TossPayment> findByOrderId(String orderId);
15+
16+
@Query("""
17+
SELECT t FROM TossPayment t
18+
WHERE t.orderId IN :orderIds
19+
""")
20+
List<TossPayment> findAllByOrderIds(@Param("orderIds") List<String> orderIds);
1221
}

0 commit comments

Comments
 (0)