mirror of https://github.com/usbharu/Hideout.git
feat: FilterなどにtoStringとequalsを実装
This commit is contained in:
parent
b52839192c
commit
d2b69b162a
|
@ -82,6 +82,16 @@ class Filter(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int = id.hashCode()
|
override fun hashCode(): Int = id.hashCode()
|
||||||
|
override fun toString(): String {
|
||||||
|
return "Filter(" +
|
||||||
|
"id=$id, " +
|
||||||
|
"userDetailId=$userDetailId, " +
|
||||||
|
"name=$name, " +
|
||||||
|
"filterContext=$filterContext, " +
|
||||||
|
"filterAction=$filterAction, " +
|
||||||
|
"filterKeywords=$filterKeywords" +
|
||||||
|
")"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun isAllow(user: UserDetail, action: Action, resource: Filter): Boolean {
|
fun isAllow(user: UserDetail, action: Action, resource: Filter): Boolean {
|
||||||
|
|
|
@ -33,4 +33,14 @@ class FilterKeyword(
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return id.hashCode()
|
return id.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FilterKeyword(" +
|
||||||
|
"id=$id, " +
|
||||||
|
"keyword=$keyword, " +
|
||||||
|
"mode=$mode" +
|
||||||
|
")"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,13 @@ class FilterName(name: String) {
|
||||||
return name.hashCode()
|
return name.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FilterName(" +
|
||||||
|
"name='$name'" +
|
||||||
|
")"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val LENGTH = 300
|
const val LENGTH = 300
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,31 @@
|
||||||
|
|
||||||
package dev.usbharu.hideout.core.domain.model.filter
|
package dev.usbharu.hideout.core.domain.model.filter
|
||||||
|
|
||||||
class FilterResult(val filter: Filter, val matchedKeyword: String)
|
class FilterResult(val filter: Filter, val matchedKeyword: String) {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as FilterResult
|
||||||
|
|
||||||
|
if (filter != other.filter) return false
|
||||||
|
if (matchedKeyword != other.matchedKeyword) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = filter.hashCode()
|
||||||
|
result = 31 * result + matchedKeyword.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FilterResult(" +
|
||||||
|
"filter=$filter, " +
|
||||||
|
"matchedKeyword='$matchedKeyword'" +
|
||||||
|
")"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -18,4 +18,31 @@ package dev.usbharu.hideout.core.domain.model.filter
|
||||||
|
|
||||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||||
|
|
||||||
class FilteredPost(val post: Post, val filterResults: List<FilterResult>)
|
class FilteredPost(val post: Post, val filterResults: List<FilterResult>) {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as FilteredPost
|
||||||
|
|
||||||
|
if (post != other.post) return false
|
||||||
|
if (filterResults != other.filterResults) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = post.hashCode()
|
||||||
|
result = 31 * result + filterResults.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "FilteredPost(" +
|
||||||
|
"post=$post, " +
|
||||||
|
"filterResults=$filterResults" +
|
||||||
|
")"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package dev.usbharu.hideout.core.domain.service.filter
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.filter.*
|
||||||
|
import dev.usbharu.hideout.core.domain.model.post.TestPostFactory
|
||||||
|
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class FilterDomainServiceTest {
|
||||||
|
@Test
|
||||||
|
fun apply_filterContextの適用範囲にフィルターが適用される() {
|
||||||
|
val post = TestPostFactory.create()
|
||||||
|
|
||||||
|
val domainService = FilterDomainService()
|
||||||
|
val filter = Filter(
|
||||||
|
FilterId(1),
|
||||||
|
userDetailId = UserDetailId(1),
|
||||||
|
FilterName("filter"),
|
||||||
|
setOf(FilterContext.HOME),
|
||||||
|
filterAction = FilterAction.HIDE,
|
||||||
|
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("test"), FilterMode.NONE))
|
||||||
|
)
|
||||||
|
val apply = domainService.apply(post, FilterContext.HOME, listOf(filter))
|
||||||
|
assertEquals(1, apply.filterResults.size)
|
||||||
|
assertEquals("test", apply.filterResults.first().matchedKeyword)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun apply_filterContextに当てはまらないならfilterResultsが空になる() {
|
||||||
|
val post = TestPostFactory.create()
|
||||||
|
|
||||||
|
val domainService = FilterDomainService()
|
||||||
|
val filter = Filter(
|
||||||
|
FilterId(1),
|
||||||
|
userDetailId = UserDetailId(1),
|
||||||
|
FilterName("filter"),
|
||||||
|
setOf(FilterContext.PUBLIC),
|
||||||
|
filterAction = FilterAction.HIDE,
|
||||||
|
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("test"), FilterMode.NONE))
|
||||||
|
)
|
||||||
|
val apply = domainService.apply(post, FilterContext.HOME, listOf(filter))
|
||||||
|
assertEquals(0, apply.filterResults.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun overviewにも適用される() {
|
||||||
|
val post = TestPostFactory.create(overview = "test")
|
||||||
|
|
||||||
|
val domainService = FilterDomainService()
|
||||||
|
val filter = Filter(
|
||||||
|
FilterId(1),
|
||||||
|
userDetailId = UserDetailId(1),
|
||||||
|
FilterName("filter"),
|
||||||
|
setOf(FilterContext.HOME),
|
||||||
|
filterAction = FilterAction.HIDE,
|
||||||
|
setOf(FilterKeyword(FilterKeywordId(1), FilterKeywordKeyword("test"), FilterMode.NONE))
|
||||||
|
)
|
||||||
|
val apply = domainService.apply(post, FilterContext.HOME, listOf(filter))
|
||||||
|
assertEquals(2, apply.filterResults.size)
|
||||||
|
assertEquals("test", apply.filterResults.first().matchedKeyword)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun applyAll_filterContextの適用範囲にフィルターが適用される() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue