150 lines
4.0 KiB
Kotlin
150 lines
4.0 KiB
Kotlin
package kr.co.vividnext.sodalive.search
|
|
|
|
import kr.co.vividnext.sodalive.content.ContentType
|
|
import kr.co.vividnext.sodalive.member.Member
|
|
import org.springframework.stereotype.Service
|
|
|
|
@Service
|
|
class SearchService(private val repository: SearchRepository) {
|
|
fun searchUnified(
|
|
keyword: String,
|
|
isAdultContentVisible: Boolean,
|
|
contentType: ContentType,
|
|
member: Member
|
|
): SearchUnifiedResponse {
|
|
val isAdult = member.auth != null && isAdultContentVisible
|
|
|
|
val creatorList = repository.searchCreatorList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.CREATOR
|
|
it
|
|
}
|
|
|
|
val contentList = repository.searchContentList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.CONTENT
|
|
it
|
|
}
|
|
|
|
val seriesList = repository.searchSeriesList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType,
|
|
offset = 0,
|
|
limit = 3
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.SERIES
|
|
it
|
|
}
|
|
|
|
return SearchUnifiedResponse(
|
|
creatorList = creatorList,
|
|
contentList = contentList,
|
|
seriesList = seriesList
|
|
)
|
|
}
|
|
|
|
fun searchCreatorList(
|
|
keyword: String,
|
|
isAdultContentVisible: Boolean,
|
|
contentType: ContentType,
|
|
member: Member,
|
|
offset: Long,
|
|
limit: Long
|
|
): SearchResponse {
|
|
val totalCount = repository.searchCreatorTotalCount(keyword, memberId = member.id!!)
|
|
val items = repository.searchCreatorList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
offset = offset,
|
|
limit = limit
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.CREATOR
|
|
it
|
|
}
|
|
|
|
return SearchResponse(totalCount, items)
|
|
}
|
|
|
|
fun searchContentList(
|
|
keyword: String,
|
|
isAdultContentVisible: Boolean,
|
|
contentType: ContentType,
|
|
member: Member,
|
|
offset: Long,
|
|
limit: Long
|
|
): SearchResponse {
|
|
val isAdult = member.auth != null && isAdultContentVisible
|
|
|
|
val totalCount = repository.searchContentTotalCount(
|
|
keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType
|
|
)
|
|
|
|
val items = repository.searchContentList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType,
|
|
offset = offset,
|
|
limit = limit
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.CONTENT
|
|
it
|
|
}
|
|
|
|
return SearchResponse(totalCount, items)
|
|
}
|
|
|
|
fun searchSeriesList(
|
|
keyword: String,
|
|
isAdultContentVisible: Boolean,
|
|
contentType: ContentType,
|
|
member: Member,
|
|
offset: Long,
|
|
limit: Long
|
|
): SearchResponse {
|
|
val isAdult = member.auth != null && isAdultContentVisible
|
|
|
|
val totalCount = repository.searchSeriesTotalCount(
|
|
keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType
|
|
)
|
|
|
|
val items = repository.searchSeriesList(
|
|
keyword = keyword,
|
|
memberId = member.id!!,
|
|
isAdult = isAdult,
|
|
contentType = contentType,
|
|
offset = offset,
|
|
limit = limit
|
|
)
|
|
.map {
|
|
it.type = SearchResponseType.SERIES
|
|
it
|
|
}
|
|
|
|
return SearchResponse(totalCount, items)
|
|
}
|
|
}
|