Compare commits
2 Commits
26c09de7c9
...
80c44373c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 80c44373c7 | |||
| a538bb766d |
@@ -27,5 +27,6 @@ data class GetHomeResponse(
|
|||||||
val recommendChannelList: List<RecommendChannelResponse>,
|
val recommendChannelList: List<RecommendChannelResponse>,
|
||||||
val freeContentList: List<AudioContentMainItem>,
|
val freeContentList: List<AudioContentMainItem>,
|
||||||
val pointAvailableContentList: List<AudioContentMainItem>,
|
val pointAvailableContentList: List<AudioContentMainItem>,
|
||||||
|
val recommendContentList: List<AudioContentMainItem>,
|
||||||
val curationList: List<GetContentCurationResponse>
|
val curationList: List<GetContentCurationResponse>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -63,4 +63,20 @@ class HomeController(private val service: HomeService) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 추천 콘텐츠만 새로고침하기 위한 엔드포인트
|
||||||
|
@GetMapping("/recommend-contents")
|
||||||
|
fun getRecommendContents(
|
||||||
|
@RequestParam("isAdultContentVisible", required = false) isAdultContentVisible: Boolean? = null,
|
||||||
|
@RequestParam("contentType", required = false) contentType: ContentType? = null,
|
||||||
|
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||||
|
) = run {
|
||||||
|
ApiResponse.ok(
|
||||||
|
service.getRecommendContentList(
|
||||||
|
isAdultContentVisible = isAdultContentVisible ?: true,
|
||||||
|
contentType = contentType ?: ContentType.ALL,
|
||||||
|
member = member
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ class HomeService(
|
|||||||
@Value("\${cloud.aws.cloud-front.host}")
|
@Value("\${cloud.aws.cloud-front.host}")
|
||||||
private val imageHost: String
|
private val imageHost: String
|
||||||
) {
|
) {
|
||||||
|
companion object {
|
||||||
|
private const val RECOMMEND_TARGET_SIZE = 20
|
||||||
|
private const val RECOMMEND_MAX_ATTEMPTS = 3
|
||||||
|
}
|
||||||
|
|
||||||
fun fetchData(
|
fun fetchData(
|
||||||
timezone: String,
|
timezone: String,
|
||||||
isAdultContentVisible: Boolean,
|
isAdultContentVisible: Boolean,
|
||||||
@@ -213,6 +218,11 @@ class HomeService(
|
|||||||
recommendChannelList = recommendChannelList,
|
recommendChannelList = recommendChannelList,
|
||||||
freeContentList = freeContentList,
|
freeContentList = freeContentList,
|
||||||
pointAvailableContentList = pointAvailableContentList,
|
pointAvailableContentList = pointAvailableContentList,
|
||||||
|
recommendContentList = getRecommendContentList(
|
||||||
|
isAdultContentVisible = isAdultContentVisible,
|
||||||
|
contentType = contentType,
|
||||||
|
member = member
|
||||||
|
),
|
||||||
curationList = curationList
|
curationList = curationList
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -284,4 +294,46 @@ class HomeService(
|
|||||||
|
|
||||||
return dayToSeriesPublishedDaysOfWeek[zonedDateTime.dayOfWeek] ?: SeriesPublishedDaysOfWeek.RANDOM
|
return dayToSeriesPublishedDaysOfWeek[zonedDateTime.dayOfWeek] ?: SeriesPublishedDaysOfWeek.RANDOM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 추천 콘텐츠 조회 로직은 변경 가능성을 고려하여 별도 메서드로 추출한다.
|
||||||
|
fun getRecommendContentList(
|
||||||
|
isAdultContentVisible: Boolean,
|
||||||
|
contentType: ContentType,
|
||||||
|
member: Member?
|
||||||
|
): List<AudioContentMainItem> {
|
||||||
|
val memberId = member?.id
|
||||||
|
val isAdult = member?.auth != null && isAdultContentVisible
|
||||||
|
|
||||||
|
// Set + List 조합으로 중복 제거 및 순서 보존, 각 시도마다 limit=60으로 조회
|
||||||
|
val seen = HashSet<Long>(RECOMMEND_TARGET_SIZE * 2)
|
||||||
|
val result = ArrayList<AudioContentMainItem>(RECOMMEND_TARGET_SIZE)
|
||||||
|
var attempt = 0
|
||||||
|
while (attempt < RECOMMEND_MAX_ATTEMPTS && result.size < RECOMMEND_TARGET_SIZE) {
|
||||||
|
attempt += 1
|
||||||
|
val batch = contentService.getLatestContentByTheme(
|
||||||
|
theme = emptyList(), // 특정 테마에 종속되지 않도록 전체에서 랜덤 조회
|
||||||
|
contentType = contentType,
|
||||||
|
offset = 0,
|
||||||
|
limit = (RECOMMEND_TARGET_SIZE * RECOMMEND_MAX_ATTEMPTS).toLong(), // 60개 조회
|
||||||
|
isFree = false,
|
||||||
|
isAdult = isAdult,
|
||||||
|
orderByRandom = true
|
||||||
|
).filter {
|
||||||
|
if (memberId != null) {
|
||||||
|
!memberService.isBlocked(blockedMemberId = memberId, memberId = it.creatorId)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (item in batch) {
|
||||||
|
if (result.size >= RECOMMEND_TARGET_SIZE) break
|
||||||
|
if (seen.add(item.contentId)) {
|
||||||
|
result.add(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user