Skip to content

Commit

Permalink
[fix #169] 북마크 카운팅 시 삭제된 컨텐츠는 빼도록 (#171)
Browse files Browse the repository at this point in the history
* fix: 컨텐츠 삭제 전 북마크 취소

* fix: 북마크 카운팅 시 삭제된 컨텐츠는 빼도록
  • Loading branch information
jimin3263 authored Oct 27, 2024
1 parent e2fb354 commit e8d8249
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.data.jpa.repository.JpaRepository

interface BookMarkRepository : JpaRepository<BookmarkEntity, Long> {
interface BookMarkRepository : JpaRepository<BookmarkEntity, Long>, BookmarkQuerydslRepository {
fun findByContentIdAndUserIdAndDeleted(
contentId: Long,
userId: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pokit.out.persistence.bookmark.persist

interface BookmarkQuerydslRepository {
fun countByUserId(userId: Long): Int
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.pokit.out.persistence.bookmark.persist

import com.pokit.out.persistence.bookmark.persist.QBookmarkEntity.bookmarkEntity
import com.pokit.out.persistence.content.persist.QContentEntity.contentEntity
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Repository

@Repository
class BookmarkQuerydslRepositoryImpl(
private val queryFactory: JPAQueryFactory
) : BookmarkQuerydslRepository {
override fun countByUserId(userId: Long): Int {
return (queryFactory
.select(bookmarkEntity.id.countDistinct())
.from(bookmarkEntity)
.join(contentEntity)
.on(
bookmarkEntity.contentId.eq(contentEntity.id),
contentEntity.deleted.isFalse,
)
.where(
bookmarkEntity.userId.eq(userId),
bookmarkEntity.deleted.isFalse,
)
.fetchOne() ?: 0L).toInt()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class ContentCountAdapter(
.fetchFirst()!!.toInt()
}

override fun getBookmarkContent(userId: Long) =
bookMarkRepository.countByUserIdAndDeleted(userId, false)
override fun getBookmarkCount(userId: Long): Int =
bookMarkRepository.countByUserId(userId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.pokit.content.port.out
interface ContentCountPort {
fun getUnreadCount(userId: Long): Int

fun getBookmarkContent(userId: Long): Int
fun getBookmarkCount(userId: Long): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class ContentService(
contentCountPort.getUnreadCount(userId)

override fun getBookmarkCount(userId: Long) =
contentCountPort.getBookmarkContent(userId)
contentCountPort.getBookmarkCount(userId)

private fun verifyContent(userId: Long, contentId: Long): Content {
return contentPort.loadByUserIdAndId(userId, contentId)
Expand Down

0 comments on commit e8d8249

Please sign in to comment.