Skip to content

Commit

Permalink
[feat #86] 필터링 쿼리 검색키워드 조건 추가 (#87)
Browse files Browse the repository at this point in the history
* feat : Search Condition 검색 키워드 필드 추

* feat : 쿼리에 검색 키워드 조건 추가

* feat : Search Condition 검색 키워드 필드 추가
  • Loading branch information
dlswns2480 authored Aug 12, 2024
1 parent c2a03bd commit fa5c8ac
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ data class ContentSearchParams(
val startDate: LocalDate?,
@DateTimeFormat(pattern = "yyyy.MM.dd")
val endDate: LocalDate?,
val categoryIds: List<Long>?
val categoryIds: List<Long>?,
val searchWord: String?
)

internal fun ContentSearchParams.toDto() = ContentSearchCondition(
Expand All @@ -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
)
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand All @@ -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
}
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class ContentFixture {
favorites = null,
startDate = null,
endDate = null,
categoryIds = null
categoryIds = null,
searchWord = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +16,9 @@ import io.mockk.mockk

class UserServiceTest : BehaviorSpec({
val userPort = mockk<UserPort>()
val userService = UserService(userPort)
val categoryPort = mockk<CategoryPort>()
val categoryImagePort = mockk<CategoryImagePort>()
val userService = UserService(userPort, categoryPort, categoryImagePort)
Given("회원을 등록할 때") {
val user = UserFixture.getUser()
val invalidUser = UserFixture.getInvalidUser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ data class ContentSearchCondition(
val favorites: Boolean?,
val startDate: LocalDate?,
val endDate: LocalDate?,
val categoryIds: List<Long>?
val categoryIds: List<Long>?,
val searchWord: String?
)

0 comments on commit fa5c8ac

Please sign in to comment.