From 51da490721aecd0fb104231e35b7b3b0a6693bfb Mon Sep 17 00:00:00 2001 From: eom-tae-in Date: Wed, 25 Sep 2024 20:29:48 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20nice=20=EC=9D=B8=EC=A6=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A7=84=ED=96=89=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=20?= =?UTF-8?q?=EC=A0=84=20=EC=82=AC=EC=9A=A9=ED=95=A0=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=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 --- .../member/application/auth/MemberAuthService.java | 11 ++++++++++- .../member/application/auth/dto/TestLoginRequest.java | 7 +++++++ .../java/com/atwoz/member/domain/member/Member.java | 8 +++++--- .../atwoz/member/ui/auth/MemberAuthController.java | 7 +++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/atwoz/member/application/auth/dto/TestLoginRequest.java diff --git a/src/main/java/com/atwoz/member/application/auth/MemberAuthService.java b/src/main/java/com/atwoz/member/application/auth/MemberAuthService.java index 672f9036..c4926d72 100644 --- a/src/main/java/com/atwoz/member/application/auth/MemberAuthService.java +++ b/src/main/java/com/atwoz/member/application/auth/MemberAuthService.java @@ -3,6 +3,7 @@ import com.atwoz.alert.application.event.AlertTokenCreatedEvent; import com.atwoz.global.event.Events; import com.atwoz.member.application.auth.dto.LoginRequest; +import com.atwoz.member.application.auth.dto.TestLoginRequest; import com.atwoz.member.domain.auth.MemberTokenProvider; import com.atwoz.member.domain.member.Member; import com.atwoz.member.domain.member.MemberRepository; @@ -14,6 +15,7 @@ @RequiredArgsConstructor @Service +@Transactional public class MemberAuthService { private static final String DEFAULT_PHONE_NUMBER = "01011111111"; @@ -25,7 +27,6 @@ public class MemberAuthService { /** * OAuth 인증방식과 PASS 인증 방식에 차이가 존재해서 회의 후 메서드 변경을 진행할 예정 */ - @Transactional public String login(final LoginRequest request, final OAuthProviderRequest provider) { String accessToken = oAuthRequester.getAccessToken(request.code(), provider); MemberInfoResponse memberInfoResponse = oAuthRequester.getMemberInfo(accessToken, provider); @@ -36,4 +37,12 @@ public String login(final LoginRequest request, final OAuthProviderRequest provi return memberTokenProvider.createAccessToken(createdMember.getId()); } + + //TODO: test를 위해 임시로 구현한 메서드입니다. 나중에 삭제해야합니다. + public String testLogin(final TestLoginRequest request) { + Member member = Member.createWithOAuth(request.phoneNumber()); + memberRepository.save(member); + + return memberTokenProvider.createAccessToken(member.getId()); + } } diff --git a/src/main/java/com/atwoz/member/application/auth/dto/TestLoginRequest.java b/src/main/java/com/atwoz/member/application/auth/dto/TestLoginRequest.java new file mode 100644 index 00000000..a89ff5bc --- /dev/null +++ b/src/main/java/com/atwoz/member/application/auth/dto/TestLoginRequest.java @@ -0,0 +1,7 @@ +package com.atwoz.member.application.auth.dto; + +//TODO 잠깐 테스트 용도로 로그인을 허용하기 위해 만든 dto입니다. 나중에 삭제해야합니다. +public record TestLoginRequest( + String phoneNumber +) { +} diff --git a/src/main/java/com/atwoz/member/domain/member/Member.java b/src/main/java/com/atwoz/member/domain/member/Member.java index 11fa220c..675cc90f 100644 --- a/src/main/java/com/atwoz/member/domain/member/Member.java +++ b/src/main/java/com/atwoz/member/domain/member/Member.java @@ -82,9 +82,11 @@ public static Member createWithPass(final String gender, .build(); } - public void initializeWith(final String nickname, - final Long recommenderId, - final InternalProfileInitializeRequest internalProfileInitializeRequest) { + public void initializeWith( + final String nickname, + final Long recommenderId, + final InternalProfileInitializeRequest internalProfileInitializeRequest + ) { this.nickname = nickname; initializeRecommenderId(recommenderId); memberProfile.initialize(internalProfileInitializeRequest); diff --git a/src/main/java/com/atwoz/member/ui/auth/MemberAuthController.java b/src/main/java/com/atwoz/member/ui/auth/MemberAuthController.java index 79790959..fe6d2d9a 100644 --- a/src/main/java/com/atwoz/member/ui/auth/MemberAuthController.java +++ b/src/main/java/com/atwoz/member/ui/auth/MemberAuthController.java @@ -2,6 +2,7 @@ import com.atwoz.member.application.auth.MemberAuthService; import com.atwoz.member.application.auth.dto.LoginRequest; +import com.atwoz.member.application.auth.dto.TestLoginRequest; import com.atwoz.member.infrastructure.auth.dto.OAuthProviderRequest; import com.atwoz.member.ui.auth.dto.TokenResponse; import com.atwoz.member.ui.auth.support.OAuthAuthority; @@ -26,4 +27,10 @@ public ResponseEntity login(@RequestBody @Valid final LoginReques String token = memberAuthService.login(request, provider); return ResponseEntity.ok(new TokenResponse(token)); } + + @PostMapping("/test-login") + public ResponseEntity testLogin(@RequestBody final TestLoginRequest request) { + String token = memberAuthService.testLogin(request); + return ResponseEntity.ok(new TokenResponse(token)); + } }