Skip to content

Comments

[SCRUM-312] 코스 요약 조회의 즐길거리 조회 쿼리 수정 (#144)#146

Merged
ssggii merged 2 commits intomainfrom
SCRUM-312-코스-요약-조회-API-수정
Sep 25, 2025

Hidden character warning

The head ref may contain hidden characters: "SCRUM-312-\ucf54\uc2a4-\uc694\uc57d-\uc870\ud68c-API-\uc218\uc815"
Merged

[SCRUM-312] 코스 요약 조회의 즐길거리 조회 쿼리 수정 (#144)#146
ssggii merged 2 commits intomainfrom
SCRUM-312-코스-요약-조회-API-수정

Conversation

@ssggii
Copy link
Contributor

@ssggii ssggii commented Sep 24, 2025

✏️ 연관 이슈

#144

⛳ 작업 내용

  • spotRepository.findRandom3ByCourseId 쿼리 수정
  • 관련 테스트 코드 점검
  • swagger 테스트

💬리뷰 요구사항

.

📍 참고사항

.

LEFT JOIN을 INNER JOIN으로 변경하여 이미지가 있는 즐길거리 중에서 랜덤으로 3개만 조회하도록 쿼리를 수정했습니다.
@ssggii ssggii added this to the #8-sprint milestone Sep 24, 2025
@ssggii ssggii requested a review from moonxxpower September 24, 2025 06:26
@ssggii ssggii self-assigned this Sep 24, 2025
@ssggii ssggii moved this to In Progress in Runchuck-러닝한다이 Sep 24, 2025
Copy link
Member

@moonxxpower moonxxpower left a comment

Choose a reason for hiding this comment

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

확인했습니다 👍

혹시 즐길거리 이미지가 아예 없는 경우, 빈 값으로 응답하는 것을 방지하기 위해 아래와 같이 쿼리 작성하면 어떨까요? 해당 상황이 거의 없을 것 같긴한데 만약에 모든 즐길거리에 이미지가 없는 코스가 있다면 즐길거리가 있더라도 요약 조회에서 빈 값으로 반환될거 같아서요!

SELECT
    s.spot_id AS spotId,
    s.name,
    s.description,
    si.img_url AS imageUrl
FROM
    spot s
JOIN
    course_spot cs ON s.spot_id = cs.spot_id
LEFT JOIN
    spot_image si ON s.spot_id = si.spot_id
WHERE
    cs.course_id = :courseId
ORDER BY
    (si.img_url IS NOT NULL) DESC,
    RAND()
LIMIT 3

기존 쿼리는 모든 즐길거리의 이미지가 없는 경우, 즐길거리가 존재하더라도 빈 데이터를 반환하는 문제가 있었습니다.

해당 문제를 해결하기 위해 spot_image 테이블을 LEFT JOIN으로 묶고, ORDER BY를 사용하여 이미지가 있는 즐길거리부터 우선적으로 반환하도록 수정했습니다. 이를 통해 모든 즐길거리의 이미지가 없는 경우에도 항상 데이터를 반환하여 API 안정성을 높였습니다.
@ssggii
Copy link
Contributor Author

ssggii commented Sep 25, 2025

좋은 의견 감사합니다! 그 엣지 케이스를 고려 못했네요.
LEFT JOIN으로 모든 즐길거리를 포함시키고, ORDER BY로 이미지가 있는 데이터부터 보여주는 방식으로 수정해놓을게요👍
수정 후에 바로 merge 하겠습니다!

@ssggii ssggii merged commit 2f2d57a into main Sep 25, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Runchuck-러닝한다이 Sep 25, 2025
@ssggii ssggii deleted the SCRUM-312-코스-요약-조회-API-수정 branch September 25, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants