test #332
|
@ -293,5 +293,9 @@ class LiveRoomController(
|
|||
}
|
||||
|
||||
@GetMapping("/latest-finished-live")
|
||||
fun getLatestFinishedLive() = run { ApiResponse.ok(service.getLatestFinishedLive()) }
|
||||
fun getLatestFinishedLive(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
ApiResponse.ok(service.getLatestFinishedLive(member))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ interface LiveRoomQueryRepository {
|
|||
fun getTotalHeartCount(roomId: Long): Int?
|
||||
fun getLiveRoomCreatorId(roomId: Long): Long?
|
||||
fun getHeartList(roomId: Long): List<GetLiveRoomHeartListItem>
|
||||
fun getLatestFinishedLive(): List<LiveRoom>
|
||||
fun getLatestFinishedLive(offset: Long): List<LiveRoom>
|
||||
}
|
||||
|
||||
class LiveRoomQueryRepositoryImpl(
|
||||
|
@ -382,7 +382,7 @@ class LiveRoomQueryRepositoryImpl(
|
|||
.fetch()
|
||||
}
|
||||
|
||||
override fun getLatestFinishedLive(): List<LiveRoom> {
|
||||
override fun getLatestFinishedLive(offset: Long): List<LiveRoom> {
|
||||
return queryFactory
|
||||
.selectFrom(liveRoom)
|
||||
.innerJoin(liveRoom.member, member)
|
||||
|
@ -392,6 +392,7 @@ class LiveRoomQueryRepositoryImpl(
|
|||
)
|
||||
.groupBy(liveRoom.member.id)
|
||||
.orderBy(liveRoom.updatedAt.max().desc())
|
||||
.offset(offset)
|
||||
.limit(20)
|
||||
.fetch()
|
||||
}
|
||||
|
|
|
@ -1298,16 +1298,32 @@ class LiveRoomService(
|
|||
)
|
||||
}
|
||||
|
||||
fun getLatestFinishedLive(): List<GetLatestFinishedLiveResponse> {
|
||||
return repository.getLatestFinishedLive()
|
||||
.map {
|
||||
GetLatestFinishedLiveResponse(
|
||||
memberId = it.member!!.id!!,
|
||||
nickname = it.member!!.nickname,
|
||||
profileImageUrl = "$cloudFrontHost/${it.member!!.profileImage}",
|
||||
title = it.title,
|
||||
timeAgo = it.updatedAt!!.getTimeAgoString()
|
||||
)
|
||||
}
|
||||
fun getLatestFinishedLive(member: Member?): List<GetLatestFinishedLiveResponse> {
|
||||
val result = mutableListOf<GetLatestFinishedLiveResponse>()
|
||||
var retry = 0L
|
||||
|
||||
do {
|
||||
result.addAll(
|
||||
repository.getLatestFinishedLive(offset = retry)
|
||||
.filter {
|
||||
if (member?.id != null) {
|
||||
!blockMemberRepository.isBlocked(blockedMemberId = member.id!!, memberId = it.member!!.id!!)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
.map {
|
||||
GetLatestFinishedLiveResponse(
|
||||
memberId = it.member!!.id!!,
|
||||
nickname = it.member!!.nickname,
|
||||
profileImageUrl = "$cloudFrontHost/${it.member!!.profileImage}",
|
||||
title = it.title,
|
||||
timeAgo = it.updatedAt!!.getTimeAgoString()
|
||||
)
|
||||
}
|
||||
)
|
||||
} while (result.size < 20 && retry++ < 3)
|
||||
|
||||
return result.take(20)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue