Skip to content

Commit

Permalink
🔨 Add chatCount in Item
Browse files Browse the repository at this point in the history
  • Loading branch information
wonseok committed Jan 31, 2025
1 parent 993cfe3 commit a4e1bce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ArticleController(
val articles: List<ArticleEntity> = articleService.getPreviousArticles(articleId)
val response: List<Item> =
articles.map { article ->
Item.fromArticle(Article.fromEntity(article))
Item.fromArticle(Article.fromEntity(article), articleService.getChattingUsersByArticle(Article.fromEntity(article)).size)
}
return ResponseEntity.ok(response)
}
Expand All @@ -108,7 +108,7 @@ class ArticleController(
val articles: List<ArticleEntity> = articleService.getArticlesThatUserLikes(user.id, articleId)
val response =
articles.map { article ->
Item.fromArticle(Article.fromEntity(article))
Item.fromArticle(Article.fromEntity(article), articleService.getChattingUsersByArticle(Article.fromEntity(article)).size)
}
return ResponseEntity.ok(response)
}
Expand All @@ -121,7 +121,7 @@ class ArticleController(
val articles: List<ArticleEntity> = articleService.getArticlesBySeller(user.id, articleId)
val response: List<Item> =
articles.map { article ->
Item.fromArticle(Article.fromEntity(article))
Item.fromArticle(Article.fromEntity(article), articleService.getChattingUsersByArticle(Article.fromEntity(article)).size)
}
return ResponseEntity.ok(response)
}
Expand All @@ -134,7 +134,7 @@ class ArticleController(
val articles = articleService.getArticlesByBuyer(user.id, articleId)
val response: List<Item> =
articles.map { article ->
Item.fromArticle(Article.fromEntity(article))
Item.fromArticle(Article.fromEntity(article), articleService.getChattingUsersByArticle(Article.fromEntity(article)).size)
}
return ResponseEntity.ok(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ data class Item(
val imagePresignedUrl: String,
val createdAt: Instant,
val likeCount: Int,
val chatCount: Int,
) {
companion object {
fun fromArticle(article: Article): Item {
fun fromArticle(
article: Article,
chatCount: Int,
): Item {
return Item(
id = article.id,
title = article.title,
Expand All @@ -24,6 +28,7 @@ data class Item(
imagePresignedUrl = if (article.imagePresignedUrl.isEmpty()) "" else article.imagePresignedUrl.first(),
createdAt = article.createdAt,
likeCount = article.likeCount,
chatCount = chatCount,
)
}
}
Expand Down

0 comments on commit a4e1bce

Please sign in to comment.