Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

태그 검색 조건 or로 변경 #836

Merged
merged 1 commit into from
Oct 21, 2024
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 @@ -103,10 +103,8 @@ private void addTagPredicate(
}
Subquery<Long> subquery = query.subquery(Long.class);
Root<TemplateTag> subRoot = subquery.from(TemplateTag.class);
subquery.select(subRoot.get("template").get("id")).where(subRoot.get("tag").get("id").in(tagIds))
.groupBy(subRoot.get("template").get("id"))
.having(criteriaBuilder.equal(criteriaBuilder.countDistinct(subRoot.get("tag").get("id")),
tagIds.size()));
subquery.select(subRoot.get("template").get("id"))
.where(subRoot.get("tag").get("id").in(tagIds));

predicates.add(root.get("id").in(subquery));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void testFindByCategoryId() {
}

@Test
@DisplayName("검색 테스트: 태그 ID 목록으로 템플릿 조회, 모든 태그를 가진 템플릿만 조회 성공")
@DisplayName("검색 테스트: 태그 ID 목록으로 템플릿 조회, 태그 중 하나라도 가진 템플릿 전체 조회 성공")
void testFindByTagIds() {
Tag tag1 = tagRepository.fetchById(1L);
Tag tag2 = tagRepository.fetchById(2L);
Expand All @@ -102,8 +102,9 @@ void testFindByTagIds() {
() -> assertThat(result.getContent())
.containsExactlyInAnyOrder(
templateRepository.fetchById(1L),
templateRepository.fetchById(2L)),
() -> assertThat(result.getContent()).hasSize(2)
templateRepository.fetchById(2L),
templateRepository.fetchById(3L)),
() -> assertThat(result.getContent()).hasSize(3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ void findAllSuccessByTagIds() {
() -> assertThat(actual.getContent())
.containsExactlyInAnyOrder(
templateRepository.fetchById(1L),
templateRepository.fetchById(2L)),
() -> assertThat(actual.getContent()).hasSize(2)
templateRepository.fetchById(2L),
templateRepository.fetchById(3L)),
() -> assertThat(actual.getContent()).hasSize(3)
);
}

Expand All @@ -188,7 +189,7 @@ void findAllSuccessBySingleTagId() {
Long memberId = null;
String keyword = null;
Long categoryId = null;
List<Long> tagIds = List.of(tag2.getId());
List<Long> tagIds = List.of(tag1.getId(), tag2.getId());
Visibility visibility = null;
Pageable pageable = PageRequest.of(0, 10);

Expand Down