From dac7900eb355f328c40f8e18b776a85b96af5df7 Mon Sep 17 00:00:00 2001 From: Eddy <149242983+Jindongleee@users.noreply.github.com> Date: Thu, 7 Nov 2024 01:41:41 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=97=90=EC=9D=B4=ED=84=B0=20=EB=93=B1=EB=A1=9D=20API=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20#54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f2ebbe64d072a9cc9f6fbf2e38ce3784651b73ee. --- .../bucket/service/BucketService.java | 4 +-- .../bucket/service/BucketServiceImpl.java | 8 ++---- .../creator/controller/CreatorController.java | 10 +------ .../creator/dto/CreateCreatorReq.java | 2 -- .../creator/service/CreatorServiceImpl.java | 2 +- .../example/gather_back_end/domain/User.java | 10 +++---- .../user/controller/UserController.java | 9 ++++++ .../user/controller/UserControllerApi.java | 28 ++++++++++--------- .../service/CustomOAuth2UserServiceImpl.java | 7 ----- 9 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java b/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java index 2492494..a1ee535 100644 --- a/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java +++ b/src/main/java/org/example/gather_back_end/bucket/service/BucketService.java @@ -6,13 +6,11 @@ public interface BucketService { // 프로필 이미지 업로드 - void uploadProfileImg(MultipartFile file, Long userId) throws Exception; + UploadProfileImgRes uploadProfileImg(MultipartFile file, Long userId) throws Exception; // 파일 경로 받아오기 Long getPublicImgUrl(Long userId) throws Exception; // 파일 다운로드 MultipartFile downloadFile(Long userId, String type) throws Exception; - - String defaultProfileImgUrl(); } diff --git a/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java b/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java index 53843b0..4b18173 100644 --- a/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/bucket/service/BucketServiceImpl.java @@ -56,7 +56,7 @@ private UploadManager getManager(ObjectStorage client) { } @Override - public void uploadProfileImg(MultipartFile file, Long userId) throws Exception { + public UploadProfileImgRes uploadProfileImg(MultipartFile file, Long userId) throws Exception { User user = userRepository.getById(userId); @@ -85,6 +85,7 @@ public void uploadProfileImg(MultipartFile file, Long userId) throws Exception { log.info("이미지 업로드 완료: {}", profileImgUrl); client.close(); + return UploadProfileImgRes.from(profileImgUrl); } @Override @@ -104,9 +105,4 @@ private File convertMultiPartToFile(MultipartFile file) throws Exception { fos.close(); return convFile; } - - @Override - public String defaultProfileImgUrl() { - return DEFAULT_URI_PREFIX + BUCKET_NAME_SPACE + "/b/" + BUCKET_NAME + "/o/" + "default_profile.png"; - } } diff --git a/src/main/java/org/example/gather_back_end/creator/controller/CreatorController.java b/src/main/java/org/example/gather_back_end/creator/controller/CreatorController.java index 8090c67..e066e27 100644 --- a/src/main/java/org/example/gather_back_end/creator/controller/CreatorController.java +++ b/src/main/java/org/example/gather_back_end/creator/controller/CreatorController.java @@ -1,7 +1,6 @@ package org.example.gather_back_end.creator.controller; import lombok.RequiredArgsConstructor; -import org.example.gather_back_end.bucket.service.BucketService; import org.example.gather_back_end.creator.dto.CreateCreatorReq; import org.example.gather_back_end.creator.dto.GetCreatorRes; import org.example.gather_back_end.creator.service.CreatorService; @@ -17,9 +16,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; @RestController @RequiredArgsConstructor @@ -30,10 +27,9 @@ public class CreatorController { private final PortfolioService portfolioService; private final UserRepository userRepository; private final WorkService workService; - private final BucketService bucketService; @PostMapping() - public SuccessResponse createCreator(Authentication authentication, @RequestBody CreateCreatorReq req) throws Exception { + public SuccessResponse createCreator(Authentication authentication, @RequestBody CreateCreatorReq req) { CustomOAuth2User customOAuth2User = (CustomOAuth2User) authentication.getPrincipal(); @@ -45,10 +41,6 @@ public SuccessResponse createCreator(Authentication authentication, @RequestB portfolioService.createPortfolio(user.getId(), req.createPortfolioReqList()); workService.createWork(user.getId(), req.createWorkReqList()); - if (req.profileImgUrl() != null) { - bucketService.uploadProfileImg(req.profileImgUrl(), user.getId()); - } - creatorService.createCreator( user.getId(), req.nickname(), diff --git a/src/main/java/org/example/gather_back_end/creator/dto/CreateCreatorReq.java b/src/main/java/org/example/gather_back_end/creator/dto/CreateCreatorReq.java index fa1ecbb..323a06e 100644 --- a/src/main/java/org/example/gather_back_end/creator/dto/CreateCreatorReq.java +++ b/src/main/java/org/example/gather_back_end/creator/dto/CreateCreatorReq.java @@ -4,13 +4,11 @@ import org.example.gather_back_end.domain.User; import org.example.gather_back_end.portfolio.dto.CreatePortfolioReq; import org.example.gather_back_end.work.dto.CreateWorkReq; -import org.springframework.web.multipart.MultipartFile; import java.util.*; @Builder public record CreateCreatorReq( - MultipartFile profileImgUrl, String nickname, String introductionTitle, String introductionContent, diff --git a/src/main/java/org/example/gather_back_end/creator/service/CreatorServiceImpl.java b/src/main/java/org/example/gather_back_end/creator/service/CreatorServiceImpl.java index 767f211..2de4686 100644 --- a/src/main/java/org/example/gather_back_end/creator/service/CreatorServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/creator/service/CreatorServiceImpl.java @@ -31,7 +31,7 @@ public void createCreator( ){ User user = userRepository.getById(userId); - user.createCreatorInfo(user, nickname, introductionTitle, introductionContent, contactKakaoId, contactEmail); + user.createCreatorInfo(user,nickname, introductionTitle, introductionContent, contactKakaoId, contactEmail); userRepository.save(user); }; diff --git a/src/main/java/org/example/gather_back_end/domain/User.java b/src/main/java/org/example/gather_back_end/domain/User.java index 222c944..81e1a84 100644 --- a/src/main/java/org/example/gather_back_end/domain/User.java +++ b/src/main/java/org/example/gather_back_end/domain/User.java @@ -85,10 +85,8 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) private List workList = new ArrayList<>(); - // 유저 생성 - public static User createUserInfo(String profileImgUrl, String username, String name, String email, String role, String nickname) { + public static User createUserInfo(String username, String name, String email, String role, String nickname) { return User.builder() - .profileImgUrl(profileImgUrl) .username(username) .name(name) .email(email) @@ -103,6 +101,9 @@ public void updateUserInfo(String name, String email) { this.email = email; } + public static void updateProfileImgUrl(User user, String profileImgUrl) { + user.profileImgUrl = profileImgUrl; + } // 대학생 인증 시 유저 정보 업데이트 public static void updateStudentAuthInfo(User user) { @@ -134,7 +135,4 @@ public void createCreatorInfo( user.contactEmail = contactEmail; } - public static void updateProfileImgUrl(User user, String profileImgUrl) { - user.profileImgUrl = profileImgUrl; - } } diff --git a/src/main/java/org/example/gather_back_end/user/controller/UserController.java b/src/main/java/org/example/gather_back_end/user/controller/UserController.java index 764d323..e156a3d 100644 --- a/src/main/java/org/example/gather_back_end/user/controller/UserController.java +++ b/src/main/java/org/example/gather_back_end/user/controller/UserController.java @@ -12,4 +12,13 @@ @RequestMapping("/api/users") public class UserController implements UserControllerApi { + private final BucketService bucketService; + + @PostMapping("/{userId}/profileImg") + public SuccessResponse uploadProfileImg( + @PathVariable Long userId, // TODO: 나중에 Authentication 으로 바꾸기 + @RequestParam("file") MultipartFile file) throws Exception { + UploadProfileImgRes res = bucketService.uploadProfileImg(file, userId); + return SuccessResponse.of(res); + } } diff --git a/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java b/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java index 657a82c..95f538c 100644 --- a/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java +++ b/src/main/java/org/example/gather_back_end/user/controller/UserControllerApi.java @@ -17,17 +17,19 @@ @Tag(name = "User 관련", description = "유저와 관련된 API") public interface UserControllerApi { -// @Operation(summary = "프로필 사진 업로드", description = "유저의 프로필 사진을 업로드하는 API") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "200", description = "성공", -// content = @Content(mediaType = "application/json", -// examples = @ExampleObject(value = "{\n" -// + " \"timestamp\": \"2024-10-22T21:35:03.755865\",\n" -// + " \"isSuccess\": true,\n" -// + " \"code\": \"200\",\n" -// + " \"message\": \"호출에 성공하였습니다.\",\n" -// + " \"data\": null\n" -// + "}"), -// schema = @Schema(implementation = SuccessResponse.class))) -// }) + @Operation(summary = "프로필 사진 업로드", description = "유저의 프로필 사진을 업로드하는 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공", + content = @Content(mediaType = "application/json", + examples = @ExampleObject(value = "{\n" + + " \"timestamp\": \"2024-10-22T21:35:03.755865\",\n" + + " \"isSuccess\": true,\n" + + " \"code\": \"200\",\n" + + " \"message\": \"호출에 성공하였습니다.\",\n" + + " \"data\": null\n" + + "}"), + schema = @Schema(implementation = SuccessResponse.class))) + }) + @PostMapping("/{userId}/profileImg") + SuccessResponse uploadProfileImg(@PathVariable Long userId, @RequestParam("file") MultipartFile file) throws Exception; } diff --git a/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java b/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java index 95c2866..2288cf2 100644 --- a/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java @@ -6,7 +6,6 @@ import javax.crypto.SecretKey; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.example.gather_back_end.bucket.service.BucketService; import org.example.gather_back_end.domain.User; import org.example.gather_back_end.repository.UserRepository; import org.example.gather_back_end.util.jwt.dto.CustomOAuth2User; @@ -26,7 +25,6 @@ public class CustomOAuth2UserServiceImpl extends DefaultOAuth2UserService implem private final UserRepository userRepository; private final LocalDateTimeNumericEncryption localDateTimeNumericEncryption; - private final BucketService bucketService; @Override public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException { @@ -67,11 +65,9 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic User existData = userRepository.findByUsernameCustom(username); - // Default로 기본 이미지 넣기 (default_profile.png <- OCI) if (existData == null) { userRepository.save(User.createUserInfo( - bucketService.defaultProfileImgUrl(), username, oAuth2Response.getName(), oAuth2Response.getEmail(), @@ -89,13 +85,10 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic } else { - // 유저 정보 업데이트 existData.updateUserInfo(oAuth2Response.getName(), oAuth2Response.getEmail()); - // 업데이트 된 유저 정보 userRepository.save(existData); - // 수정된 이름과 이메일을 다시 토큰에 넣기 UserDto userDto = UserDto.builder() .username(existData.getUsername()) .name(existData.getName())