Skip to content
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
@@ -0,0 +1,4 @@
package com.swyp8team2.post.presentation;

public record CreatePostResponse(Long postId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class PostController {
private final PostService postService;

@PostMapping("")
public ResponseEntity<Void> createPost(
public ResponseEntity<CreatePostResponse> 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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ 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")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request))
.header(HttpHeaders.AUTHORIZATION, "Bearer token"))
.andExpect(status().isOk())
.andExpect(content().json(objectMapper.writeValueAsString(response)))
.andDo(restDocs.document(
requestHeaders(authorizationHeader()),
requestFields(
Expand All @@ -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
Expand Down