-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/242 커뮤니티 게시글 검색 조회 (RDB) #248
Changes from 4 commits
191134b
a676e59
cf9073b
941059f
739b914
a6d775c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ | |||||||||||||
import com.somemore.community.domain.QCommunityBoard; | ||||||||||||||
import com.somemore.volunteer.domain.QVolunteer; | ||||||||||||||
import lombok.RequiredArgsConstructor; | ||||||||||||||
import org.apache.commons.lang3.StringUtils; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일부러 이거 쓰신건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 범수님 코드 참고했는데 이렇게 StringUtils의 isNotBlank 사용해서 체크하셨던데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다~ 좋은 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isNotBlank 메서드가 null 체크, ""문자열 체크, " ", 공백 체크까지해서 자주 애용하고 있습니다 좋아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leebs0521 저희만의 유틸 인터페이스를 만들고 구현체에 아파치의 스트링 유틸을 사용하는 것은 과한걸까요? 갑자기 궁금해져서 여쭤봅니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @m-a-king 음... 그렇게 생각하신 이유가 있을까요?? 저는 일단 과하다라고 느껴지긴하네용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음 기회에... |
||||||||||||||
import org.springframework.data.domain.Page; | ||||||||||||||
import org.springframework.data.domain.Pageable; | ||||||||||||||
import org.springframework.data.support.PageableExecutionUtils; | ||||||||||||||
|
@@ -44,9 +45,10 @@ public Optional<CommunityBoard> findById(Long id) { | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
@Override | ||||||||||||||
public Page<CommunityBoardView> findCommunityBoards(Pageable pageable) { | ||||||||||||||
public Page<CommunityBoardView> findCommunityBoards(String keyword, Pageable pageable) { | ||||||||||||||
List<CommunityBoardView> content = getCommunityBoardsQuery() | ||||||||||||||
.where(isNotDeleted()) | ||||||||||||||
.where(isNotDeleted() | ||||||||||||||
.and(keywordEq(keyword))) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isNotDeleted가 앞에 있는건 혹시 조인 때문인건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keywordEq이 먼저 오는게 맞을 거 같아서 수정하겠습니다! |
||||||||||||||
.offset(pageable.getOffset()) | ||||||||||||||
.limit(pageable.getPageSize()) | ||||||||||||||
.fetch(); | ||||||||||||||
|
@@ -55,7 +57,8 @@ public Page<CommunityBoardView> findCommunityBoards(Pageable pageable) { | |||||||||||||
.select(communityBoard.count()) | ||||||||||||||
.from(communityBoard) | ||||||||||||||
.join(volunteer).on(communityBoard.writerId.eq(volunteer.id)) | ||||||||||||||
.where(isNotDeleted()); | ||||||||||||||
.where(isNotDeleted() | ||||||||||||||
.and(keywordEq(keyword))); | ||||||||||||||
|
||||||||||||||
return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne); | ||||||||||||||
} | ||||||||||||||
|
@@ -160,6 +163,12 @@ private BooleanExpression isNotDeleted() { | |||||||||||||
|
||||||||||||||
private BooleanExpression isWriter(UUID writerId) {return communityBoard.writerId.eq(writerId); } | ||||||||||||||
|
||||||||||||||
private BooleanExpression keywordEq(String keyword) { | ||||||||||||||
return StringUtils.isNotBlank(keyword) | ||||||||||||||
? communityBoard.title.containsIgnoreCase( | ||||||||||||||
keyword) : null; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
이렇게 쓸 수 있을 것 같아요~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null까지 다 한줄로 올리는게 나을까요 null은 내리는 게 나을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return에 삼항연산을 사용할 때, |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// private List<CommunityBoardDocument> getBoardDocuments(String keyword) { | ||||||||||||||
// | ||||||||||||||
// if (keyword == null || keyword.isEmpty()) { | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null이 조금 걸리는데 제가 했던 SearchCondition 이라는 Dto를 만들어서 Paging까지 같이 넣는거 어떻게 생각하시나요??
다른분들 의견도 궁금합니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
참고 코드
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 좋습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condition이 단순해보이는데 builder가 아니라 생성자를 이용하는건 어떨까요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌더 만들고 paging만 넣어두는 식으로 하면 괜찮을 것 같아요