Skip to content

Commit

Permalink
[FIX #80] 자유게시판 게시글 등록 response 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jorippppong committed Feb 17, 2024
1 parent bf958ad commit 0c01177
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public PostResponseDto.MyPostResponseDto getTotalPostByKeyword(
}

@PostMapping("")
public ResponseEntity<PostResponseDto.SuccessResponseDto> createPost(
public ResponseEntity<PostResponseDto.PostIdResponseDto> createPost(
@RequestPart PostRequestDto data,
@RequestPart(required = false) List<MultipartFile> images
) throws IOException {
Member member = securityUtil.getUser();
postCommandService.createPost(data, images, member);
Long id = postCommandService.createPost(data, images, member);
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message("게시글을 성공적으로 등록했습니다.").build(),
PostResponseDto.PostIdResponseDto.builder().postId(id).build(),
HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public static class SuccessResponseDto{
private String message;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class PostIdResponseDto{
private Long postId;
}

@Builder
@Getter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PostCommandService {
* @throws IOException
*/
@Transactional
public void createPost(PostRequestDto data, List<MultipartFile> images, Member member) throws IOException {
public Long createPost(PostRequestDto data, List<MultipartFile> images, Member member) throws IOException {
Post newPost = Post.builder()
.member(member).title(data.getTitle())
.images(new ArrayList<>())
Expand All @@ -47,7 +47,8 @@ public void createPost(PostRequestDto data, List<MultipartFile> images, Member m
if(images != null && !images.isEmpty()){
newPost.getImages().addAll(setImageList(newPost, images));
}
postRepository.save(newPost);
Post post = postRepository.save(newPost);
return post.getId();
}

/**
Expand Down

0 comments on commit 0c01177

Please sign in to comment.