@@ -203,10 +203,20 @@ public PaymentSuccessHistoryPageDto viewAllSuccessTransaction(Long userId, int p
203203 .map (map ::get )
204204 .toList ();
205205
206+ List <String > orderIds = allSuccessPayments .stream ()
207+ .map (Payment ::getOrderId )
208+ .toList ();
209+
210+ Map <String , TossPayment > tossPaymentMap = tossPaymentRepository .findAllByOrderIds (orderIds )
211+ .stream ()
212+ .collect (Collectors .toMap (TossPayment ::getOrderId , t -> t ));
213+
206214 List <PaymentSuccessHistoryResponseDto > dtoList = allSuccessPayments .stream ()
207215 .map (payment -> {
208- TossPayment tossPayment = tossPaymentRepository .findByOrderId (payment .getOrderId ())
209- .orElseThrow (() -> new BusinessException (ErrorCode .INVALID_PAYMENT ));
216+ TossPayment tossPayment = tossPaymentMap .get (payment .getOrderId ());
217+ if (tossPayment == null ) {
218+ throw new BusinessException (ErrorCode .INVALID_PAYMENT );
219+ }
210220 return PaymentMapper .toPaymentSuccessHistoryResponseDto (payment , tossPayment );
211221 })
212222 .toList ();
@@ -219,7 +229,7 @@ public PaymentSuccessHistoryPageDto viewAllSuccessTransaction(Long userId, int p
219229
220230 @ Transactional (readOnly = true )
221231 public PaymentCancelHistoryPageDto viewAllFailureTransaction (Long userId , int page , int pageSize ) {
222- List <Long > paymentIds = paymentRepository .findPaymentIdsByUserAndStatus (userId ,
232+ List <Long > paymentIds = paymentRepository .findCancelledPaymentIdsByUserAndStatus (userId ,
223233 PaymentStatus .CANCELED .name (), (page - 1 ) * pageSize , pageSize );
224234
225235 if (paymentIds .isEmpty ()) {
@@ -233,10 +243,20 @@ public PaymentCancelHistoryPageDto viewAllFailureTransaction(Long userId, int pa
233243 .map (map ::get )
234244 .toList ();
235245
246+ List <String > orderIds = allFailurePayments .stream ()
247+ .map (Payment ::getOrderId )
248+ .toList ();
249+
250+ Map <String , TossPayment > tossPaymentMap = tossPaymentRepository .findAllByOrderIds (orderIds )
251+ .stream ()
252+ .collect (Collectors .toMap (TossPayment ::getOrderId , t -> t ));
253+
236254 List <PaymentCancelHistoryResponseDto > dtoList = allFailurePayments .stream ()
237255 .map (payment -> {
238- TossPayment tossPayment = tossPaymentRepository .findByOrderId (payment .getOrderId ())
239- .orElseThrow (() -> new BusinessException (ErrorCode .INVALID_PAYMENT ));
256+ TossPayment tossPayment = tossPaymentMap .get (payment .getOrderId ());
257+ if (tossPayment == null ) {
258+ throw new BusinessException (ErrorCode .INVALID_PAYMENT );
259+ }
240260 return PaymentMapper .toPaymentFailureHistoryResponseDto (payment , tossPayment );
241261 })
242262 .toList ();
0 commit comments