diff --git a/src/main/java/org/example/tree/domain/post/controller/PostController.java b/src/main/java/org/example/tree/domain/post/controller/PostController.java index 8e46a31..ce85600 100644 --- a/src/main/java/org/example/tree/domain/post/controller/PostController.java +++ b/src/main/java/org/example/tree/domain/post/controller/PostController.java @@ -18,15 +18,14 @@ public class PostController { private final PostService postService; - @PostMapping(value = "/trees/{treeId}/feed/posts", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping("/trees/{treeId}/feed/posts") public ApiResponse createPost( @PathVariable final Long treeId, @RequestHeader("Authorization") final String header, - @RequestPart(value="request") final PostRequestDTO.createPost request, - @RequestPart(value="images") final List images + @RequestBody final PostRequestDTO.createPost request ) throws Exception { String token = header.replace("Bearer ", ""); - return ApiResponse.onSuccess(postService.createPost(treeId, request, images, token)); + return ApiResponse.onSuccess(postService.createPost(treeId, request, token)); } @GetMapping("/trees/{treeId}/feed") diff --git a/src/main/java/org/example/tree/domain/post/converter/PostConverter.java b/src/main/java/org/example/tree/domain/post/converter/PostConverter.java index 60cd44c..d00ac2f 100644 --- a/src/main/java/org/example/tree/domain/post/converter/PostConverter.java +++ b/src/main/java/org/example/tree/domain/post/converter/PostConverter.java @@ -1,26 +1,21 @@ package org.example.tree.domain.post.converter; import lombok.RequiredArgsConstructor; -import org.example.tree.domain.post.dto.PostRequestDTO; import org.example.tree.domain.post.dto.PostResponseDTO; import org.example.tree.domain.post.entity.Post; import org.example.tree.domain.post.entity.PostImage; import org.example.tree.domain.profile.entity.Profile; import org.example.tree.domain.reaction.dto.ReactionResponseDTO; import org.example.tree.domain.tree.entity.Tree; -import org.example.tree.global.common.amazons3.S3UploadService; import org.springframework.stereotype.Component; -import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; @Component @RequiredArgsConstructor public class PostConverter { - private final S3UploadService s3UploadService; public Post toPost(String content, Profile profile) { return Post.builder() @@ -39,9 +34,6 @@ public PostResponseDTO.createPost toCreatePost(Post savedPost) { .collect(Collectors.toList()); return PostResponseDTO.createPost.builder() .postId(savedPost.getId()) - .postImageUrls(imageUrls) - .authorId(savedPost.getProfile().getMember().getId()) - .treeId(savedPost.getTree().getId()) .build(); } @@ -73,13 +65,12 @@ public PostResponseDTO.getPost toGetPost(Post post, int branchDegree, List toPostImages(List images) throws Exception { + public List toPostImages(List images) throws Exception { List postImages = new ArrayList<>(); - for(MultipartFile image :images) { - if (!image.isEmpty()) { - String postImageUrl = s3UploadService.uploadImage(image); // 이미지 업로드 후 URL 획득 + for(String imageUrl :images) { + if (imageUrl != null) {// 이미지 업로드 후 URL 획득 PostImage postImage = PostImage.builder() - .imageUrl(postImageUrl) // PostImage 엔티티에는 imageUrl 필드가 있어야 합니다. + .imageUrl(imageUrl) // PostImage 엔티티에는 imageUrl 필드가 있어야 합니다. .build(); postImages.add(postImage); } diff --git a/src/main/java/org/example/tree/domain/post/dto/PostRequestDTO.java b/src/main/java/org/example/tree/domain/post/dto/PostRequestDTO.java index f170385..9dbb1e2 100644 --- a/src/main/java/org/example/tree/domain/post/dto/PostRequestDTO.java +++ b/src/main/java/org/example/tree/domain/post/dto/PostRequestDTO.java @@ -4,6 +4,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -12,6 +14,7 @@ public class PostRequestDTO { @Getter public static class createPost { private String content; + private List images; } @Getter diff --git a/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java b/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java index 58b8509..643105e 100644 --- a/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java +++ b/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java @@ -16,9 +16,6 @@ public class PostResponseDTO { @AllArgsConstructor public static class createPost { private Long postId; - private List postImageUrls; - private String authorId; - private Long treeId; } @Builder diff --git a/src/main/java/org/example/tree/domain/post/service/PostService.java b/src/main/java/org/example/tree/domain/post/service/PostService.java index 8173314..a27bc8f 100644 --- a/src/main/java/org/example/tree/domain/post/service/PostService.java +++ b/src/main/java/org/example/tree/domain/post/service/PostService.java @@ -36,9 +36,9 @@ public class PostService { private final BranchService branchService; @Transactional - public PostResponseDTO.createPost createPost(Long treeId, PostRequestDTO.createPost request, List images, String token) throws Exception { + public PostResponseDTO.createPost createPost(Long treeId, PostRequestDTO.createPost request, String token) throws Exception { Profile profile = profileService.getTreeProfile(token, treeId); - List postImages = postConverter.toPostImages(images); + List postImages = postConverter.toPostImages(request.getImages()); Post post = postConverter.toPost(request.getContent(), profile); Post savedPost = postCommandService.createPost(post); for (PostImage postImage : postImages) { diff --git a/src/main/java/org/example/tree/domain/profile/controller/ProfileController.java b/src/main/java/org/example/tree/domain/profile/controller/ProfileController.java index 788b9c8..a24f9a1 100644 --- a/src/main/java/org/example/tree/domain/profile/controller/ProfileController.java +++ b/src/main/java/org/example/tree/domain/profile/controller/ProfileController.java @@ -15,22 +15,20 @@ public class ProfileController { private final ProfileService profileService; - @PostMapping(value = "/trees/owner/register", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping("/trees/owner/register") @Operation(summary = "트리하우스 설립자 프로필 등록", description = "트리하우스 오너 프로필을 등록합니다.") public ApiResponse registerTreeOwner( - @RequestPart ProfileRequestDTO.ownerProfile request, - @RequestPart("profileImage") final MultipartFile profileImage + @RequestBody ProfileRequestDTO.ownerProfile request ) throws Exception { - return ApiResponse.onSuccess(profileService.ownerProfile(request, profileImage)); + return ApiResponse.onSuccess(profileService.ownerProfile(request)); } - @PostMapping(value = "/trees/members/register", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping("/trees/members/register") @Operation(summary = "트리하우스 멤버 프로필 등록", description = "트리하우스 멤버 프로필을 등록합니다.") public ApiResponse registerTreeMember( - @RequestPart ProfileRequestDTO.createProfile request, - @RequestPart("profileImage") final MultipartFile profileImage + @RequestBody ProfileRequestDTO.createProfile request ) throws Exception { - return ApiResponse.onSuccess(profileService.createProfile(request, profileImage)); + return ApiResponse.onSuccess(profileService.createProfile(request)); } @GetMapping("/trees/{treeId}/members/{profileId}") //프로필 조회 diff --git a/src/main/java/org/example/tree/domain/profile/dto/ProfileRequestDTO.java b/src/main/java/org/example/tree/domain/profile/dto/ProfileRequestDTO.java index cae4f65..3ef43ad 100644 --- a/src/main/java/org/example/tree/domain/profile/dto/ProfileRequestDTO.java +++ b/src/main/java/org/example/tree/domain/profile/dto/ProfileRequestDTO.java @@ -12,7 +12,7 @@ public static class createProfile { private Long treeId; private String userId; private String memberName; - private MultipartFile profileImage; + private String profileImage; private String bio; } @@ -22,7 +22,7 @@ public static class ownerProfile { private Long treeId; private String userId; private String memberName; - private MultipartFile profileImage; + private String profileImage; private String bio; } diff --git a/src/main/java/org/example/tree/domain/profile/service/ProfileService.java b/src/main/java/org/example/tree/domain/profile/service/ProfileService.java index a11e382..2193e58 100644 --- a/src/main/java/org/example/tree/domain/profile/service/ProfileService.java +++ b/src/main/java/org/example/tree/domain/profile/service/ProfileService.java @@ -29,12 +29,11 @@ public class ProfileService { private final ProfileConverter profileConverter; private final TreeQueryService treeQueryService; private final MemberQueryService memberQueryService; - private final S3UploadService s3UploadService; private final BranchService branchService; private final InvitationQueryService invitationQueryService; @Transactional - public ProfileResponseDTO.createProfile createProfile(ProfileRequestDTO.createProfile request, MultipartFile profileImage) throws Exception { + public ProfileResponseDTO.createProfile createProfile(ProfileRequestDTO.createProfile request) throws Exception { Tree tree = treeQueryService.findById(request.getTreeId()); Member member = memberQueryService.findById(request.getUserId()); boolean isNewUser = profileQueryService.isNewUser(member); @@ -43,7 +42,7 @@ public ProfileResponseDTO.createProfile createProfile(ProfileRequestDTO.createPr currentProfile.inactivate(); profileCommandService.updateProfile(currentProfile); } - String profileImageUrl = !profileImage.isEmpty() ? s3UploadService.uploadImage(profileImage) : DEFAULT_PROFILE_IMAGE; + String profileImageUrl = request.getProfileImage() == null ? DEFAULT_PROFILE_IMAGE : request.getProfileImage(); Profile newProfile = profileConverter.toProfile(tree, member, request.getMemberName(), request.getBio(), profileImageUrl); profileCommandService.createProfile(newProfile); tree.increaseTreeSize(); @@ -54,7 +53,7 @@ public ProfileResponseDTO.createProfile createProfile(ProfileRequestDTO.createPr } @Transactional - public ProfileResponseDTO.createProfile ownerProfile(ProfileRequestDTO.ownerProfile request, MultipartFile profileImage) throws Exception { + public ProfileResponseDTO.createProfile ownerProfile(ProfileRequestDTO.ownerProfile request) throws Exception { Tree tree = treeQueryService.findById(request.getTreeId()); Member member = memberQueryService.findById(request.getUserId()); boolean isNewUser = profileQueryService.isNewUser(member); @@ -63,7 +62,7 @@ public ProfileResponseDTO.createProfile ownerProfile(ProfileRequestDTO.ownerProf currentProfile.inactivate(); profileCommandService.updateProfile(currentProfile); } - String profileImageUrl = !profileImage.isEmpty() ? s3UploadService.uploadImage(profileImage) : DEFAULT_PROFILE_IMAGE; + String profileImageUrl = request.getProfileImage() == null ? DEFAULT_PROFILE_IMAGE : request.getProfileImage(); Profile newProfile = profileConverter.toProfile(tree, member, request.getMemberName(), request.getBio(), profileImageUrl); profileCommandService.createProfile(newProfile); tree.increaseTreeSize();