Skip to content

Commit

Permalink
Merge pull request #91 from study-hub-inu/feat/SH-320-post-inquery
Browse files Browse the repository at this point in the history
[Feat] : 제목 or 전공 검색만 되게 + where 후위 와일드 카드 변경
  • Loading branch information
wellbeing-dough authored Feb 16, 2024
2 parents 04455f0 + 8d263b2 commit 43d9734
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ResponseEntity<FindPostResponseByUserId> getMyPosts(@RequestParam int pag
@Operation(summary = "스터디 게시글 전체 조회", description = "parameter 칸에 조회할 내용을 입력해주세요")
@ApiImplicitParams({
@ApiImplicitParam(name = "inquiry", value = "검색 값"),
@ApiImplicitParam(name = "titleAndMajor", value = "true = 제목, 학과 중 하나만 일치할 경우, false = 학과만 일치"),
@ApiImplicitParam(name = "titleAndMajor", value = "true = 제목만 일치, false = 학과만 일치"),
@ApiImplicitParam(name = "hot", value = "true = 인기순 O, false = 인기순 X"),
@ApiImplicitParam(name = "page", value = "페이지", required = true),
@ApiImplicitParam(name = "size", value = "사이즈", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public List<PostDataByInquiry> findByInquiry(final InquiryRequest inquiryRequest
))
.from(studyPostEntity)
.leftJoin(userEntity).on(studyPostEntity.postedUserId.eq(userEntity.id))
.where(textEq(inquiryRequest.getInquiryText()).or(majorEq(inquiryRequest.getInquiryText(), inquiryRequest.isTitleAndMajor())))
.where(textEqMajorOrTitle(inquiryRequest.getInquiryText(), inquiryRequest.isTitleAndMajor()))
// .where(textEq(inquiryRequest.getInquiryText(), inquiryRequest.isTitleAndMajor()).or(majorEq(inquiryRequest.getInquiryText(), inquiryRequest.isTitleAndMajor())))
.orderBy(studyPostEntity.close.asc(), hotPredicate(inquiryRequest), studyPostEntity.createdDate.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1);
Expand Down Expand Up @@ -181,8 +182,21 @@ public List<PostDataByMajor> findByMajor(MajorType major, Long exceptPostId) {
return data.fetch();
}

private BooleanExpression textEq(String inquiryText) {
return studyPostEntity.title.contains(Objects.requireNonNullElse(inquiryText, ""));

private Predicate textEqMajorOrTitle(String inquiryText, boolean titleAndMajor) {
if (inquiryText != null && !titleAndMajor) {
return studyPostEntity.major.eq(MajorType.findMajorType(inquiryText));
} else {
return studyPostEntity.title.like(Objects.requireNonNullElse(inquiryText, "") + "%");
}
}

private BooleanExpression textEq(String inquiryText, boolean titleAndMajor) {
if (!titleAndMajor) {
return studyPostEntity.title.contains(Objects.requireNonNullElse(inquiryText, ""));
}
return null;
// return studyPostEntity.title.contains(Objects.requireNonNullElse(inquiryText, ""));
}

private Predicate majorEq(String inquiryText, boolean titleAndMajor) {
Expand Down

0 comments on commit 43d9734

Please sign in to comment.