diff --git a/src/main/java/com/swyp8team2/post/presentation/CreatePostResponse.java b/src/main/java/com/swyp8team2/post/presentation/CreatePostResponse.java new file mode 100644 index 00000000..44467835 --- /dev/null +++ b/src/main/java/com/swyp8team2/post/presentation/CreatePostResponse.java @@ -0,0 +1,4 @@ +package com.swyp8team2.post.presentation; + +public record CreatePostResponse(Long postId) { +} diff --git a/src/main/java/com/swyp8team2/post/presentation/PostController.java b/src/main/java/com/swyp8team2/post/presentation/PostController.java index 8ed8b674..80596126 100644 --- a/src/main/java/com/swyp8team2/post/presentation/PostController.java +++ b/src/main/java/com/swyp8team2/post/presentation/PostController.java @@ -32,12 +32,12 @@ public class PostController { private final PostService postService; @PostMapping("") - public ResponseEntity createPost( + public ResponseEntity createPost( @Valid @RequestBody CreatePostRequest request, @AuthenticationPrincipal UserInfo userInfo ) { - postService.create(userInfo.userId(), request); - return ResponseEntity.ok().build(); + + return ResponseEntity.ok(new CreatePostResponse(postService.create(userInfo.userId(), request))); } @GetMapping("/{postId}") diff --git a/src/test/java/com/swyp8team2/post/presentation/PostControllerTest.java b/src/test/java/com/swyp8team2/post/presentation/PostControllerTest.java index 6823b72a..6041d4d4 100644 --- a/src/test/java/com/swyp8team2/post/presentation/PostControllerTest.java +++ b/src/test/java/com/swyp8team2/post/presentation/PostControllerTest.java @@ -48,6 +48,9 @@ void createPost() throws Exception { "제목", List.of(new PostImageRequestDto(1L), new PostImageRequestDto(2L)) ); + given(postService.create(any(), any())) + .willReturn(1L); + CreatePostResponse response = new CreatePostResponse(1L); //when then mockMvc.perform(post("/posts") @@ -55,6 +58,7 @@ void createPost() throws Exception { .content(objectMapper.writeValueAsString(request)) .header(HttpHeaders.AUTHORIZATION, "Bearer token")) .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(response))) .andDo(restDocs.document( requestHeaders(authorizationHeader()), requestFields( @@ -69,7 +73,13 @@ void createPost() throws Exception { fieldWithPath("images[].imageFileId") .type(JsonFieldType.NUMBER) .description("투표 후보 이미지 ID") - ))); + ), + responseFields( + fieldWithPath("postId") + .type(JsonFieldType.NUMBER) + .description("게시글 Id") + ) + )); } @Test