Skip to content

Commit

Permalink
fix: 삭제된 컨텐츠 조회되는 버그 픽스 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimin3263 authored Aug 12, 2024
1 parent 814825c commit c2a03bd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pokit.out.persistence.content.impl

import com.pokit.category.model.CategoryStatus
import com.pokit.content.dto.response.ContentsResult
import com.pokit.content.dto.request.ContentSearchCondition
import com.pokit.content.model.Content
Expand Down Expand Up @@ -125,6 +124,35 @@ class ContentAdapter(
return SliceImpl(contentResults, pageable, hasNext)
}

override fun loadBookmarkedContentsByUserId(userId: Long, pageable: Pageable): Slice<ContentsResult> {
val contents = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count())
.from(contentEntity)
.leftJoin(userLogEntity).on(userLogEntity.contentId.eq(contentEntity.id))
.join(categoryEntity).on(categoryEntity.id.eq(contentEntity.categoryId))
.join(bookmarkEntity).on(bookmarkEntity.contentId.eq(contentEntity.id))
.where(
categoryEntity.userId.eq(userId),
contentEntity.deleted.isFalse,
)
.offset(pageable.offset)
.groupBy(contentEntity)
.limit((pageable.pageSize + 1).toLong())
.orderBy(getSortOrder(contentEntity.createdAt, "createdAt", pageable))
.fetch()

val hasNext = getHasNext(contents, pageable)

val contentResults = contents.map {
ContentsResult.of(
it[contentEntity]!!.toDomain(),
it[categoryEntity.name]!!,
it[userLogEntity.count()]!!
)
}

return SliceImpl(contentResults, pageable, hasNext)
}

override fun loadByContentIds(contentIds: List<Long>): List<Content> =
contentRepository.findByIdIn(contentIds)
.map { it.toDomain() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface ContentPort {
fun deleteByUserId(userId: Long)

fun loadByContentIds(contentIds: List<Long>): List<Content>

fun loadBookmarkedContentsByUserId(userId: Long, pageable: Pageable): Slice<ContentsResult>
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,10 @@ class ContentService(
}

override fun getBookmarkContents(userId: Long, pageable: Pageable): Slice<RemindContentResult> {
val bookMarks = bookMarkPort.loadByUserId(userId, pageable)
val contentIds = bookMarks.content.map { it.contentId }
val contentsById = contentPort.loadByContentIds(contentIds).associateBy { it.id }

val remindContents = contentIds.map { contentId ->
val content = contentsById[contentId]
content?.let {
val isRead = userLogPort.isContentRead(it.id, userId)
val category = categoryPort.loadCategoryOrThrow(it.categoryId, userId).toRemindCategory()
it.toRemindContentResult(isRead, category)
}
}

return SliceImpl(remindContents, pageable, bookMarks.hasNext())
val bookMarks = contentPort.loadBookmarkedContentsByUserId(userId, pageable)
.map { it.toRemindContentResult() }

return SliceImpl(bookMarks.content, pageable, bookMarks.hasNext())
}

override fun getUnreadContents(userId: Long, pageable: Pageable): Slice<RemindContentResult> {
Expand Down

0 comments on commit c2a03bd

Please sign in to comment.