diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java index 88c30577..6e08539b 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java @@ -52,11 +52,11 @@ public List findAllByTypeAndFieldAndSearch( eqContestType(contestType) .and(eqContestField(contestFieldId)) .and( - titleLike(search) - .or(contentLike(search)) - .or(writerNameLike(search)) - .or(associationLike(search)) - .or(topicLike(search))); + likeTitle(search) + .or(likeContent(search)) + .or(likeWriterName(search)) + .or(likeAssociation(search)) + .or(likeTopic(search))); OrderSpecifier orderBy = getOrderBy(sortBy); @@ -118,27 +118,23 @@ private BooleanExpression eqContestField(Long contestFieldId) { return contestBoard.contestField.id.eq(contestFieldId); } - private BooleanExpression titleLike(String search) { - return hasText(search) ? contestBoard.title.value.containsIgnoreCase(search) : null; + private BooleanExpression likeTitle(String search) { + return contestBoard.title.value.like("%" + search + "%"); } - private BooleanExpression contentLike(String search) { - return hasText(search) ? contestBoard.content.value.containsIgnoreCase(search) : null; + private BooleanExpression likeContent(String search) { + return contestBoard.content.value.like("%" + search + "%"); } - private BooleanExpression writerNameLike(String search) { - return hasText(search) ? contestBoard.writer.name.value.containsIgnoreCase(search) : null; + private BooleanExpression likeWriterName(String search) { + return contestBoard.writer.name.value.like("%" + search + "%"); } - private BooleanExpression associationLike(String search) { - return hasText(search) ? contestBoard.association.value.containsIgnoreCase(search) : null; + private BooleanExpression likeAssociation(String search) { + return contestBoard.association.value.like("%" + search + "%"); } - private BooleanExpression topicLike(String search) { - return hasText(search) ? contestBoard.topic.value.containsIgnoreCase(search) : null; - } - - private Boolean hasText(String text) { - return text != null && !text.trim().isEmpty(); + private BooleanExpression likeTopic(String search) { + return contestBoard.association.value.like("%" + search + "%"); } } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java index 7d72e855..af56f778 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImplTest.java @@ -28,6 +28,7 @@ import com.inhabas.api.domain.contest.dto.ContestBoardDto; import com.inhabas.api.domain.contest.dto.SaveContestBoardDto; import com.inhabas.api.domain.contest.repository.ContestBoardRepository; +import com.inhabas.api.domain.contest.repository.ContestFieldRepository; import com.inhabas.api.domain.file.dto.FileDownloadDto; import com.inhabas.api.domain.file.usecase.S3Service; import com.inhabas.api.domain.member.domain.entity.MemberTest; @@ -49,6 +50,8 @@ public class ContestBoardServiceImplTest { @Mock private ContestBoardRepository contestBoardRepository; + @Mock private ContestFieldRepository contestFieldRepository; + @Mock private MemberRepository memberRepository; @Mock private MenuRepository menuRepository; @@ -125,9 +128,12 @@ void getContestBoard() { void writeContestBoard() { // given Member member = MemberTest.chiefMember(); + + ContestField contestField = ContestField.builder().name("빅데이터").build(); + ReflectionTestUtils.setField(contestField, "id", 1L); SaveContestBoardDto saveContestBoardDto = SaveContestBoardDto.builder() - .contestFieldId(1L) + .contestFieldId(contestField.getId()) .title("테스트 제목") .content("테스트 내용") .association("(주) 아이바스") @@ -137,7 +143,6 @@ void writeContestBoard() { .files(null) .build(); - ContestField contestField = ContestField.builder().name("빅데이터").build(); Menu menu = getContestMenu(getContestMenuGroup()); ContestBoard contestBoard = ContestBoard.builder() @@ -154,6 +159,8 @@ void writeContestBoard() { given(memberRepository.findById(any())).willReturn(Optional.of(member)); given(contestBoardRepository.save(any())).willReturn(contestBoard); + given(contestFieldRepository.findById(contestField.getId())) + .willReturn(Optional.of(contestField)); given(menuRepository.findById(anyInt())).willReturn(Optional.of(menu)); // when