콘텐츠 댓글 조회 수정
- 콘텐츠 크리에이터 - 댓글 전체 조회 - 일반 유저 - 공개 댓글 + 내가 쓴 댓글
This commit is contained in:
		| @@ -111,6 +111,8 @@ interface AudioContentQueryRepository { | |||||||
|     fun getAudioContentCurationList(isAdult: Boolean, offset: Long, limit: Long): List<AudioContentCuration> |     fun getAudioContentCurationList(isAdult: Boolean, offset: Long, limit: Long): List<AudioContentCuration> | ||||||
|  |  | ||||||
|     fun getNotReleaseContentId(): List<Long> |     fun getNotReleaseContentId(): List<Long> | ||||||
|  |  | ||||||
|  |     fun isContentCreator(contentId: Long, memberId: Long): Boolean | ||||||
| } | } | ||||||
|  |  | ||||||
| @Repository | @Repository | ||||||
| @@ -721,4 +723,19 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | |||||||
|             .where(where) |             .where(where) | ||||||
|             .fetch() |             .fetch() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     override fun isContentCreator(contentId: Long, memberId: Long): Boolean { | ||||||
|  |         val foundedContentId = queryFactory | ||||||
|  |             .select(audioContent.id) | ||||||
|  |             .from(audioContent) | ||||||
|  |             .innerJoin(audioContent.member, member) | ||||||
|  |             .where( | ||||||
|  |                 audioContent.isActive.isTrue | ||||||
|  |                     .and(audioContent.id.eq(contentId)) | ||||||
|  |                     .and(audioContent.member.id.eq(memberId)) | ||||||
|  |             ) | ||||||
|  |             .fetchOne() | ||||||
|  |  | ||||||
|  |         return foundedContentId != null && foundedContentId == contentId | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -492,6 +492,8 @@ class AudioContentService( | |||||||
|             commentRepository.findByContentId( |             commentRepository.findByContentId( | ||||||
|                 cloudFrontHost = coverImageHost, |                 cloudFrontHost = coverImageHost, | ||||||
|                 contentId = audioContent.id!!, |                 contentId = audioContent.id!!, | ||||||
|  |                 memberId = member.id!!, | ||||||
|  |                 isContentCreator = creatorId == member.id!!, | ||||||
|                 timezone = timezone, |                 timezone = timezone, | ||||||
|                 offset = 0, |                 offset = 0, | ||||||
|                 limit = 1 |                 limit = 1 | ||||||
| @@ -502,7 +504,11 @@ class AudioContentService( | |||||||
|  |  | ||||||
|         // 댓글 수 |         // 댓글 수 | ||||||
|         val commentCount = if (audioContent.isCommentAvailable) { |         val commentCount = if (audioContent.isCommentAvailable) { | ||||||
|             commentRepository.totalCountCommentByContentId(contentId = audioContent.id!!) |             commentRepository.totalCountCommentByContentId( | ||||||
|  |                 contentId = audioContent.id!!, | ||||||
|  |                 memberId = member.id!!, | ||||||
|  |                 isContentCreator = creatorId == member.id!! | ||||||
|  |             ) | ||||||
|         } else { |         } else { | ||||||
|             0 |             0 | ||||||
|         } |         } | ||||||
| @@ -666,7 +672,11 @@ class AudioContentService( | |||||||
|         val items = audioContentList |         val items = audioContentList | ||||||
|             .map { |             .map { | ||||||
|                 val commentCount = commentRepository |                 val commentCount = commentRepository | ||||||
|                     .totalCountCommentByContentId(it.contentId) |                     .totalCountCommentByContentId( | ||||||
|  |                         it.contentId, | ||||||
|  |                         memberId = member.id!!, | ||||||
|  |                         isContentCreator = creatorId == member.id!! | ||||||
|  |                     ) | ||||||
|                 it.commentCount = commentCount |                 it.commentCount = commentCount | ||||||
|  |  | ||||||
|                 val likeCount = audioContentLikeRepository |                 val likeCount = audioContentLikeRepository | ||||||
|   | |||||||
| @@ -55,6 +55,7 @@ class AudioContentCommentController(private val service: AudioContentCommentServ | |||||||
|         ApiResponse.ok( |         ApiResponse.ok( | ||||||
|             service.getCommentList( |             service.getCommentList( | ||||||
|                 audioContentId = audioContentId, |                 audioContentId = audioContentId, | ||||||
|  |                 memberId = member.id!!, | ||||||
|                 timezone = timezone, |                 timezone = timezone, | ||||||
|                 pageable = pageable |                 pageable = pageable | ||||||
|             ) |             ) | ||||||
|   | |||||||
| @@ -16,12 +16,14 @@ interface AudioContentCommentQueryRepository { | |||||||
|     fun findByContentId( |     fun findByContentId( | ||||||
|         cloudFrontHost: String, |         cloudFrontHost: String, | ||||||
|         contentId: Long, |         contentId: Long, | ||||||
|  |         memberId: Long, | ||||||
|  |         isContentCreator: Boolean, | ||||||
|         timezone: String, |         timezone: String, | ||||||
|         offset: Long, |         offset: Long, | ||||||
|         limit: Int |         limit: Int | ||||||
|     ): List<GetAudioContentCommentListItem> |     ): List<GetAudioContentCommentListItem> | ||||||
|  |  | ||||||
|     fun totalCountCommentByContentId(contentId: Long): Int |     fun totalCountCommentByContentId(contentId: Long, memberId: Long, isContentCreator: Boolean): Int | ||||||
|     fun commentReplyCountByAudioContentCommentId(commentId: Long): Int |     fun commentReplyCountByAudioContentCommentId(commentId: Long): Int | ||||||
|     fun getAudioContentCommentReplyList( |     fun getAudioContentCommentReplyList( | ||||||
|         cloudFrontHost: String, |         cloudFrontHost: String, | ||||||
| @@ -45,21 +47,32 @@ class AudioContentCommentQueryRepositoryImpl( | |||||||
|     override fun findByContentId( |     override fun findByContentId( | ||||||
|         cloudFrontHost: String, |         cloudFrontHost: String, | ||||||
|         contentId: Long, |         contentId: Long, | ||||||
|  |         memberId: Long, | ||||||
|  |         isContentCreator: Boolean, | ||||||
|         timezone: String, |         timezone: String, | ||||||
|         offset: Long, |         offset: Long, | ||||||
|         limit: Int |         limit: Int | ||||||
|     ): List<GetAudioContentCommentListItem> { |     ): List<GetAudioContentCommentListItem> { | ||||||
|         return queryFactory.selectFrom(audioContentComment) |         var where = audioContentComment.audioContent.id.eq(contentId) | ||||||
|             .where( |             .and(audioContentComment.isActive.isTrue) | ||||||
|                 audioContentComment.audioContent.id.eq(contentId) |             .and(audioContentComment.parent.isNull) | ||||||
|                     .and(audioContentComment.isActive.isTrue) |  | ||||||
|                     .and(audioContentComment.parent.isNull) |         if (!isContentCreator) { | ||||||
|  |             where = where.and( | ||||||
|  |                 audioContentComment.isSecret.isFalse | ||||||
|  |                     .or(audioContentComment.member.id.eq(memberId)) | ||||||
|             ) |             ) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return queryFactory | ||||||
|  |             .selectFrom(audioContentComment) | ||||||
|  |             .innerJoin(audioContentComment.audioContent, audioContent) | ||||||
|  |             .innerJoin(audioContentComment.member, member) | ||||||
|  |             .where(where) | ||||||
|             .offset(offset) |             .offset(offset) | ||||||
|             .limit(limit.toLong()) |             .limit(limit.toLong()) | ||||||
|             .orderBy(audioContentComment.createdAt.desc()) |             .orderBy(audioContentComment.createdAt.desc()) | ||||||
|             .fetch() |             .fetch() | ||||||
|             .asSequence() |  | ||||||
|             .map { |             .map { | ||||||
|                 val date = it.createdAt!! |                 val date = it.createdAt!! | ||||||
|                     .atZone(ZoneId.of("UTC")) |                     .atZone(ZoneId.of("UTC")) | ||||||
| @@ -75,22 +88,32 @@ class AudioContentCommentQueryRepositoryImpl( | |||||||
|                         "$cloudFrontHost/profile/default-profile.png" |                         "$cloudFrontHost/profile/default-profile.png" | ||||||
|                     }, |                     }, | ||||||
|                     comment = it.comment, |                     comment = it.comment, | ||||||
|  |                     isSecret = it.isSecret, | ||||||
|                     donationCan = it.donationCan ?: 0, |                     donationCan = it.donationCan ?: 0, | ||||||
|                     date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), |                     date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), | ||||||
|                     replyCount = commentReplyCountByAudioContentCommentId(it.id!!) |                     replyCount = commentReplyCountByAudioContentCommentId(it.id!!) | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
|             .toList() |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun totalCountCommentByContentId(contentId: Long): Int { |     override fun totalCountCommentByContentId(contentId: Long, memberId: Long, isContentCreator: Boolean): Int { | ||||||
|         return queryFactory.select(audioContentComment.id) |         var where = audioContentComment.audioContent.id.eq(contentId) | ||||||
|             .from(audioContentComment) |             .and(audioContentComment.isActive.isTrue) | ||||||
|             .where( |             .and(audioContentComment.parent.isNull) | ||||||
|                 audioContentComment.audioContent.id.eq(contentId) |  | ||||||
|                     .and(audioContentComment.parent.isNull) |         if (!isContentCreator) { | ||||||
|                     .and(audioContentComment.isActive.isTrue) |             where = where.and( | ||||||
|  |                 audioContentComment.isSecret.isFalse | ||||||
|  |                     .or(audioContentComment.member.id.eq(memberId)) | ||||||
|             ) |             ) | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return queryFactory | ||||||
|  |             .select(audioContentComment.id) | ||||||
|  |             .from(audioContentComment) | ||||||
|  |             .innerJoin(audioContentComment.audioContent, audioContent) | ||||||
|  |             .innerJoin(audioContentComment.member, member) | ||||||
|  |             .where(where) | ||||||
|             .fetch() |             .fetch() | ||||||
|             .size |             .size | ||||||
|     } |     } | ||||||
| @@ -140,6 +163,7 @@ class AudioContentCommentQueryRepositoryImpl( | |||||||
|                         "$cloudFrontHost/profile/default-profile.png" |                         "$cloudFrontHost/profile/default-profile.png" | ||||||
|                     }, |                     }, | ||||||
|                     comment = it.comment, |                     comment = it.comment, | ||||||
|  |                     isSecret = it.isSecret, | ||||||
|                     donationCan = it.donationCan ?: 0, |                     donationCan = it.donationCan ?: 0, | ||||||
|                     date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), |                     date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), | ||||||
|                     replyCount = 0 |                     replyCount = 0 | ||||||
|   | |||||||
| @@ -107,16 +107,27 @@ class AudioContentCommentService( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun getCommentList(audioContentId: Long, timezone: String, pageable: Pageable): GetAudioContentCommentListResponse { |     fun getCommentList( | ||||||
|         val commentList = |         audioContentId: Long, | ||||||
|             repository.findByContentId( |         memberId: Long, | ||||||
|                 cloudFrontHost = cloudFrontHost, |         timezone: String, | ||||||
|                 contentId = audioContentId, |         pageable: Pageable | ||||||
|                 timezone = timezone, |     ): GetAudioContentCommentListResponse { | ||||||
|                 offset = pageable.offset, |         val isContentCreator = audioContentRepository.isContentCreator(audioContentId, memberId) | ||||||
|                 limit = pageable.pageSize |         val commentList = repository.findByContentId( | ||||||
|             ) |             cloudFrontHost = cloudFrontHost, | ||||||
|         val totalCount = repository.totalCountCommentByContentId(audioContentId) |             contentId = audioContentId, | ||||||
|  |             memberId = memberId, | ||||||
|  |             isContentCreator = isContentCreator, | ||||||
|  |             timezone = timezone, | ||||||
|  |             offset = pageable.offset, | ||||||
|  |             limit = pageable.pageSize | ||||||
|  |         ) | ||||||
|  |         val totalCount = repository.totalCountCommentByContentId( | ||||||
|  |             contentId = audioContentId, | ||||||
|  |             memberId = memberId, | ||||||
|  |             isContentCreator = isContentCreator | ||||||
|  |         ) | ||||||
|  |  | ||||||
|         return GetAudioContentCommentListResponse(totalCount, commentList) |         return GetAudioContentCommentListResponse(totalCount, commentList) | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,16 +1,19 @@ | |||||||
| package kr.co.vividnext.sodalive.content.comment | package kr.co.vividnext.sodalive.content.comment | ||||||
|  |  | ||||||
|  | import com.querydsl.core.annotations.QueryProjection | ||||||
|  |  | ||||||
| data class GetAudioContentCommentListResponse( | data class GetAudioContentCommentListResponse( | ||||||
|     val totalCount: Int, |     val totalCount: Int, | ||||||
|     val items: List<GetAudioContentCommentListItem> |     val items: List<GetAudioContentCommentListItem> | ||||||
| ) | ) | ||||||
|  |  | ||||||
| data class GetAudioContentCommentListItem( | data class GetAudioContentCommentListItem @QueryProjection constructor( | ||||||
|     val id: Long, |     val id: Long, | ||||||
|     val writerId: Long, |     val writerId: Long, | ||||||
|     val nickname: String, |     val nickname: String, | ||||||
|     val profileUrl: String, |     val profileUrl: String, | ||||||
|     val comment: String, |     val comment: String, | ||||||
|  |     val isSecret: Boolean, | ||||||
|     val donationCan: Int, |     val donationCan: Int, | ||||||
|     val date: String, |     val date: String, | ||||||
|     val replyCount: Int |     val replyCount: Int | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ data class GetAudioContentOrderListResponse( | |||||||
| data class GetAudioContentOrderListItem @QueryProjection constructor( | data class GetAudioContentOrderListItem @QueryProjection constructor( | ||||||
|     val contentId: Long, |     val contentId: Long, | ||||||
|     val coverImageUrl: String, |     val coverImageUrl: String, | ||||||
|  |     val creatorId: Long, | ||||||
|     val creatorNickname: String, |     val creatorNickname: String, | ||||||
|     val title: String, |     val title: String, | ||||||
|     val themeStr: String, |     val themeStr: String, | ||||||
|   | |||||||
| @@ -126,6 +126,7 @@ class OrderQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Orde | |||||||
|                 QGetAudioContentOrderListItem( |                 QGetAudioContentOrderListItem( | ||||||
|                     audioContent.id, |                     audioContent.id, | ||||||
|                     audioContent.coverImage.prepend("/").prepend(coverImageHost), |                     audioContent.coverImage.prepend("/").prepend(coverImageHost), | ||||||
|  |                     audioContent.member.id, | ||||||
|                     audioContent.member.nickname, |                     audioContent.member.nickname, | ||||||
|                     audioContent.title, |                     audioContent.title, | ||||||
|                     audioContent.theme.theme, |                     audioContent.theme.theme, | ||||||
|   | |||||||
| @@ -98,10 +98,13 @@ class OrderService( | |||||||
|             offset = offset, |             offset = offset, | ||||||
|             limit = limit |             limit = limit | ||||||
|         ) |         ) | ||||||
|             .asSequence() |  | ||||||
|             .map { |             .map { | ||||||
|                 val commentCount = audioContentCommentQueryRepository |                 val commentCount = audioContentCommentQueryRepository | ||||||
|                     .totalCountCommentByContentId(it.contentId) |                     .totalCountCommentByContentId( | ||||||
|  |                         it.contentId, | ||||||
|  |                         memberId = member.id!!, | ||||||
|  |                         isContentCreator = it.creatorId == member.id!! | ||||||
|  |                     ) | ||||||
|  |  | ||||||
|                 val likeCount = audioContentLikeQueryRepository |                 val likeCount = audioContentLikeQueryRepository | ||||||
|                     .totalCountAudioContentLike(it.contentId) |                     .totalCountAudioContentLike(it.contentId) | ||||||
| @@ -110,7 +113,6 @@ class OrderService( | |||||||
|                 it.likeCount = likeCount |                 it.likeCount = likeCount | ||||||
|                 it |                 it | ||||||
|             } |             } | ||||||
|             .toList() |  | ||||||
|  |  | ||||||
|         return GetAudioContentOrderListResponse( |         return GetAudioContentOrderListResponse( | ||||||
|             totalCount = totalCount, |             totalCount = totalCount, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user