From fa5c8ac2a83d4b5a7c5b82ba17452216b4b42e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:14:20 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#86]=20=ED=95=84=ED=84=B0=EB=A7=81=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EA=B2=80=EC=83=89=ED=82=A4=EC=9B=8C?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : Search Condition 검색 키워드 필드 추 * feat : 쿼리에 검색 키워드 조건 추가 * feat : Search Condition 검색 키워드 필드 추가 --- .../content/dto/request/ContentSearchParams.kt | 6 ++++-- .../out/persistence/content/impl/ContentAdapter.kt | 12 ++++++++++-- .../persistence/content/impl/ContentAdapterTest.kt | 13 ++++++++++++- .../kotlin/com/pokit/content/ContentFixture.kt | 3 ++- .../pokit/content/port/service/ContentService.kt | 11 +++-------- .../com/pokit/user/port/service/UserServiceTest.kt | 7 +++++-- .../content/dto/request/ContentSearchCondition.kt | 3 ++- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/ContentSearchParams.kt b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/ContentSearchParams.kt index f9fb4d90..d12369b1 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/ContentSearchParams.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/request/ContentSearchParams.kt @@ -11,7 +11,8 @@ data class ContentSearchParams( val startDate: LocalDate?, @DateTimeFormat(pattern = "yyyy.MM.dd") val endDate: LocalDate?, - val categoryIds: List? + val categoryIds: List?, + val searchWord: String? ) internal fun ContentSearchParams.toDto() = ContentSearchCondition( @@ -20,5 +21,6 @@ internal fun ContentSearchParams.toDto() = ContentSearchCondition( favorites = this.favorites, startDate = this.startDate, endDate = this.endDate, - categoryIds = this.categoryIds + categoryIds = this.categoryIds, + searchWord = this.searchWord ) diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/content/impl/ContentAdapter.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/content/impl/ContentAdapter.kt index 9c2496db..9f2bb1c6 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/content/impl/ContentAdapter.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/content/impl/ContentAdapter.kt @@ -1,7 +1,7 @@ package com.pokit.out.persistence.content.impl -import com.pokit.content.dto.response.ContentsResult import com.pokit.content.dto.request.ContentSearchCondition +import com.pokit.content.dto.response.ContentsResult import com.pokit.content.model.Content import com.pokit.content.port.out.ContentPort import com.pokit.log.model.LogType @@ -73,7 +73,8 @@ class ContentAdapter( isUnread(condition.isRead), contentEntity.deleted.isFalse, dateBetween(condition.startDate, condition.endDate), - categoryIn(condition.categoryIds) + categoryIn(condition.categoryIds), + containsWord(condition.searchWord) ) .offset(pageable.offset) .groupBy(contentEntity) @@ -231,4 +232,11 @@ class ContentAdapter( property.desc() } } + + private fun containsWord(searchWord: String?): Predicate? { + return searchWord?.let { + contentEntity.title.contains(searchWord) + .or(contentEntity.memo.contains(searchWord)) + } + } } diff --git a/adapters/out-persistence/src/test/kotlin/com/pokit/out/persistence/content/impl/ContentAdapterTest.kt b/adapters/out-persistence/src/test/kotlin/com/pokit/out/persistence/content/impl/ContentAdapterTest.kt index e2053094..53ea0ef4 100644 --- a/adapters/out-persistence/src/test/kotlin/com/pokit/out/persistence/content/impl/ContentAdapterTest.kt +++ b/adapters/out-persistence/src/test/kotlin/com/pokit/out/persistence/content/impl/ContentAdapterTest.kt @@ -160,7 +160,7 @@ class ContentAdapterTest( ) val savedAnotherCategory = categoryRepository.save(CategoryEntity.of(anotherCategory)) - val content3 = ContentFixture.getContent(savedAnotherCategory.id) + val content3 = ContentFixture.getContent(savedAnotherCategory.id).copy(title = "제목3의 컨텐츠") contentRepository.save(ContentEntity.of(content3)) @@ -183,6 +183,17 @@ class ContentAdapterTest( result.content.size shouldBe 3 } } + When("키워드로 검색할 떄") { + val result = contentAdapter.loadAllByUserIdAndContentId( + savedUser.id, + condition.copy(categoryId = null, searchWord = content3.title), + pageRequest + ) + Then("해당 키워드를 제목이나 메모에 포함하는 컨텐츠들이 조회된다.") { + result.content.size shouldBe 1 + result.content[0].title shouldBe content3.title + } + } } diff --git a/adapters/out-persistence/src/testFixtures/kotlin/com/pokit/content/ContentFixture.kt b/adapters/out-persistence/src/testFixtures/kotlin/com/pokit/content/ContentFixture.kt index 05728a16..f4750b99 100644 --- a/adapters/out-persistence/src/testFixtures/kotlin/com/pokit/content/ContentFixture.kt +++ b/adapters/out-persistence/src/testFixtures/kotlin/com/pokit/content/ContentFixture.kt @@ -62,7 +62,8 @@ class ContentFixture { favorites = null, startDate = null, endDate = null, - categoryIds = null + categoryIds = null, + searchWord = null ) } } diff --git a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt index 807c79f8..1d659b33 100644 --- a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt +++ b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt @@ -5,18 +5,12 @@ import com.pokit.bookmark.port.out.BookmarkPort import com.pokit.category.exception.CategoryErrorCode import com.pokit.category.model.Category import com.pokit.category.model.RemindCategory -import com.pokit.category.model.toRemindCategory import com.pokit.category.port.out.CategoryPort -import com.pokit.category.port.service.loadCategoryOrThrow import com.pokit.common.exception.NotFoundCustomException import com.pokit.content.dto.request.ContentCommand +import com.pokit.content.dto.request.ContentSearchCondition import com.pokit.content.dto.request.toDomain import com.pokit.content.dto.response.* -import com.pokit.content.dto.response.ContentsResult -import com.pokit.content.dto.request.ContentSearchCondition -import com.pokit.content.dto.response.BookMarkContentResponse -import com.pokit.content.dto.response.GetContentResponse -import com.pokit.content.dto.response.toGetContentResponse import com.pokit.content.exception.ContentErrorCode import com.pokit.content.model.Content import com.pokit.content.port.`in`.ContentUseCase @@ -126,7 +120,8 @@ class ContentService( favorites = null, startDate = null, endDate = null, - categoryIds = null + categoryIds = null, + searchWord = null ) val unreadContents = contentPort.loadAllByUserIdAndContentId(userId, contentSearchCondition, pageable) diff --git a/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt b/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt index c5d11e50..1ef6bd3f 100644 --- a/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt +++ b/application/src/test/kotlin/com/pokit/user/port/service/UserServiceTest.kt @@ -1,7 +1,8 @@ package com.pokit.user.port.service +import com.pokit.category.port.out.CategoryImagePort +import com.pokit.category.port.out.CategoryPort import com.pokit.common.exception.ClientValidationException -import com.pokit.common.exception.NotFoundCustomException import com.pokit.token.model.AuthPlatform import com.pokit.user.UserFixture import com.pokit.user.dto.request.UpdateNicknameRequest @@ -15,7 +16,9 @@ import io.mockk.mockk class UserServiceTest : BehaviorSpec({ val userPort = mockk() - val userService = UserService(userPort) + val categoryPort = mockk() + val categoryImagePort = mockk() + val userService = UserService(userPort, categoryPort, categoryImagePort) Given("회원을 등록할 때") { val user = UserFixture.getUser() val invalidUser = UserFixture.getInvalidUser() diff --git a/domain/src/main/kotlin/com/pokit/content/dto/request/ContentSearchCondition.kt b/domain/src/main/kotlin/com/pokit/content/dto/request/ContentSearchCondition.kt index 1ebbf711..6a9ddd14 100644 --- a/domain/src/main/kotlin/com/pokit/content/dto/request/ContentSearchCondition.kt +++ b/domain/src/main/kotlin/com/pokit/content/dto/request/ContentSearchCondition.kt @@ -8,5 +8,6 @@ data class ContentSearchCondition( val favorites: Boolean?, val startDate: LocalDate?, val endDate: LocalDate?, - val categoryIds: List? + val categoryIds: List?, + val searchWord: String? )