앱 API - 오디션 리스트
This commit is contained in:
parent
bb41a81eb1
commit
f77b5f67d0
|
@ -0,0 +1,30 @@
|
||||||
|
package kr.co.vividnext.sodalive.audition
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||||
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
|
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.RestController
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/audition")
|
||||||
|
class AuditionController(private val service: AuditionService) {
|
||||||
|
@GetMapping
|
||||||
|
fun getAuditionList(
|
||||||
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||||
|
pageable: Pageable
|
||||||
|
) = run {
|
||||||
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
|
|
||||||
|
ApiResponse.ok(
|
||||||
|
service.getAuditionList(
|
||||||
|
offset = pageable.offset,
|
||||||
|
limit = pageable.pageSize.toLong(),
|
||||||
|
isAdult = member.auth != null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package kr.co.vividnext.sodalive.audition
|
||||||
|
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||||
|
import kr.co.vividnext.sodalive.audition.QAudition.audition
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
|
||||||
|
interface AuditionRepository : JpaRepository<Audition, Long>, AuditionQueryRepository
|
||||||
|
|
||||||
|
interface AuditionQueryRepository {
|
||||||
|
fun getInProgressAuditionCount(isAdult: Boolean): Int
|
||||||
|
fun getCompletedAuditionCount(isAdult: Boolean): Int
|
||||||
|
fun getAuditionList(offset: Long, limit: Long, isAdult: Boolean): List<GetAuditionListItem>
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuditionQueryRepositoryImpl(
|
||||||
|
private val queryFactory: JPAQueryFactory,
|
||||||
|
|
||||||
|
@Value("\${cloud.aws.cloud-front.host}")
|
||||||
|
private val cloudFrontHost: String
|
||||||
|
) : AuditionQueryRepository {
|
||||||
|
override fun getInProgressAuditionCount(isAdult: Boolean): Int {
|
||||||
|
var where = audition.isActive.isTrue
|
||||||
|
.and(audition.status.eq(AuditionStatus.IN_PROGRESS))
|
||||||
|
|
||||||
|
if (!isAdult) {
|
||||||
|
where = where.and(audition.isAdult.isFalse)
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryFactory
|
||||||
|
.select(audition.id)
|
||||||
|
.from(audition)
|
||||||
|
.where(where)
|
||||||
|
.fetch()
|
||||||
|
.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getCompletedAuditionCount(isAdult: Boolean): Int {
|
||||||
|
var where = audition.isActive.isTrue
|
||||||
|
.and(audition.status.eq(AuditionStatus.COMPLETED))
|
||||||
|
|
||||||
|
if (!isAdult) {
|
||||||
|
where = where.and(audition.isAdult.isFalse)
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryFactory
|
||||||
|
.select(audition.id)
|
||||||
|
.from(audition)
|
||||||
|
.where(where)
|
||||||
|
.fetch()
|
||||||
|
.size
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAuditionList(offset: Long, limit: Long, isAdult: Boolean): List<GetAuditionListItem> {
|
||||||
|
var where = audition.isActive.isTrue
|
||||||
|
.and(
|
||||||
|
audition.status.eq(AuditionStatus.COMPLETED)
|
||||||
|
.and(audition.status.eq(AuditionStatus.IN_PROGRESS))
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!isAdult) {
|
||||||
|
where = where.and(audition.isAdult.isFalse)
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryFactory
|
||||||
|
.select(
|
||||||
|
QGetAuditionListItem(
|
||||||
|
audition.id,
|
||||||
|
audition.title,
|
||||||
|
audition.imagePath.prepend("/").prepend(cloudFrontHost),
|
||||||
|
audition.status.eq(AuditionStatus.COMPLETED)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.from(audition)
|
||||||
|
.where(where)
|
||||||
|
.fetch()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package kr.co.vividnext.sodalive.audition
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class AuditionService(private val repository: AuditionRepository) {
|
||||||
|
fun getAuditionList(offset: Long, limit: Long, isAdult: Boolean): GetAuditionListResponse {
|
||||||
|
val inProgressCount = repository.getInProgressAuditionCount(isAdult = isAdult)
|
||||||
|
val completedCount = repository.getCompletedAuditionCount(isAdult = isAdult)
|
||||||
|
val items = repository.getAuditionList(offset = offset, limit = limit, isAdult = isAdult)
|
||||||
|
|
||||||
|
return GetAuditionListResponse(inProgressCount, completedCount, items)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package kr.co.vividnext.sodalive.audition
|
||||||
|
|
||||||
|
import com.querydsl.core.annotations.QueryProjection
|
||||||
|
|
||||||
|
data class GetAuditionListResponse(
|
||||||
|
val inProgressCount: Int,
|
||||||
|
val completedCount: Int,
|
||||||
|
val items: List<GetAuditionListItem>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class GetAuditionListItem @QueryProjection constructor(
|
||||||
|
val id: Long,
|
||||||
|
val title: String,
|
||||||
|
val imageUrl: String,
|
||||||
|
val isOff: Boolean
|
||||||
|
)
|
Loading…
Reference in New Issue