From b9f47b3cf88078656820475ada819178f545f5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Mon, 14 Oct 2024 20:32:22 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=EA=B3=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20URL=EC=9D=B4=20=EB=94=B0=EB=A1=9C?= =?UTF-8?q?=20=EB=84=98=EC=96=B4=EC=98=A4=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DarakbangMemberController.java | 10 ++++++++-- .../controller/swagger/DarakbangMemberSwagger.java | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java index ff061659a..8a1945915 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java @@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import mouda.backend.common.config.argumentresolver.LoginDarakbangMember; import mouda.backend.common.config.argumentresolver.LoginMember; import mouda.backend.common.response.RestResponse; @@ -22,6 +23,7 @@ import mouda.backend.member.domain.Member; import mouda.backend.member.presentation.response.DarakbangMemberInfoResponse; +@Slf4j @RestController @RequestMapping("/v1/darakbang") @RequiredArgsConstructor @@ -68,11 +70,15 @@ public ResponseEntity> findMyInfo( }) public ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestPart(value = "profile_img", required = false) MultipartFile profile_img, + @RequestPart(value = "file", required = false) MultipartFile file, + @RequestPart(value = "profile", required = false) String profile, @RequestPart("nickname") String nickname, @RequestPart(value = "description", required = false) String description ) { - darakbangMemberService.updateMyInfo(darakbangMember, profile_img, nickname, description); + + log.info("file : {}, profile : {}, nickname : {}, description : {}", file.toString(), profile, nickname, + description); + darakbangMemberService.updateMyInfo(darakbangMember, file, nickname, description); return ResponseEntity.ok().build(); } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java index 1efcb55b7..43b9d2a0e 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java @@ -54,6 +54,7 @@ ResponseEntity> findMyInfo( ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember member, @RequestPart MultipartFile file, + @RequestPart String profile, @RequestPart String nickname, @RequestPart String description ); From b133a6c6319e427721841ce9ed79a7c2e45df5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Mon, 14 Oct 2024 21:25:41 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EC=83=88=EB=A1=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=90=9C=20=ED=8C=8C=EC=9D=BC=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20S3=EC=97=85=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/DarakbangMemberService.java | 11 ++++++++--- .../darakbangmember/domain/DarakbangMember.java | 7 +++++++ .../implement/DarakbangMemberWriter.java | 4 ++++ .../controller/DarakbangMemberController.java | 3 --- .../controller/swagger/DarakbangMemberSwagger.java | 1 - 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java index b00111b78..d255ecb80 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java @@ -62,8 +62,13 @@ public void updateMyInfo( DarakbangMember darakbangMember, MultipartFile file, String nickname, String description ) { - String url = s3Client.uploadFile(file); - String profile = imageParser.parse(url); - darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, profile); + if (file != null) { // 새로 추가된 파일이 있는 경우 + String url = s3Client.uploadFile(file); // S3 Upload + String newProfileUrl = imageParser.parse(url); // 새로 저장할 profile url + darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, newProfileUrl); + return; + } + // 이미지 변경 없이 닉네임과 소개을 그대로 저장하는 경우 + darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description); } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java b/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java index 0340e26bd..0d3e7488d 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java @@ -84,6 +84,13 @@ public boolean isNotManager() { return role != DarakBangMemberRole.MANAGER; } + public DarakbangMember updateMyInfo(String nickname, String description) { + this.nickname = nickname; + this.description = description; + + return this; + } + public DarakbangMember updateMyInfo(String nickname, String description, String profile) { this.nickname = nickname; this.description = description; diff --git a/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberWriter.java b/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberWriter.java index 61ad24936..6b816456a 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberWriter.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/implement/DarakbangMemberWriter.java @@ -45,6 +45,10 @@ public DarakbangMember saveMember(Darakbang darakbang, String nickname, Member m } } + public void updateMyInfo(DarakbangMember darakbangMember, String nickname, String description) { + darakbangMemberRepository.save(darakbangMember.updateMyInfo(nickname, description)); + } + public void updateMyInfo(DarakbangMember darakbangMember, String nickname, String description, String profile) { darakbangMemberRepository.save(darakbangMember.updateMyInfo(nickname, description, profile)); } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java index 8a1945915..598540786 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java @@ -71,13 +71,10 @@ public ResponseEntity> findMyInfo( public ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember darakbangMember, @RequestPart(value = "file", required = false) MultipartFile file, - @RequestPart(value = "profile", required = false) String profile, @RequestPart("nickname") String nickname, @RequestPart(value = "description", required = false) String description ) { - log.info("file : {}, profile : {}, nickname : {}, description : {}", file.toString(), profile, nickname, - description); darakbangMemberService.updateMyInfo(darakbangMember, file, nickname, description); return ResponseEntity.ok().build(); diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java index 43b9d2a0e..1efcb55b7 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java @@ -54,7 +54,6 @@ ResponseEntity> findMyInfo( ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember member, @RequestPart MultipartFile file, - @RequestPart String profile, @RequestPart String nickname, @RequestPart String description ); From c31fa6dade7454817799cc272af366b640cf5ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Mon, 14 Oct 2024 22:46:15 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=ED=98=B9?= =?UTF-8?q?=EC=9D=80=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20DB=20Prof?= =?UTF-8?q?ile=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/DarakbangMemberService.java | 12 ++++++++---- .../controller/DarakbangMemberController.java | 4 ++-- .../controller/swagger/DarakbangMemberSwagger.java | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java index d255ecb80..0406f94c3 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java @@ -59,8 +59,8 @@ public DarakbangMemberInfoResponse findMyInfo(DarakbangMember darakbangMember) { } public void updateMyInfo( - DarakbangMember darakbangMember, MultipartFile file, - String nickname, String description + DarakbangMember darakbangMember, String isReset, + MultipartFile file, String nickname, String description ) { if (file != null) { // 새로 추가된 파일이 있는 경우 String url = s3Client.uploadFile(file); // S3 Upload @@ -68,7 +68,11 @@ public void updateMyInfo( darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, newProfileUrl); return; } - // 이미지 변경 없이 닉네임과 소개을 그대로 저장하는 경우 - darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description); + if (isReset.equals("true")) { // 기본 이미지 변경 시 + // darakbangMemberWriter.removeProfile(darakbangMember); // 기본 이미지가 원래 있는데 true => db propfile -> null + darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, null); + } else { // 이미지 변경 없이 닉네임과 소개을 그대로 저장하는 경우 + darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description); + } } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java index 598540786..4453aa777 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/DarakbangMemberController.java @@ -70,12 +70,12 @@ public ResponseEntity> findMyInfo( }) public ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember darakbangMember, + @RequestPart(value = "isReset") String isReset, @RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("nickname") String nickname, @RequestPart(value = "description", required = false) String description ) { - - darakbangMemberService.updateMyInfo(darakbangMember, file, nickname, description); + darakbangMemberService.updateMyInfo(darakbangMember, isReset, file, nickname, description); return ResponseEntity.ok().build(); } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java index 1efcb55b7..3916a2fe3 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/presentation/controller/swagger/DarakbangMemberSwagger.java @@ -53,6 +53,7 @@ ResponseEntity> findMyInfo( }) ResponseEntity updateMyInfo( @LoginDarakbangMember DarakbangMember member, + @RequestPart String isReset, @RequestPart MultipartFile file, @RequestPart String nickname, @RequestPart String description From 76436c183ef16a2d002b03d4e1b6ac3926dc1eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Wed, 16 Oct 2024 14:22:21 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20=EC=95=A0=ED=94=8C=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/business/AppleAuthService.java | 32 ++++++++++++++++--- .../auth/exception/AuthErrorMessage.java | 3 +- .../controller/AppleAuthController.java | 20 +++--------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java index a96475280..ff4e5f317 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java @@ -1,13 +1,20 @@ package mouda.backend.auth.business; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import mouda.backend.auth.business.result.LoginProcessResult; +import mouda.backend.auth.exception.AuthErrorMessage; +import mouda.backend.auth.exception.AuthException; import mouda.backend.auth.implement.AppleOauthManager; import mouda.backend.auth.implement.LoginManager; import mouda.backend.auth.implement.jwt.AccessTokenProvider; +import mouda.backend.auth.presentation.controller.AppleUserInfoRequest; import mouda.backend.auth.presentation.request.AppleOauthRequest; import mouda.backend.auth.presentation.response.LoginResponse; import mouda.backend.member.domain.LoginDetail; @@ -26,6 +33,7 @@ public class AppleAuthService { private final MemberWriter memberWriter; private final AppleOauthManager appleOauthManager; private final AccessTokenProvider accessTokenProvider; + private final ObjectMapper objectMapper; public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) { Member member = memberFinder.findByNonce(oauthRequest.nonce()); @@ -39,11 +47,27 @@ public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) { return new LoginResponse(result.accessToken()); } - public String save(String idToken, String firstName, String lastName) { - log.info("idToken: {}, firstName: {}, lastName: {}", idToken, firstName, lastName); + + public String getAccessToken(String idToken) { + String socialLoginId = appleOauthManager.getSocialLoginId(idToken); + Member member = memberFinder.findBySocialId(socialLoginId); + return accessTokenProvider.provide(member); + } + + public void save(String idToken, String user) { + try { + AppleUserInfoRequest request = objectMapper.readValue(user, AppleUserInfoRequest.class); + String firstName = request.name().firstName(); + String lastName = request.name().lastName(); + saveMember(idToken, firstName, lastName); + } catch (JsonProcessingException exception) { + throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.APPLE_USER_BAD_REQUEST) + } + } + + private void saveMember(String idToken, String firstName, String lastName) { String socialLoginId = appleOauthManager.getSocialLoginId(idToken); Member member = new Member(lastName + firstName, new LoginDetail(OauthType.APPLE, socialLoginId)); - Member savedMember = memberWriter.append(member); - return accessTokenProvider.provide(savedMember); + memberWriter.append(member); } } diff --git a/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java b/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java index 9dc060781..a2b1d7ff9 100644 --- a/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java +++ b/backend/src/main/java/mouda/backend/auth/exception/AuthErrorMessage.java @@ -18,7 +18,8 @@ public enum AuthErrorMessage { KAKAO_CONNECT_TIMEOUT("커넥션 타임아웃 되었습니다."), DARAKBANG_NOT_ENTERED("가입한 다락방이 아닙니다."), MEMBER_NOT_FOUND("회원가입 이력을 찾을 수 없습니다."), - KAKAO_CANNOT_SIGNUP("기존 카카오 로그인 이력이 있는 사용자만 이용할 수 있는 서비스입니다. 새로운 회원은 다른 로그인 서비스를 이용해주세요."); + KAKAO_CANNOT_SIGNUP("기존 카카오 로그인 이력이 있는 사용자만 이용할 수 있는 서비스입니다. 새로운 회원은 다른 로그인 서비스를 이용해주세요."), + APPLE_USER_BAD_REQUEST("잘못된 애플 로그인 요청입니다."); private final String message; } diff --git a/backend/src/main/java/mouda/backend/auth/presentation/controller/AppleAuthController.java b/backend/src/main/java/mouda/backend/auth/presentation/controller/AppleAuthController.java index 013228eaa..dcf5bd57e 100644 --- a/backend/src/main/java/mouda/backend/auth/presentation/controller/AppleAuthController.java +++ b/backend/src/main/java/mouda/backend/auth/presentation/controller/AppleAuthController.java @@ -1,7 +1,6 @@ package mouda.backend.auth.presentation.controller; import java.io.IOException; -import java.util.Map; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -10,12 +9,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.databind.ObjectMapper; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import mouda.backend.auth.business.AppleAuthService; -import mouda.backend.auth.util.TokenDecoder; @RestController @Slf4j @@ -23,24 +19,16 @@ public class AppleAuthController { private final AppleAuthService appleAuthService; - private final ObjectMapper objectMapper; @PostMapping("/v1/oauth/apple") public ResponseEntity test( - @RequestParam("code") String code, @RequestParam("id_token") String id_token, - @RequestParam("user") String user + @RequestParam(name = "user", required = false) String user ) throws IOException { - AppleUserInfoRequest request = objectMapper.readValue(user, AppleUserInfoRequest.class); - - String firstName = request.name().firstName(); - String lastName = request.name().lastName(); - Map stringStringMap = TokenDecoder.parseIdToken(id_token); - for (String s : stringStringMap.keySet()) { - log.info("{} : {}", s, stringStringMap.get(s)); + if (user != null) { + appleAuthService.save(id_token, user); } - log.error("firstName : {}, lastNAme: {}", firstName, lastName); - String accessToken = appleAuthService.save(id_token, firstName, lastName); + String accessToken = appleAuthService.getAccessToken(id_token); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Location", "https://dev.mouda.site/oauth/apple?token=" + accessToken); return new ResponseEntity<>(httpHeaders, HttpStatus.FOUND); From 42f2fd64112fd2c64339b71a8008463eb87ddaca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Wed, 16 Oct 2024 16:16:56 +0900 Subject: [PATCH 5/7] =?UTF-8?q?test:=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=ED=95=98=EA=B3=A0=20=EC=BC=80=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=EB=B3=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/auth/business/AppleAuthService.java | 3 +-- .../business/DarakbangMemberService.java | 11 +++++------ .../darakbangmember/implement/ImageParser.java | 2 -- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java index ff4e5f317..24d44cb0f 100644 --- a/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java +++ b/backend/src/main/java/mouda/backend/auth/business/AppleAuthService.java @@ -47,7 +47,6 @@ public LoginResponse oauthLogin(AppleOauthRequest oauthRequest) { return new LoginResponse(result.accessToken()); } - public String getAccessToken(String idToken) { String socialLoginId = appleOauthManager.getSocialLoginId(idToken); Member member = memberFinder.findBySocialId(socialLoginId); @@ -61,7 +60,7 @@ public void save(String idToken, String user) { String lastName = request.name().lastName(); saveMember(idToken, firstName, lastName); } catch (JsonProcessingException exception) { - throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.APPLE_USER_BAD_REQUEST) + throw new AuthException(HttpStatus.BAD_REQUEST, AuthErrorMessage.APPLE_USER_BAD_REQUEST); } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java index 0406f94c3..8ef6aa252 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java @@ -62,16 +62,15 @@ public void updateMyInfo( DarakbangMember darakbangMember, String isReset, MultipartFile file, String nickname, String description ) { - if (file != null) { // 새로 추가된 파일이 있는 경우 - String url = s3Client.uploadFile(file); // S3 Upload - String newProfileUrl = imageParser.parse(url); // 새로 저장할 profile url + if (file != null) { + String url = s3Client.uploadFile(file); + String newProfileUrl = imageParser.parse(url); darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, newProfileUrl); return; } - if (isReset.equals("true")) { // 기본 이미지 변경 시 - // darakbangMemberWriter.removeProfile(darakbangMember); // 기본 이미지가 원래 있는데 true => db propfile -> null + if (isReset.equals("true")) { darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, null); - } else { // 이미지 변경 없이 닉네임과 소개을 그대로 저장하는 경우 + } else { darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description); } } diff --git a/backend/src/main/java/mouda/backend/darakbangmember/implement/ImageParser.java b/backend/src/main/java/mouda/backend/darakbangmember/implement/ImageParser.java index 06c3ef430..2fe0c3c39 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/implement/ImageParser.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/implement/ImageParser.java @@ -16,8 +16,6 @@ public class ImageParser { private String prefix; public String parse(String url) { - log.info("ImageParser url : {}", url); - String[] split = url.split(URL_DELIMITER); StringBuilder profile = new StringBuilder(prefix); From b02091400dc1d36154d84a44e5a92fa5df19f3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Wed, 16 Oct 2024 16:18:06 +0900 Subject: [PATCH 6/7] =?UTF-8?q?test:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=88=98=EC=A0=95=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `@MockBean`을 Nested 내부에 작성하면 에러가 터져서 외부에 선언하였습니다. --- .../business/DarakbangMemberServiceTest.java | 79 ++++++++++++++++++- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java b/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java index a56f4604e..1d7dbece5 100644 --- a/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java +++ b/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java @@ -1,18 +1,25 @@ package mouda.backend.darakbangmember.business; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import mouda.backend.common.fixture.DarakbangMemberFixture; import mouda.backend.common.fixture.DarakbangSetUp; import mouda.backend.common.fixture.MemberFixture; -import mouda.backend.darakbang.infrastructure.DarakbangRepository; import mouda.backend.darakbangmember.domain.DarakbangMember; +import mouda.backend.darakbangmember.implement.S3Client; import mouda.backend.darakbangmember.infrastructure.DarakbangMemberRepository; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberResponses; import mouda.backend.darakbangmember.presentation.response.DarakbangMemberRoleResponse; @@ -29,12 +36,15 @@ class DarakbangMemberServiceTest extends DarakbangSetUp { @Autowired private DarakbangMemberRepository darakbangMemberRepository; - @Autowired - private DarakbangRepository darakbangRepository; - @Autowired private DarakbangMemberService darakbangMemberService; + @MockBean + private S3Client s3Client; + + @Value("${aws.s3.prefix}") + private String prefix; + @DisplayName("다락방 멤버 권한 조회 테스트") @Nested class DarakbangMemberRoleReadTest { @@ -86,4 +96,65 @@ void findMyInfo() { assertThat(response.profile()).isEqualTo("profile"); assertThat(response.description()).isEqualTo("description"); } + + @DisplayName("마이페이지 수정 테스트") + @Nested + class UpdateMyInfoTest { + + private String nickname = "수정된 닉네임"; + private String description = "수정된 소개"; + + @DisplayName("이미지 추가 없이 닉네임, 소개만 변경하는 경우 S3 통신 없이 DB값을 변경한다.") + @Test + void updateMyInfoWhenNoProfileUpdate() { + // when + darakbangMemberService.updateMyInfo(darakbangAnna, "false", null, nickname, description); + + // then + Optional annaOptional = darakbangMemberRepository.findById(darakbangAnna.getId()); + assertThat(annaOptional.isPresent()).isTrue(); + assertThat(annaOptional.get().getNickname()).isEqualTo(nickname); + assertThat(annaOptional.get().getDescription()).isEqualTo(description); + + verify(s3Client, times(0)).uploadFile(any()); + } + + @DisplayName("이미지 추가와 더불어 닉네임, 소개를 변경하는 경우 S3 통신과 함께 DB 값을 변경한다.") + @Test + void updateMyInfoWithProfileUpdate() { + // given + MockMultipartFile file = new MockMultipartFile("file", "test-file.txt", + MediaType.TEXT_PLAIN_VALUE, "Hello, World!".getBytes()); + when(s3Client.uploadFile(any())).thenReturn("https://s3url/uuid.png"); + + // when + darakbangMemberService.updateMyInfo(darakbangAnna, "false", file, nickname, description); + + // then + Optional annaOptional = darakbangMemberRepository.findById(darakbangAnna.getId()); + assertThat(annaOptional.isPresent()).isTrue(); + assertThat(annaOptional.get().getNickname()).isEqualTo(nickname); + assertThat(annaOptional.get().getDescription()).isEqualTo(description); + String expectedUrl = prefix + "uuid.png"; + assertThat(annaOptional.get().getProfile()).isEqualTo(expectedUrl); + + verify(s3Client, times(1)).uploadFile(any()); + } + + @DisplayName("기존 이미지로 변경하는 경우 S3 통신 없이 DB의 프로필 이미지 URL 값을 제거한다.") + @Test + void updateMyInfoWithBasicProfileUpdate() { + // when + darakbangMemberService.updateMyInfo(darakbangAnna, "true", null, nickname, description); + + // then + Optional annaOptional = darakbangMemberRepository.findById(darakbangAnna.getId()); + assertThat(annaOptional.isPresent()).isTrue(); + assertThat(annaOptional.get().getNickname()).isEqualTo(nickname); + assertThat(annaOptional.get().getDescription()).isEqualTo(description); + assertThat(annaOptional.get().getProfile()).isNull(); + + verify(s3Client, times(0)).uploadFile(any()); + } + } } From 50dc5b7b07684ebb92d7ef2f4ccc324fb5cf7ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EA=B2=B8?= Date: Wed, 16 Oct 2024 17:03:54 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B2=BD=EC=9A=B0=EC=97=90=EB=8F=84=20S3=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/DarakbangMemberService.java | 11 ++++++++--- .../business/DarakbangMemberServiceTest.java | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java index 6690ed4f4..7c2b82c3d 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/business/DarakbangMemberService.java @@ -65,16 +65,21 @@ public void updateMyInfo( if (file != null) { String url = s3Client.uploadFile(file); String newProfileUrl = imageParser.parse(url); - if (darakbangMember.hasImage()) { - s3Client.deleteFile(darakbangMember.getProfile()); - } + deleteProfile(darakbangMember); darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, newProfileUrl); return; } if (isReset.equals("true")) { + deleteProfile(darakbangMember); darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description, null); } else { darakbangMemberWriter.updateMyInfo(darakbangMember, nickname, description); } } + + private void deleteProfile(DarakbangMember darakbangMember) { + if (darakbangMember.hasImage()) { + s3Client.deleteFile(darakbangMember.getProfile()); + } + } } diff --git a/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java b/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java index 1d7dbece5..a65a22bd3 100644 --- a/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java +++ b/backend/src/test/java/mouda/backend/darakbangmember/business/DarakbangMemberServiceTest.java @@ -144,6 +144,9 @@ void updateMyInfoWithProfileUpdate() { @DisplayName("기존 이미지로 변경하는 경우 S3 통신 없이 DB의 프로필 이미지 URL 값을 제거한다.") @Test void updateMyInfoWithBasicProfileUpdate() { + // given + doNothing().when(s3Client).deleteFile(anyString()); + // when darakbangMemberService.updateMyInfo(darakbangAnna, "true", null, nickname, description);