Skip to content

Commit 09da5b3

Browse files
committed
[Refactor]: 익명 게시글은 검색이 되지 않게 수정
1 parent 09521d4 commit 09da5b3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

back/src/main/java/com/back/domain/post/repository/PostRepositoryCustomImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public Page<Post> searchPosts(PostSearchCondition condition, Pageable pageable)
3030
.selectFrom(post)
3131
.leftJoin(post.user, user).fetchJoin()
3232
.where(getCategoryCondition(condition.category()),
33-
getSearchCondition(condition.keyword(), condition.searchType()))
33+
getSearchCondition(condition.keyword(), condition.searchType()),
34+
excludeHiddenIfSearch(condition.keyword(), condition.searchType()))
3435
.orderBy(post.createdDate.desc())
3536
.offset(pageable.getOffset())
3637
.limit(pageable.getPageSize())
@@ -41,7 +42,8 @@ public Page<Post> searchPosts(PostSearchCondition condition, Pageable pageable)
4142
.from(post)
4243
.where(
4344
getCategoryCondition(condition.category()),
44-
getSearchCondition(condition.keyword(), condition.searchType())
45+
getSearchCondition(condition.keyword(), condition.searchType()),
46+
excludeHiddenIfSearch(condition.keyword(), condition.searchType())
4547
);
4648

4749
return PageableExecutionUtils.getPage(posts, pageable, count::fetchOne);
@@ -71,4 +73,11 @@ private BooleanExpression getSearchCondition(String searchKeyword, SearchType se
7173
case AUTHOR -> post.user.nickname.containsIgnoreCase(searchKeyword);
7274
};
7375
}
76+
77+
private BooleanExpression excludeHiddenIfSearch(String searchKeyword, SearchType searchType) {
78+
if (!StringUtils.hasText(searchKeyword) || searchType == null) {
79+
return null;
80+
}
81+
return post.hide.eq(false);
82+
}
7483
}

back/src/test/java/com/back/domain/post/controller/PostControllerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void createPosts() {
244244
.content("내용 " + i)
245245
.category(i % 2 == 0 ? PostCategory.SCENARIO : PostCategory.CHAT)
246246
.user(testUser)
247+
.hide(i % 2 == 0)
247248
.build();
248249
postRepository.save(post);
249250
}
@@ -259,7 +260,7 @@ void successWithDefaultParameters() throws Exception {
259260
}
260261

261262
@Test
262-
@DisplayName("성공 - 카테고리 필터링")
263+
@DisplayName("성공 - 카테고리 필터링, 익명은 검색되지 않아야 한다.")
263264
void successWithCategoryFilter() throws Exception {
264265
mockMvc.perform(get("/api/v1/posts")
265266
.param("category", PostCategory.SCENARIO.name()))
@@ -276,7 +277,7 @@ void successWithTitleContentSearch() throws Exception {
276277
.param("searchType", "TITLE_CONTENT")
277278
.param("keyword", "게시글"))
278279
.andExpect(status().isOk())
279-
.andExpect(jsonPath("$.items.length()").value(5));
280+
.andExpect(jsonPath("$.items.length()").value(3));
280281
}
281282

282283
@Test

0 commit comments

Comments
 (0)