시리즈 리스트 조회 API
- DTO 조회시 EnumCollection 부분의 문제로 series 필드 전체 조회로 변경
This commit is contained in:
parent
d3b9fd7d78
commit
7b04803aa0
|
@ -1,23 +1,21 @@
|
|||
package kr.co.vividnext.sodalive.content.series
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.admin.content.series.genre.QSeriesGenre
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.QSeries.series
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.Series
|
||||
import kr.co.vividnext.sodalive.member.QMember
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface ContentSeriesRepository : JpaRepository<Series, Long>, ContentSeriesQueryRepository
|
||||
|
||||
interface ContentSeriesQueryRepository {
|
||||
fun getSeriesTotalCount(creatorId: Long, isAuth: Boolean): Int
|
||||
fun getSeriesRawItemList(
|
||||
fun getSeriesList(
|
||||
imageHost: String,
|
||||
creatorId: Long,
|
||||
isAuth: Boolean,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetSeriesListRawItem>
|
||||
): List<Series>
|
||||
}
|
||||
|
||||
class ContentSeriesQueryRepositoryImpl(
|
||||
|
@ -39,16 +37,13 @@ class ContentSeriesQueryRepositoryImpl(
|
|||
.size
|
||||
}
|
||||
|
||||
override fun getSeriesRawItemList(
|
||||
override fun getSeriesList(
|
||||
imageHost: String,
|
||||
creatorId: Long,
|
||||
isAuth: Boolean,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetSeriesListRawItem> {
|
||||
val qMember = QMember.member
|
||||
val qSeriesGenre = QSeriesGenre.seriesGenre
|
||||
|
||||
): List<Series> {
|
||||
var where = series.member.id.eq(creatorId)
|
||||
.and(series.isActive.isTrue)
|
||||
|
||||
|
@ -56,31 +51,8 @@ class ContentSeriesQueryRepositoryImpl(
|
|||
where = where.and(series.isAdult.isFalse)
|
||||
}
|
||||
|
||||
println(
|
||||
queryFactory.select(series.publishedDaysOfWeek)
|
||||
.from(series)
|
||||
.where(where)
|
||||
.fetch()
|
||||
)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetSeriesListRawItem(
|
||||
series.id,
|
||||
series.title,
|
||||
series.coverImage.prepend("/").prepend(imageHost),
|
||||
series.publishedDaysOfWeek,
|
||||
series.state,
|
||||
qSeriesGenre.genre,
|
||||
series.isAdult,
|
||||
qMember.id,
|
||||
qMember.nickname,
|
||||
qMember.profileImage.prepend("/").prepend(imageHost)
|
||||
)
|
||||
)
|
||||
.from(series)
|
||||
.innerJoin(series.member, qMember)
|
||||
.innerJoin(series.genre, qSeriesGenre)
|
||||
.selectFrom(series)
|
||||
.where(where)
|
||||
.fetch()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package kr.co.vividnext.sodalive.content.series
|
||||
|
||||
import kr.co.vividnext.sodalive.content.series.content.ContentSeriesContentRepository
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesPublishedDaysOfWeek
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesSortType
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesState
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
|
@ -23,7 +25,7 @@ class ContentSeriesService(
|
|||
limit: Long = 10
|
||||
): GetSeriesListResponse {
|
||||
val totalCount = repository.getSeriesTotalCount(creatorId = creatorId, isAuth = member.auth != null)
|
||||
val rawItems = repository.getSeriesRawItemList(
|
||||
val rawItems = repository.getSeriesList(
|
||||
imageHost = coverImageHost,
|
||||
creatorId = creatorId,
|
||||
isAuth = member.auth != null,
|
||||
|
@ -32,7 +34,20 @@ class ContentSeriesService(
|
|||
)
|
||||
|
||||
val items = rawItems
|
||||
.map { it.toSeriesListItem() }
|
||||
.map {
|
||||
GetSeriesListResponse.SeriesListItem(
|
||||
seriesId = it.id!!,
|
||||
title = it.title,
|
||||
coverImage = "$coverImageHost/${it.coverImage!!}",
|
||||
publishedDaysOfWeek = publishedDaysOfWeekText(it.publishedDaysOfWeek),
|
||||
isComplete = it.state == SeriesState.COMPLETE,
|
||||
creator = GetSeriesListResponse.SeriesListItemCreator(
|
||||
creatorId = it.member!!.id!!,
|
||||
nickname = it.member!!.nickname,
|
||||
profileImage = "$coverImageHost/${it.member!!.profileImage!!}"
|
||||
)
|
||||
)
|
||||
}
|
||||
.map {
|
||||
it.numberOfContent = seriesContentRepository.getContentCount(
|
||||
seriesId = it.seriesId,
|
||||
|
@ -56,4 +71,27 @@ class ContentSeriesService(
|
|||
|
||||
return GetSeriesListResponse(totalCount, items)
|
||||
}
|
||||
|
||||
private fun publishedDaysOfWeekText(publishedDaysOfWeek: Set<SeriesPublishedDaysOfWeek>): String {
|
||||
val dayOfWeekText = publishedDaysOfWeek.toList().sortedBy { it.ordinal }
|
||||
.map {
|
||||
when (it) {
|
||||
SeriesPublishedDaysOfWeek.SUN -> "일"
|
||||
SeriesPublishedDaysOfWeek.MON -> "월"
|
||||
SeriesPublishedDaysOfWeek.TUE -> "화"
|
||||
SeriesPublishedDaysOfWeek.WED -> "수"
|
||||
SeriesPublishedDaysOfWeek.THU -> "목"
|
||||
SeriesPublishedDaysOfWeek.FRI -> "금"
|
||||
SeriesPublishedDaysOfWeek.SAT -> "토"
|
||||
SeriesPublishedDaysOfWeek.RANDOM -> "랜덤"
|
||||
}
|
||||
}
|
||||
.joinToString(", ") { it }
|
||||
|
||||
return if (publishedDaysOfWeek.contains(SeriesPublishedDaysOfWeek.RANDOM)) {
|
||||
dayOfWeekText
|
||||
} else {
|
||||
"매주 ${dayOfWeekText}요일"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package kr.co.vividnext.sodalive.content.series
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesPublishedDaysOfWeek
|
||||
import kr.co.vividnext.sodalive.creator.admin.content.series.SeriesState
|
||||
|
||||
data class GetSeriesListRawItem @QueryProjection constructor(
|
||||
val seriesId: Long,
|
||||
val title: String,
|
||||
val coverImage: String,
|
||||
val publishedDaysOfWeek: Set<SeriesPublishedDaysOfWeek>,
|
||||
val state: SeriesState,
|
||||
val genre: String,
|
||||
val isAdult: Boolean,
|
||||
val creatorId: Long,
|
||||
val creatorNickname: String,
|
||||
val creatorProfileImage: String
|
||||
|
||||
) {
|
||||
fun toSeriesListItem(): GetSeriesListResponse.SeriesListItem {
|
||||
return GetSeriesListResponse.SeriesListItem(
|
||||
seriesId = seriesId,
|
||||
title = title,
|
||||
coverImage = coverImage,
|
||||
publishedDaysOfWeek = publishedDaysOfWeekText(),
|
||||
isComplete = state == SeriesState.COMPLETE,
|
||||
creator = GetSeriesListResponse.SeriesListItemCreator(
|
||||
creatorId = creatorId,
|
||||
nickname = creatorNickname,
|
||||
profileImage = creatorProfileImage
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun publishedDaysOfWeekText(): String {
|
||||
val dayOfWeekText = publishedDaysOfWeek.toList().sortedBy { it.ordinal }
|
||||
.map {
|
||||
when (it) {
|
||||
SeriesPublishedDaysOfWeek.SUN -> "일"
|
||||
SeriesPublishedDaysOfWeek.MON -> "월"
|
||||
SeriesPublishedDaysOfWeek.TUE -> "화"
|
||||
SeriesPublishedDaysOfWeek.WED -> "수"
|
||||
SeriesPublishedDaysOfWeek.THU -> "목"
|
||||
SeriesPublishedDaysOfWeek.FRI -> "금"
|
||||
SeriesPublishedDaysOfWeek.SAT -> "토"
|
||||
SeriesPublishedDaysOfWeek.RANDOM -> "랜덤"
|
||||
}
|
||||
}
|
||||
.joinToString(", ") { it }
|
||||
|
||||
return if (publishedDaysOfWeek.contains(SeriesPublishedDaysOfWeek.RANDOM)) {
|
||||
dayOfWeekText
|
||||
} else {
|
||||
"매주 ${dayOfWeekText}요일"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue