Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : post와 comment 응답에 user id를 포함하도록 수정 #167

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ package io.csbroker.apiserver.controller.v1.post.response

import io.csbroker.apiserver.model.Comment
import java.time.LocalDateTime
import java.util.UUID

data class CommentResponseDto(
val id: Long,
val content: String,
val username: String,
val userId: UUID,
val likeCount: Long,
val isLiked: Boolean,
val createdAt: LocalDateTime,
) {
constructor(comment: Comment, likeCount: Long, isLiked: Boolean) : this(
id = comment.id,
content = comment.content,
userId = comment.user.id!!,
username = comment.user.username,
likeCount = likeCount,
isLiked = isLiked,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package io.csbroker.apiserver.controller.v1.post.response

import io.csbroker.apiserver.model.Post
import java.util.UUID

data class PostResponseDto(
val id: Long,
val content: String,
val username: String,
val userId: UUID,
val likeCount: Long,
val isLiked: Boolean,
val comments: List<CommentResponseDto>,
) {
constructor(post: Post, likeCount: Long, isLiked: Boolean, comments: List<CommentResponseDto>) : this(
id = post.id,
content = post.content,
userId = post.user.id!!,
username = post.user.username,
likeCount = likeCount,
isLiked = isLiked,
comments = comments,
comments = comments.sortedBy { it.createdAt },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오더링 디테일 좋네요👍

)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.springframework.restdocs.payload.JsonFieldType
import org.springframework.restdocs.payload.PayloadDocumentation
import org.springframework.restdocs.request.RequestDocumentation
import java.time.LocalDateTime
import java.util.UUID

class PostControllerTest : RestDocsTest() {
private lateinit var postService: PostService
Expand Down Expand Up @@ -101,13 +102,15 @@ class PostControllerTest : RestDocsTest() {
1L,
"CONTENT",
"USER",
UUID.randomUUID(),
1,
true,
listOf(
CommentResponseDto(
1L,
"CONTENT",
"USER",
UUID.randomUUID(),
1,
true,
LocalDateTime.now(),
Expand Down Expand Up @@ -138,6 +141,8 @@ class PostControllerTest : RestDocsTest() {
.type(JsonFieldType.STRING).description("글 내용"),
PayloadDocumentation.fieldWithPath("data[].username")
.type(JsonFieldType.STRING).description("작성자"),
PayloadDocumentation.fieldWithPath("data[].userId")
.type(JsonFieldType.STRING).description("작성자 ID"),
PayloadDocumentation.fieldWithPath("data[].likeCount")
.type(JsonFieldType.NUMBER).description("좋아요 수"),
PayloadDocumentation.fieldWithPath("data[].isLiked")
Expand All @@ -148,6 +153,8 @@ class PostControllerTest : RestDocsTest() {
.type(JsonFieldType.STRING).description("댓글 내용"),
PayloadDocumentation.fieldWithPath("data[].comments[].username")
.type(JsonFieldType.STRING).description("댓글 작성자"),
PayloadDocumentation.fieldWithPath("data[].comments[].userId")
.type(JsonFieldType.STRING).description("댓글 작성자 ID"),
PayloadDocumentation.fieldWithPath("data[].comments[].likeCount")
.type(JsonFieldType.NUMBER).description("좋아요 수"),
PayloadDocumentation.fieldWithPath("data[].comments[].isLiked")
Expand Down