Skip to content

Commit

Permalink
refactor: 쿼리 multiline string으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
donghoony committed Aug 11, 2024
1 parent e29150a commit 6241cdc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

public interface OptionItemRepository extends JpaRepository<OptionItem, Long> {

@Query(value = "" +
"SELECT o.id FROM option_item o " +
"LEFT JOIN checkbox_answer ca " +
"LEFT JOIN checkbox_answer_selected_option c " +
"ON c.checkbox_answer_id = ca.id " +
"WHERE ca.review_id = :reviewId " +
"AND c.selected_option_id = o.id",
nativeQuery = true)
@Query(value = """
SELECT o.id FROM option_item o
LEFT JOIN checkbox_answer ca
LEFT JOIN checkbox_answer_selected_option c
ON c.checkbox_answer_id = ca.id
WHERE ca.review_id = :reviewId
AND c.selected_option_id = o.id
""", nativeQuery = true)
Set<Long> findSelectedOptionItemIdsByReviewId(long reviewId);

@Query(value = "" +
"SELECT o.* FROM option_item o " +
"LEFT JOIN checkbox_answer ca " +
"LEFT JOIN checkbox_answer_selected_option c " +
"ON c.checkbox_answer_id = ca.id " +
"WHERE ca.review_id = :reviewId " +
"AND ca.question_id = :questionId " +
"AND c.selected_option_id = o.id " +
"ORDER BY o.position",
nativeQuery = true)
@Query(value = """
SELECT o.* FROM option_item o
LEFT JOIN checkbox_answer ca
LEFT JOIN checkbox_answer_selected_option c
ON c.checkbox_answer_id = ca.id
WHERE ca.review_id = :reviewId
AND ca.question_id = :questionId
AND c.selected_option_id = o.id
ORDER BY o.position ASC
""", nativeQuery = true)
List<OptionItem> findSelectedOptionItemsByReviewIdAndQuestionId(long reviewId, long questionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

public interface QuestionRepository2 extends JpaRepository<Question2, Long> {

@Query(value = "" +
"SELECT q.* FROM question2 q " +
"LEFT JOIN section_question sq " +
"ON sq.question_id = q.id " +
"WHERE sq.section_id = :sectionId " +
"ORDER BY q.position ASC",
nativeQuery = true
)
@Query(value = """
SELECT q.* FROM question2 q
LEFT JOIN section_question sq
ON sq.question_id = q.id
WHERE sq.section_id = :sectionId
ORDER BY q.position ASC
""", nativeQuery = true)
List<Question2> findAllBySectionId(long sectionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

public interface SectionRepository extends JpaRepository<Section, Long> {

@Query(value = "" +
"SELECT s.* FROM section s LEFT JOIN template_section ts " +
"ON ts.section_id = s.id " +
"WHERE ts.template_id = :templateId " +
"ORDER BY s.position ASC",
nativeQuery = true
)
@Query(value = """
SELECT s.* FROM section s LEFT JOIN template_section ts
ON ts.section_id = s.id
WHERE ts.template_id = :templateId
ORDER BY s.position ASC
""", nativeQuery = true)
List<Section> findAllByTemplateId(long templateId);
}

0 comments on commit 6241cdc

Please sign in to comment.