From 20b11af7af056585bf897cca54a4fca0f945897f Mon Sep 17 00:00:00 2001 From: junwon <67488973+wjdwnsdnjs13@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:10:29 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=95=88=EB=93=9C=EB=A1=9C?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=EC=97=90=20=EB=A7=9E=EB=8F=84=EB=A1=9D=20acc?= =?UTF-8?q?essToken=EC=9C=BC=EB=A1=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85/=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=B2=98=EB=A6=AC=20(#?= =?UTF-8?q?61)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 25 ++++++++++++++----- .../member/dto/request/RegisterReq.java | 6 ++--- .../spot/jpa/oauth/OauthRepositoryImpl.java | 1 + .../usecase/port/in/member/MemberUsecase.java | 4 ++- .../usecase/service/member/MemberService.java | 11 +++++--- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java b/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java index 9829b95c..e9d91194 100644 --- a/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java +++ b/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java @@ -39,20 +39,23 @@ public class MemberController { public JwtTokenResponse create(@RequestBody @Valid RegisterReq request) { Member member = request.toDomain(); - Member memberResult = memberUsecase.create(member); + Member memberResult = memberUsecase.create(request.accessToken(), member); return new JwtTokenResponse(jwtTokenUtil.getJWTToken(memberResult)); } - @GetMapping("/{idCode}") + @GetMapping("/{accessToken}") @ResponseStatus(HttpStatus.OK) @Operation(summary = "Member 로그인 API") public JwtTokenResponse login( - @PathVariable("idCode") - @Parameter(name = "idCode", description = "sns idCode", required = true) - String idCode) { + @PathVariable("accessToken") + @Parameter( + name = "accessToken", + description = "sns accessToken", + required = true) + String accessToken) { - Member member = memberUsecase.login(idCode); + Member member = memberUsecase.login(accessToken); return new JwtTokenResponse(jwtTokenUtil.getJWTToken(member)); } @@ -67,4 +70,14 @@ public Boolean duplicatedNickname( Boolean result = memberUsecase.duplicatedNickname(nickname); return result; } + + @GetMapping("/accessToken/{idCode}") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "(백엔드용)accessToken을 받아오기 위한 API") + public String getAccessToken( + @PathVariable("idCode") + @Parameter(name = "idCode", description = "카카오에서 발급 받은 idCode", required = true) + String idCode) { + return memberUsecase.getAccessToken(idCode); + } } diff --git a/application/src/main/java/org/depromeet/spot/application/member/dto/request/RegisterReq.java b/application/src/main/java/org/depromeet/spot/application/member/dto/request/RegisterReq.java index bd3bf0d1..dbfbc156 100644 --- a/application/src/main/java/org/depromeet/spot/application/member/dto/request/RegisterReq.java +++ b/application/src/main/java/org/depromeet/spot/application/member/dto/request/RegisterReq.java @@ -10,8 +10,8 @@ import io.swagger.v3.oas.annotations.media.Schema; public record RegisterReq( - @NotNull(message = "인가 id code는 필수 값입니다.") @Schema(description = "인가 id code") - String idCode, + @NotNull(message = "인가 accessToken는 필수 값입니다.") @Schema(description = "카카오 인증 accessToken") + String accessToken, @NotNull(message = "닉네임 값은 필수입니다.") @Schema(description = "설정하려는 닉네임") @Length(min = 2, max = 10, message = "닉네임은 2글자에서 10글자 사이여야합니다.") @@ -25,6 +25,6 @@ public record RegisterReq( Long teamId) { public Member toDomain() { - return Member.builder().idToken(idCode).nickname(nickname).teamId(teamId).build(); + return Member.builder().nickname(nickname).teamId(teamId).build(); } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/oauth/OauthRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/oauth/OauthRepositoryImpl.java index 2497b322..cfe8fb46 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/oauth/OauthRepositoryImpl.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/oauth/OauthRepositoryImpl.java @@ -80,6 +80,7 @@ public Member getLoginUserInfo(String accesstoken) { // TODO : idToken이 변경 될 수 있음. 등록된 email도 변경될 수 있기에 추 후 논의가 필요. // 기존 유저와 비교를 위해선 idToken만 필요함. + // 앱에서는 accessToken을 반환해주기에 accessToken으로 로직 처리 return userInfo.toLoginDomain(); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java index 89097f21..b34d5100 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java @@ -4,9 +4,11 @@ public interface MemberUsecase { - Member create(Member member); + Member create(String accessToken, Member member); Member login(String idCode); Boolean duplicatedNickname(String nickname); + + String getAccessToken(String idCode); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java index 88c1a085..5628c8e8 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java @@ -21,11 +21,10 @@ public class MemberService implements MemberUsecase { private final MemberRepository memberRepository; @Override - public Member create(Member member) { + public Member create(String accessToken, Member member) { if (memberRepository.existsByNickname(member.getNickname())) { throw new MemberNicknameConflictException(); } - String accessToken = oauthRepository.getKakaoAccessToken(member.getIdToken()); Member memberResult = oauthRepository.getRegisterUserInfo(accessToken, member); Optional existedMember = memberRepository.findByIdToken(memberResult.getIdToken()); if (existedMember.isPresent()) { @@ -36,8 +35,7 @@ public Member create(Member member) { } @Override - public Member login(String idCode) { - String accessToken = oauthRepository.getKakaoAccessToken(idCode); + public Member login(String accessToken) { Member memberResult = oauthRepository.getLoginUserInfo(accessToken); Optional existedMember = memberRepository.findByIdToken(memberResult.getIdToken()); if (existedMember.isEmpty()) { @@ -52,4 +50,9 @@ public Boolean duplicatedNickname(String nickname) { throw new MemberNicknameConflictException(); return Boolean.FALSE; } + + @Override + public String getAccessToken(String idCode) { + return oauthRepository.getKakaoAccessToken(idCode); + } }