Skip to content

Commit

Permalink
🐛 유실물 commentCnt 적용 (#290) (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
discphy authored Dec 13, 2024
1 parent ae4a590 commit d03f356
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand All @@ -27,7 +27,7 @@ class GetLostPostDto {
val isFromLost112: Boolean
) {
companion object {
fun of(entity: LostPostEntity, images: List<ImageDto>, recommendPosts: List<RecommendResponse>): Response {
fun of(entity: LostPostEntity, commentCnt: Int, images: List<ImageDto>, recommendPosts: List<RecommendResponse>): Response {
return Response(
id = entity.id,
title = entity.title,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<LostPostEntity> {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ interface CommentRepository: JpaRepository<CommentEntity, Long> {
fun findAllByLostPostId(postId: Long): List<CommentEntity>

fun countByCommunityPostId(postId: Long): Int

fun countByLostPostId(postId: Long): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ interface CommentReader {
fun findAllByCommunityPostId(postId: Long): List<CommentEntity>

fun findAllByLostPostId(postId: Long): List<CommentEntity>
fun count(postId: Long): Int

fun countCommunity(postId: Long): Int

fun countLost(postId: Long): Int
}

0 comments on commit d03f356

Please sign in to comment.