98 lines
4.1 KiB
Kotlin
98 lines
4.1 KiB
Kotlin
package kr.co.vividnext.sodalive.search
|
|
|
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
|
import kr.co.vividnext.sodalive.common.SodaException
|
|
import kr.co.vividnext.sodalive.content.ContentType
|
|
import kr.co.vividnext.sodalive.member.Member
|
|
import org.springframework.data.domain.Pageable
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
|
import org.springframework.web.bind.annotation.GetMapping
|
|
import org.springframework.web.bind.annotation.RequestMapping
|
|
import org.springframework.web.bind.annotation.RequestParam
|
|
import org.springframework.web.bind.annotation.RestController
|
|
|
|
@RestController
|
|
@RequestMapping("/search")
|
|
class SearchController(private val service: SearchService) {
|
|
@GetMapping
|
|
fun searchUnified(
|
|
@RequestParam keyword: String,
|
|
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
|
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
ApiResponse.ok(
|
|
service.searchUnified(
|
|
keyword,
|
|
isAdultContentVisible = isAdultContentVisible ?: true,
|
|
contentType = contentType ?: ContentType.ALL,
|
|
member = member
|
|
)
|
|
)
|
|
}
|
|
|
|
@GetMapping("/creators")
|
|
fun searchCreatorList(
|
|
@RequestParam keyword: String,
|
|
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
|
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
|
pageable: Pageable
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
ApiResponse.ok(
|
|
service.searchCreatorList(
|
|
keyword,
|
|
isAdultContentVisible = isAdultContentVisible ?: true,
|
|
contentType = contentType ?: ContentType.ALL,
|
|
member = member,
|
|
offset = pageable.offset,
|
|
limit = pageable.pageSize.toLong()
|
|
)
|
|
)
|
|
}
|
|
|
|
@GetMapping("/contents")
|
|
fun searchContentList(
|
|
@RequestParam keyword: String,
|
|
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
|
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
|
pageable: Pageable
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
ApiResponse.ok(
|
|
service.searchContentList(
|
|
keyword,
|
|
isAdultContentVisible = isAdultContentVisible ?: true,
|
|
contentType = contentType ?: ContentType.ALL,
|
|
member = member,
|
|
offset = pageable.offset,
|
|
limit = pageable.pageSize.toLong()
|
|
)
|
|
)
|
|
}
|
|
|
|
@GetMapping("/series")
|
|
fun searchSeriesList(
|
|
@RequestParam keyword: String,
|
|
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
|
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
|
pageable: Pageable
|
|
) = run {
|
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
ApiResponse.ok(
|
|
service.searchSeriesList(
|
|
keyword,
|
|
isAdultContentVisible = isAdultContentVisible ?: true,
|
|
contentType = contentType ?: ContentType.ALL,
|
|
member = member,
|
|
offset = pageable.offset,
|
|
limit = pageable.pageSize.toLong()
|
|
)
|
|
)
|
|
}
|
|
}
|