From 5c0ff047da5d702ba17b6542cbaadbc51b27bf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 25 Sep 2023 20:40:51 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20Login=20=EC=88=98=EC=A0=95=20+=20Member?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=EC=97=90=EC=84=9C=20=EC=A0=84=ED=99=94?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=82=AD=EC=A0=9C=20+=20AfterLoginDto=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/AuthController.java | 11 +++-------- .../domain/member/dto/response/AfterLoginDto.java | 14 ++++++++++++++ .../backend/domain/member/entity/AuthStatus.java | 6 ++++++ .../twtw/backend/domain/member/entity/Member.java | 5 +---- .../backend/domain/member/mapper/MemberMapper.java | 1 - .../backend/domain/member/service/AuthService.java | 8 +++++--- .../member/controller/AuthControllerTest.java | 4 +++- 7 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java create mode 100644 backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java diff --git a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java index e951bdc2..8127580f 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java @@ -3,6 +3,7 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; import com.twtw.backend.domain.member.service.AuthService; @@ -34,13 +35,7 @@ public ResponseEntity saveMember(@RequestBody MemberSaveRequest member } @PostMapping("/login") - public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request) { - TokenDto tokenDto = authService.getTokenByOAuth(request); - - if (tokenDto == null) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(tokenDto); - } else { - return ResponseEntity.status(HttpStatus.OK).body(tokenDto); - } + public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request) { + return ResponseEntity.status(HttpStatus.OK).body(authService.getTokenByOAuth(request)); } } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java new file mode 100644 index 00000000..3283358b --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/AfterLoginDto.java @@ -0,0 +1,14 @@ +package com.twtw.backend.domain.member.dto.response; + +import com.twtw.backend.domain.member.entity.AuthStatus; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AfterLoginDto { + private AuthStatus status; + private TokenDto tokenDto; +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java new file mode 100644 index 00000000..c115defa --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthStatus.java @@ -0,0 +1,6 @@ +package com.twtw.backend.domain.member.entity; + +public enum AuthStatus { + SU, + SI +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java index ed99daa8..ec365d2b 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java @@ -21,17 +21,14 @@ public class Member { private String profileImage; - private String phoneNumber; - @Enumerated(EnumType.STRING) private Role role; @Embedded private OAuth2Info oAuth2Info; - public Member(String nickname, String profileImage, String phoneNumber, Role role) { + public Member(String nickname, String profileImage, Role role) { this.nickname = nickname; this.profileImage = profileImage; - this.phoneNumber = phoneNumber; this.role = role; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java index e0b7b1a0..3f726f8d 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java @@ -15,7 +15,6 @@ public Member toMemberEntity(MemberSaveRequest request) { new Member( request.getNickname(), request.getProfileImage(), - request.getPhoneNumber(), request.getRole()); return member; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java index 9a9b33d2..933091a4 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java @@ -3,7 +3,9 @@ import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.AuthStatus; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.RefreshToken; import com.twtw.backend.domain.member.mapper.MemberMapper; @@ -64,7 +66,7 @@ public TokenDto saveMember(MemberSaveRequest request) { * 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행 * * */ - public TokenDto getTokenByOAuth(OAuthRequest request) { + public AfterLoginDto getTokenByOAuth(OAuthRequest request) { String clientId = request.getToken(); Optional member = @@ -74,10 +76,10 @@ public TokenDto getTokenByOAuth(OAuthRequest request) { Member curMember = member.get(); UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(curMember); TokenDto tokenDto = saveRefreshToken(credit, curMember.getId().toString()); - return tokenDto; + return new AfterLoginDto(AuthStatus.SI,tokenDto); } - return null; + return new AfterLoginDto(AuthStatus.SU,null); } /* diff --git a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java index 0b12fe08..322dd53d 100644 --- a/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/member/controller/AuthControllerTest.java @@ -14,7 +14,9 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; +import com.twtw.backend.domain.member.dto.response.AfterLoginDto; import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.AuthStatus; import com.twtw.backend.domain.member.entity.AuthType; import com.twtw.backend.domain.member.entity.Role; import com.twtw.backend.domain.member.service.AuthService; @@ -96,7 +98,7 @@ void saveMember() throws Exception { @DisplayName("멤버가 저장된 상태에서의 로그인 API가 수행되는가") void afterSocialLogin() throws Exception { // given - final TokenDto expected = new TokenDto("access.token.value", "refresh.token.value"); + final AfterLoginDto expected = new AfterLoginDto(AuthStatus.SI,new TokenDto("access.token.value", "refresh.token.value")); given(authService.getTokenByOAuth(any())).willReturn(expected); // when