Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ Optional<ExamTicketInfoProjection> findExamTicketInfoProjectionById(
FROM ExamApplicationJpaEntity ea
JOIN PaymentJpaEntity p ON p.examApplicationId = ea.id
LEFT JOIN RefundJpaEntity r ON r.examApplicationId = ea.id
WHERE p.paymentStatus = 'DONE'
AND (r IS NULL OR r.refundStatus = 'DONE')
WHERE (p.paymentStatus = 'DONE' OR r.refundStatus = 'DONE')
AND ea.applicationId IN :applicationIds
AND ea.deleted = false
""")
Comment on lines +92 to 95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Avoid OR on a LEFT-joined table to prevent row multiplication; add p.deleted filter for consistency

Using OR with a column from the LEFT join (Line 92) will include all rows where p.paymentStatus = 'DONE' even when there are multiple Refund rows with non-DONE statuses, multiplying results per application. It also broadens semantics to include cases where payment is not DONE but refund is DONE (intentional?), and misses the common p.deleted = false guard used elsewhere in this repository.

Refactor to use EXISTS for the refund condition and restore the p.deleted = false consistency. This prevents duplicates and keeps semantics explicit.

Apply this diff within the current query:

-            WHERE (p.paymentStatus = 'DONE' OR r.refundStatus = 'DONE')
-            AND ea.applicationId IN :applicationIds
-            AND ea.deleted = false
+            WHERE ea.applicationId IN :applicationIds
+            AND ea.deleted = false
+            AND (
+                (p.paymentStatus = 'DONE' AND p.deleted = false)
+                OR EXISTS (
+                    SELECT 1 FROM RefundJpaEntity r2
+                    WHERE r2.examApplicationId = ea.id
+                    AND r2.refundStatus = 'DONE'
+                )
+            )

Additionally, since the refund condition is evaluated via EXISTS, the LEFT JOIN to Refund is no longer needed and can be removed to simplify the query and avoid accidental fan-out:

// Outside the selected lines (optional cleanup)
JOIN PaymentJpaEntity p ON p.examApplicationId = ea.id
-- remove: LEFT JOIN RefundJpaEntity r ON r.examApplicationId = ea.id

If the broadened inclusion of “refund-done even if payment not done” is intentional, the EXISTS keeps that behavior without duplicating rows. If not intentional, consider reverting to the stricter semantics.

🤖 Prompt for AI Agents
src/main/java/life/mosu/mosuserver/domain/examapplication/repository/ExamApplicationJpaRepository.java
around lines 92-95: the query uses "WHERE (p.paymentStatus = 'DONE' OR
r.refundStatus = 'DONE')" with a LEFT JOIN to Refund, which can multiply rows
and omits the p.deleted guard. Replace the OR with an EXISTS subquery that
checks for a Refund row with refundStatus = 'DONE' and deleted = false for the
same exam application, restore the p.deleted = false condition and make the
Payment join an inner JOIN (JOIN PaymentJpaEntity p ON p.examApplicationId =
ea.id) so the payment filter applies consistently, and remove the LEFT JOIN to
Refund entirely to avoid fan-out.

List<ExamApplicationWithStatus> findByApplicationIdIn(List<Long> applicationIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public record InquiryCreateRequest(
@Size(max = 1000, message = "본문은 최대 1000자까지 입력 가능합니다.")
@Schema(description = "문의 내용", example = "포인트는 어떻게 사용하나요?")
@NotNull String content,

@Size(max = 3, message = "첨부파일은 최대 3개까지 첨부할 수 있습니다.")
List<FileRequest> attachments
) {

Expand Down