Skip to content

Commit

Permalink
[feat #175] 링크 목록 조회 시 즐겨찾기 필드 추가 (#176)
Browse files Browse the repository at this point in the history
* feat : 링크 목록 조회 시 북마크 left join 추가

* feat : 링크 목록 응답 dto 즐겨찾기 필드 추가
  • Loading branch information
dlswns2480 authored Nov 14, 2024
1 parent e5a47ac commit 789f087
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data class ContentsResponse(
val createdAt: String,
val isRead: Boolean,
val thumbNail: String,
val isFavorite: Boolean
)

fun ContentsResult.toResponse(): ContentsResponse {
Expand All @@ -30,6 +31,7 @@ fun ContentsResult.toResponse(): ContentsResponse {
alertYn = this.alertYn,
createdAt = this.createdAt.format(formatter),
isRead = this.isRead,
thumbNail = this.thumbNail
thumbNail = this.thumbNail,
isFavorite = this.isFavorite
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ class ContentAdapter(
condition: ContentSearchCondition,
pageable: Pageable,
): Slice<ContentsResult> {
val query = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count())
val query = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count(), bookmarkEntity.count())
.from(contentEntity)
.leftJoin(userLogEntity).on(userLogEntity.contentId.eq(contentEntity.id))
.join(categoryEntity).on(categoryEntity.id.eq(contentEntity.categoryId))
.leftJoin(bookmarkEntity).on(bookmarkEntity.contentId.eq(contentEntity.id))

FavoriteOrNot(condition.favorites, query) // 북마크 조인 여부

Expand All @@ -90,18 +91,20 @@ class ContentAdapter(
ContentsResult.of(
it[contentEntity]!!.toDomain(),
it[categoryEntity.name]!!,
it[userLogEntity.count()]!!
it[userLogEntity.count()]!!,
it[bookmarkEntity.count()]!!
)
}

return SliceImpl(contents, pageable, hasNext)
}

override fun loadByUserIdAndCategoryName(userId: Long, categoryName: String, pageable: Pageable): Slice<ContentsResult> {
val contents = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count())
val contents = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count(), bookmarkEntity.count())
.from(contentEntity)
.leftJoin(userLogEntity).on(userLogEntity.contentId.eq(contentEntity.id))
.join(categoryEntity).on(categoryEntity.id.eq(contentEntity.categoryId))
.leftJoin(bookmarkEntity).on(bookmarkEntity.contentId.eq(contentEntity.id))
.where(
categoryEntity.userId.eq(userId),
categoryEntity.name.eq(categoryName),
Expand All @@ -119,19 +122,20 @@ class ContentAdapter(
ContentsResult.of(
it[contentEntity]!!.toDomain(),
it[categoryEntity.name]!!,
it[userLogEntity.count()]!!
it[userLogEntity.count()]!!,
it[bookmarkEntity.count()]!!
)
}

return SliceImpl(contentResults, pageable, hasNext)
}

override fun loadBookmarkedContentsByUserId(userId: Long, pageable: Pageable): Slice<ContentsResult> {
val contents = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count())
val contents = queryFactory.select(contentEntity, categoryEntity.name, userLogEntity.count(), bookmarkEntity.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))
.leftJoin(bookmarkEntity).on(bookmarkEntity.contentId.eq(contentEntity.id))
.where(
categoryEntity.userId.eq(userId),
contentEntity.deleted.isFalse,
Expand All @@ -149,7 +153,8 @@ class ContentAdapter(
ContentsResult.of(
it[contentEntity]!!.toDomain(),
it[categoryEntity.name]!!,
it[userLogEntity.count()]!!
it[userLogEntity.count()]!!,
it[bookmarkEntity.count()]!!
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ data class ContentsResult(
val alertYn: String,
val createdAt: LocalDateTime,
val isRead: Boolean,
val thumbNail: String
val thumbNail: String,
val isFavorite: Boolean
) {
companion object {
fun of(content: Content, categoryName: String, isRead: Long): ContentsResult {
fun of(content: Content, categoryName: String, isRead: Long, isFavorite: Long): ContentsResult {
return ContentsResult(
contentId = content.id,
category = RemindCategory(content.categoryId, categoryName),
Expand All @@ -29,7 +30,8 @@ data class ContentsResult(
alertYn = content.alertYn,
createdAt = content.createdAt,
isRead = isRead > 0,
thumbNail = content.thumbNail ?: ContentDefault.THUMB_NAIL
thumbNail = content.thumbNail ?: ContentDefault.THUMB_NAIL,
isFavorite = isFavorite > 0
)
}
}
Expand Down

0 comments on commit 789f087

Please sign in to comment.