fix(series-banner): 배너 응답 생성을 서비스로 옮긴다
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package kr.co.vividnext.sodalive.content.series.main
|
||||
|
||||
import kr.co.vividnext.sodalive.admin.content.series.banner.dto.SeriesBannerResponse
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.content.series.ContentSeriesService
|
||||
@@ -35,11 +34,7 @@ class SeriesMainController(
|
||||
if (member == null) throw SodaException(messageKey = "common.error.bad_credentials")
|
||||
val preference = resolvePreference(member)
|
||||
|
||||
val banners = bannerService.getDisplayBanners(PageRequest.of(0, 10), langContext.lang)
|
||||
.content
|
||||
.map {
|
||||
SeriesBannerResponse.from(it, imageHost)
|
||||
}
|
||||
val banners = bannerService.getDisplayBannerResponses(PageRequest.of(0, 10), langContext.lang, imageHost)
|
||||
|
||||
val completedSeriesList = contentSeriesService.getSeriesList(
|
||||
creatorId = null,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package kr.co.vividnext.sodalive.content.series.main.banner
|
||||
|
||||
import kr.co.vividnext.sodalive.admin.content.series.AdminContentSeriesRepository
|
||||
import kr.co.vividnext.sodalive.admin.content.series.banner.dto.SeriesBannerListPageResponse
|
||||
import kr.co.vividnext.sodalive.admin.content.series.banner.dto.SeriesBannerResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.i18n.Lang
|
||||
import org.springframework.data.domain.Page
|
||||
@@ -9,23 +11,54 @@ import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
@Service
|
||||
@Transactional(readOnly = true)
|
||||
class ContentSeriesBannerService(
|
||||
private val bannerRepository: SeriesBannerRepository,
|
||||
private val seriesRepository: AdminContentSeriesRepository
|
||||
) {
|
||||
fun getActiveBanners(pageable: Pageable): Page<SeriesBanner> {
|
||||
return bannerRepository.findByIsActiveTrueOrderBySortOrderAsc(pageable)
|
||||
fun getActiveBanners(pageable: Pageable, imageHost: String): SeriesBannerListPageResponse {
|
||||
val banners = bannerRepository.findByIsActiveTrueOrderBySortOrderAsc(pageable)
|
||||
return SeriesBannerListPageResponse(
|
||||
totalCount = banners.totalElements,
|
||||
content = banners.content.map {
|
||||
SeriesBannerResponse.from(
|
||||
banner = it,
|
||||
imageHost = imageHost,
|
||||
appendLanguageToSeriesTitle = true
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun getDisplayBanners(pageable: Pageable, lang: Lang): Page<SeriesBanner> {
|
||||
return bannerRepository.findByIsActiveTrueAndLangOrderBySortOrderAsc(lang, pageable)
|
||||
}
|
||||
|
||||
fun getDisplayBannerResponses(pageable: Pageable, lang: Lang, imageHost: String): List<SeriesBannerResponse> {
|
||||
return getDisplayBanners(pageable, lang).content.map {
|
||||
SeriesBannerResponse.from(it, imageHost)
|
||||
}
|
||||
}
|
||||
|
||||
fun getBannerById(bannerId: Long): SeriesBanner {
|
||||
return bannerRepository.findById(bannerId)
|
||||
.orElseThrow { SodaException(messageKey = "series.banner.error.not_found") }
|
||||
}
|
||||
|
||||
fun getBannerDetailResponse(bannerId: Long, imageHost: String): SeriesBannerResponse {
|
||||
return SeriesBannerResponse.from(getBannerById(bannerId), imageHost)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun updateBannerResponse(
|
||||
bannerId: Long,
|
||||
imagePath: String? = null,
|
||||
seriesId: Long? = null,
|
||||
imageHost: String
|
||||
): SeriesBannerResponse {
|
||||
return SeriesBannerResponse.from(updateBanner(bannerId, imagePath, seriesId), imageHost)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun registerBanner(seriesId: Long, imagePath: String, lang: Lang? = null): SeriesBanner {
|
||||
val series = seriesRepository.findByIdAndActiveTrue(seriesId)
|
||||
|
||||
Reference in New Issue
Block a user