diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java index 9056c654..3a3eaf28 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/controller/StudyPostController.java @@ -87,7 +87,7 @@ public ResponseEntity 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) diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java index dd4d2219..572c32de 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/studypost/repository/StudyPostRepositoryImpl.java @@ -49,7 +49,8 @@ public List 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); @@ -181,8 +182,21 @@ public List 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) {