From d03f3561e12dd5563448b7922031b31e6ab40120 Mon Sep 17 00:00:00 2001 From: 10 Date: Fri, 13 Dec 2024 13:20:07 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20=EC=9C=A0=EC=8B=A4=EB=AC=BC=20commentCn?= =?UTF-8?q?t=20=EC=A0=81=EC=9A=A9=20(#290)=20(#292)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/lost/adapter/web/in/dto/GetLostPostDto.kt | 5 +++-- .../api/lost/adapter/web/in/dto/SearchLostPostsDto.kt | 2 +- .../api/lost/application/service/LostPostService.kt | 10 +++++++--- .../api/comment/adapter/web/out/CommentPersistence.kt | 6 +++++- .../api/comment/adapter/web/out/CommentRepository.kt | 2 ++ .../api/comment/application/port/out/CommentReader.kt | 5 ++++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/GetLostPostDto.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/GetLostPostDto.kt index 287e9ca7..13204fac 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/GetLostPostDto.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/GetLostPostDto.kt @@ -15,7 +15,7 @@ class GetLostPostDto { val createdBy: String?, val createdAt: String, val subwayLineId: Long?, - val commentCnt: Int = 0, + val commentCnt: Int, val status: LostStatus, val storage: String?, val storageNumber: String?, @@ -27,7 +27,7 @@ class GetLostPostDto { val isFromLost112: Boolean ) { companion object { - fun of(entity: LostPostEntity, images: List, recommendPosts: List): Response { + fun of(entity: LostPostEntity, commentCnt: Int, images: List, recommendPosts: List): Response { return Response( id = entity.id, title = entity.title, @@ -36,6 +36,7 @@ class GetLostPostDto { createdBy = entity.createdBy, createdAt = entity.date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), subwayLineId = entity.subwayLine?.id, + commentCnt = commentCnt, status = entity.status, storage = entity.storage, storageNumber = entity.storageNumber, diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/SearchLostPostsDto.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/SearchLostPostsDto.kt index 80fde561..77838810 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/SearchLostPostsDto.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/adapter/web/in/dto/SearchLostPostsDto.kt @@ -32,7 +32,7 @@ class SearchLostPostsDto { val createdBy: String, val createdAt: String, val subwayLineId: Long?, - val commentCnt: Int = 0, + val commentCnt: Int, val status: LostStatus, val imageUrl: String?, val categoryName: String? diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt index 802ada6a..c1415126 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt @@ -1,5 +1,6 @@ package backend.team.ahachul_backend.api.lost.application.service +import backend.team.ahachul_backend.api.comment.application.port.out.CommentReader import backend.team.ahachul_backend.api.lost.adapter.web.`in`.dto.* import backend.team.ahachul_backend.api.lost.application.port.`in`.LostPostUseCase import backend.team.ahachul_backend.api.lost.application.port.out.CategoryReader @@ -34,20 +35,22 @@ class LostPostService( private val lostPostFileService: LostPostFileService, private val subwayLineReader: SubwayLineReader, private val memberReader: MemberReader, - private val categoryReader: CategoryReader + private val categoryReader: CategoryReader, + private val commentReader: CommentReader, ): LostPostUseCase { override fun getLostPost(id: Long): GetLostPostDto.Response { val entity = lostPostReader.getLostPost(id) val recommendPosts = getRecommendPosts(entity.subwayLine, entity.category) val recommendPostsDto = mapRecommendPostsDto(recommendPosts) + val commentCnt = commentReader.countLost(id) if (entity.origin == LostOrigin.LOST112) { - return GetLostPostDto.Response.of(entity, listOf(), recommendPostsDto) + return GetLostPostDto.Response.of(entity, commentCnt, listOf(), recommendPostsDto) } val files = lostPostFileReader.findAllByPostId(id) - return GetLostPostDto.Response.of(entity, convertToImageDto(files), recommendPostsDto) + return GetLostPostDto.Response.of(entity, commentCnt, convertToImageDto(files), recommendPostsDto) } private fun getRecommendPosts(subwayLine: SubwayLineEntity?, category:CategoryEntity?): List { @@ -116,6 +119,7 @@ class LostPostService( createdBy = it.createdBy, createdAt = it.date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")), subwayLineId = it.subwayLine?.id, + commentCnt = commentReader.countLost(it.id), status = it.status, imageUrl = getFileSource(it), categoryName = it.category?.name diff --git a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentPersistence.kt b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentPersistence.kt index f86b7048..ac3d1115 100644 --- a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentPersistence.kt +++ b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentPersistence.kt @@ -33,7 +33,11 @@ class CommentPersistence( return repository.findAllByLostPostId(postId) } - override fun count(postId: Long): Int { + override fun countCommunity(postId: Long): Int { return repository.countByCommunityPostId(postId) } + + override fun countLost(postId: Long): Int { + return repository.countByLostPostId(postId) + } } \ No newline at end of file diff --git a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentRepository.kt b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentRepository.kt index c5ae1f86..9e08f01e 100644 --- a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentRepository.kt +++ b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/adapter/web/out/CommentRepository.kt @@ -21,4 +21,6 @@ interface CommentRepository: JpaRepository { fun findAllByLostPostId(postId: Long): List fun countByCommunityPostId(postId: Long): Int + + fun countByLostPostId(postId: Long): Int } \ No newline at end of file diff --git a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/port/out/CommentReader.kt b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/port/out/CommentReader.kt index 79a91313..70393bbd 100644 --- a/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/port/out/CommentReader.kt +++ b/core/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/port/out/CommentReader.kt @@ -11,5 +11,8 @@ interface CommentReader { fun findAllByCommunityPostId(postId: Long): List fun findAllByLostPostId(postId: Long): List - fun count(postId: Long): Int + + fun countCommunity(postId: Long): Int + + fun countLost(postId: Long): Int } \ No newline at end of file