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
3 changes: 3 additions & 0 deletions src/docs/asciidoc/post-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ include::{snippetsDir}/savePost/1/request-part-data-fields.adoc[]
==== 성공 Response
include::{snippetsDir}/savePost/1/http-response.adoc[]

==== Response Body Fields
include::{snippetsDir}/savePost/1/response-fields.adoc[]

==== 실패 Response
실패 1. 인증되지 않은 유저일 경우

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.ftm.server.adapter.in.web.post.controller;

import com.ftm.server.adapter.in.web.post.dto.request.SavePostRequest;
import com.ftm.server.adapter.in.web.post.dto.response.SavePostResponse;
import com.ftm.server.application.command.post.SavePostCommand;
import com.ftm.server.application.port.in.post.SavePostUseCase;
import com.ftm.server.application.vo.post.PostInfoVo;
import com.ftm.server.common.response.ApiResponse;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import com.ftm.server.infrastructure.security.UserPrincipal;
Expand All @@ -24,17 +26,18 @@ public class SavePostController {
private final SavePostUseCase savePostUseCase;

@PostMapping("/api/posts")
public ResponseEntity<ApiResponse<Void>> savePost(
public ResponseEntity<ApiResponse<SavePostResponse>> savePost(
@RequestPart(value = "data") @Valid SavePostRequest request,
@RequestPart(value = "postImageFiles", required = false)
List<MultipartFile> postImageFiles,
@RequestPart(value = "productImageFiles", required = false)
List<MultipartFile> productImageFiles,
@AuthenticationPrincipal UserPrincipal userPrincipal) {
savePostUseCase.execute(
SavePostCommand.from(
userPrincipal.getId(), request, postImageFiles, productImageFiles));
PostInfoVo vo =
savePostUseCase.execute(
SavePostCommand.from(
userPrincipal.getId(), request, postImageFiles, productImageFiles));
return ResponseEntity.status(HttpStatus.CREATED)
.body(ApiResponse.success(SuccessResponseCode.CREATED));
.body(ApiResponse.success(SuccessResponseCode.CREATED, SavePostResponse.from(vo)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.ftm.server.adapter.in.web.post.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ftm.server.application.vo.post.PostInfoVo;
import java.time.LocalDateTime;
import lombok.Getter;

@Getter
public class SavePostResponse {

private final Long postId;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", shape = JsonFormat.Shape.STRING)
private final LocalDateTime createdAt;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm", shape = JsonFormat.Shape.STRING)
private final LocalDateTime updatedAt;

private SavePostResponse(PostInfoVo postInfoVo) {
this.postId = postInfoVo.getId();
this.createdAt = postInfoVo.getCreatedAt();
this.updatedAt = postInfoVo.getUpdatedAt();
}

public static SavePostResponse from(PostInfoVo postInfoVo) {
return new SavePostResponse(postInfoVo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private SavePostCommand(
List<MultipartFile> productImages) {
this.userId = userId;
this.title = request.getTitle();
this.groomingCategory = getGroomingCategory();
this.groomingCategory = request.getGroomingCategory();
this.hashTags = request.getHashtags().toArray(new HashTag[0]);
this.content = request.getContent();
this.postImages = postImages;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.ftm.server.application.port.in.post;

import com.ftm.server.application.command.post.SavePostCommand;
import com.ftm.server.application.vo.post.PostInfoVo;
import com.ftm.server.common.annotation.UseCase;

@UseCase
public interface SavePostUseCase {

void execute(SavePostCommand command);
PostInfoVo execute(SavePostCommand command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.ftm.server.application.port.out.s3.S3PostImageUploadPort;
import com.ftm.server.application.port.out.s3.S3PostProductImageUploadPort;
import com.ftm.server.application.port.out.transcation.AfterRollbackExecutorPort;
import com.ftm.server.application.vo.post.PostInfoVo;
import com.ftm.server.common.exception.CustomException;
import com.ftm.server.common.response.enums.ErrorResponseCode;
import com.ftm.server.domain.entity.Post;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class SavePostService implements SavePostUseCase {

@Override
@Transactional
public void execute(SavePostCommand command) {
public PostInfoVo execute(SavePostCommand command) {

// 상품, 상품이미지 검증
validateProductImages(command.getProducts(), command.getProductImages());
Expand Down Expand Up @@ -98,6 +99,8 @@ public void execute(SavePostCommand command) {
postProductImages.add(PostProductImage.createDefault(postProduct.getId()));
}
savePostProductImagePort.savePostProductImages(postProductImages);

return PostInfoVo.from(post);
}

private void validateProductImages(
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/ftm/server/application/vo/post/PostInfoVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.ftm.server.application.vo.post;

import com.ftm.server.domain.entity.Post;
import com.ftm.server.domain.enums.GroomingCategory;
import com.ftm.server.domain.enums.HashTag;
import java.time.LocalDateTime;
import lombok.Getter;

@Getter
public class PostInfoVo {

private final Long id;
private final String title;
private final String content;
private final GroomingCategory groomingCategory;
private final HashTag[] hashtags;
private final Integer viewCount;
private final Integer likeCount;
private final Boolean isDeleted;
private final LocalDateTime deletedAt;
private final LocalDateTime createdAt;
private final LocalDateTime updatedAt;

private PostInfoVo(Post post) {
this.id = post.getId();
this.title = post.getTitle();
this.content = post.getContent();
this.groomingCategory = post.getGroomingCategory();
this.hashtags = post.getHashtags();
this.viewCount = post.getViewCount();
this.likeCount = post.getLikeCount();
this.isDeleted = post.getIsDeleted();
this.deletedAt = post.getDeletedAt();
this.createdAt = post.getCreatedAt();
this.updatedAt = post.getUpdatedAt();
}

public static PostInfoVo from(Post post) {
return new PostInfoVo(post);
}
}
5 changes: 4 additions & 1 deletion src/test/java/com/ftm/server/post/SavePostTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public class SavePostTest extends BaseTest {
fieldWithPath("status").type(NUMBER).description("응답 상태"),
fieldWithPath("code").type(STRING).description("상태 코드"),
fieldWithPath("message").type(STRING).description("메시지"),
fieldWithPath("data").type(OBJECT).optional().description("응답 데이터"));
fieldWithPath("data").type(OBJECT).optional().description("응답 데이터"),
fieldWithPath("data.postId").type(NUMBER).description("생성된 유저픽 게시글 ID"),
fieldWithPath("data.createdAt").type(STRING).description("게시글 생성 날짜"),
fieldWithPath("data.updatedAt").type(STRING).description("게시글 수정 날짜"));

private ResultActions getResultActions(
MockHttpSession session,
Expand Down
Loading