Skip to content

Commit

Permalink
feat : post와 comment 응답에 user id를 포함하도록 수정 (#167)
Browse files Browse the repository at this point in the history
* feat : post와 comment 응답에 user id를 포함하도록 수정

* update restdocs
  • Loading branch information
kshired authored Dec 17, 2023
1 parent 96656d1 commit 57fa5bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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 },
)
}
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

0 comments on commit 57fa5bb

Please sign in to comment.