From 77bcdc4d99f9d057833080e006d4df47971d25c6 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:20:59 +0900 Subject: [PATCH 1/6] =?UTF-8?q?update=20::=20MemberNotFoundException=20->?= =?UTF-8?q?=20UserNotFoundException=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...emberNotFoundException.java => UserNotFoundException.java} | 4 ++-- .../v2/domain/auth/service/impl/ReissueTokenServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/com/mindway/server/v2/domain/auth/exception/{MemberNotFoundException.java => UserNotFoundException.java} (68%) diff --git a/src/main/java/com/mindway/server/v2/domain/auth/exception/MemberNotFoundException.java b/src/main/java/com/mindway/server/v2/domain/auth/exception/UserNotFoundException.java similarity index 68% rename from src/main/java/com/mindway/server/v2/domain/auth/exception/MemberNotFoundException.java rename to src/main/java/com/mindway/server/v2/domain/auth/exception/UserNotFoundException.java index 34d2a38..166b3f9 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/exception/MemberNotFoundException.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/exception/UserNotFoundException.java @@ -3,9 +3,9 @@ import com.mindway.server.v2.global.exception.ErrorCode; import com.mindway.server.v2.global.exception.MindWayException; -public class MemberNotFoundException extends MindWayException { +public class UserNotFoundException extends MindWayException { - public MemberNotFoundException() { + public UserNotFoundException() { super(ErrorCode.MEMBER_NOT_FOUND); } } diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java index 488f973..0e084d7 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/ReissueTokenServiceImpl.java @@ -2,7 +2,7 @@ import com.mindway.server.v2.domain.auth.RefreshToken; import com.mindway.server.v2.domain.auth.exception.ExpiredRefreshTokenException; -import com.mindway.server.v2.domain.auth.exception.MemberNotFoundException; +import com.mindway.server.v2.domain.auth.exception.UserNotFoundException; import com.mindway.server.v2.domain.auth.presentation.dto.response.TokenResponse; import com.mindway.server.v2.domain.auth.repository.RefreshRepository; import com.mindway.server.v2.domain.auth.service.ReissueTokenService; @@ -27,7 +27,7 @@ public TokenResponse execute(String refreshToken) { .orElseThrow(ExpiredRefreshTokenException::new); User user = userRepository.findById(refreshEntity.getMemberId()) - .orElseThrow(MemberNotFoundException::new); + .orElseThrow(UserNotFoundException::new); refreshRepository.deleteById(refreshEntity.getRefreshToken()); From 4af0d6f3be276c0386cdbc868d2fb03be6b00ffc Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:21:05 +0900 Subject: [PATCH 2/6] =?UTF-8?q?update=20::=20MemberNotFoundException=20->?= =?UTF-8?q?=20UserNotFoundException=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mindway/server/v2/domain/user/util/UserUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java b/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java index 7f3d8b3..5e315a2 100644 --- a/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java +++ b/src/main/java/com/mindway/server/v2/domain/user/util/UserUtil.java @@ -1,6 +1,6 @@ package com.mindway.server.v2.domain.user.util; -import com.mindway.server.v2.domain.auth.exception.MemberNotFoundException; +import com.mindway.server.v2.domain.auth.exception.UserNotFoundException; import com.mindway.server.v2.domain.user.entity.User; import com.mindway.server.v2.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -16,6 +16,6 @@ public class UserUtil { public User getCurrentUser() { String email = SecurityContextHolder.getContext().getAuthentication().getName(); return userRepository.findByEmail(email) - .orElseThrow(MemberNotFoundException::new); + .orElseThrow(UserNotFoundException::new); } } From 1ca6bd90420a668bb8f1b9d00f375f3be83853f1 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:21:33 +0900 Subject: [PATCH 3/6] =?UTF-8?q?delete=20::=20gauth=5Frole=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mindway/server/v2/domain/user/entity/User.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/mindway/server/v2/domain/user/entity/User.java b/src/main/java/com/mindway/server/v2/domain/user/entity/User.java index d4b6d93..059d5b0 100644 --- a/src/main/java/com/mindway/server/v2/domain/user/entity/User.java +++ b/src/main/java/com/mindway/server/v2/domain/user/entity/User.java @@ -26,8 +26,6 @@ public class User { @Embedded private StudentNum studentNum; - private String gauth_role; - @Enumerated(EnumType.STRING) private Authority authority; From 9566dab0cad1e8a49e0cc414ee8d9c8b72beb386 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:21:55 +0900 Subject: [PATCH 4/6] =?UTF-8?q?add=20::=20=EA=B6=8C=ED=95=9C=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/domain/auth/service/impl/SignInServiceImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java index 26c1512..f2c7534 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java @@ -68,6 +68,15 @@ public TokenResponse execute(SignInRequest signInRequest) throws GAuthException{ } private User saveUser(GAuthUserInfo gAuthUserInfo) { + if (Objects.equals(gAuthUserInfo.getRole(), "ROLE_STUDENT")) { + return saveStudent(gAuthUserInfo); + } else if (Objects.equals(gAuthUserInfo.getRole(), "ROLE_TEACHER")) { + return saveTeacher(gAuthUserInfo); + } + return null; + } + + private User saveStudent(GAuthUserInfo gAuthUserInfo) { User user = User.builder() .id(UUID.randomUUID()) .email(gAuthUserInfo.getEmail()) From 07e14c2e2555ef4b1df3695ce0e56e95de6c281e Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:22:17 +0900 Subject: [PATCH 5/6] =?UTF-8?q?add=20::=20saveTeacher=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/impl/SignInServiceImpl.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java index f2c7534..26622b5 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java @@ -91,6 +91,20 @@ private User saveStudent(GAuthUserInfo gAuthUserInfo) { return user; } + private User saveTeacher(GAuthUserInfo gAuthUserInfo) { + User teacher = User.builder() + .id(UUID.randomUUID()) + .email(gAuthUserInfo.getEmail()) + .name(gAuthUserInfo.getName()) + .studentNum(new StudentNum(gAuthUserInfo.getGrade(), gAuthUserInfo.getClassNum(), gAuthUserInfo.getNum())) + .authority(Authority.ROLE_TEACHER) + .build(); + + userRepository.save(teacher); + + return teacher; + } + private void saveRefreshToken(TokenResponse tokenResponse, User user) { RefreshToken refreshToken = RefreshToken.builder() .refreshToken(tokenResponse.getRefreshToken()) From 6bb5da8a30e0632936a87dd433e9a86e77244a09 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:22:40 +0900 Subject: [PATCH 6/6] =?UTF-8?q?add=20::=20user=20null=20=EA=B2=80=EC=82=AC?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/domain/auth/service/impl/SignInServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java index 26622b5..3023cb8 100644 --- a/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/auth/service/impl/SignInServiceImpl.java @@ -1,6 +1,7 @@ package com.mindway.server.v2.domain.auth.service.impl; import com.mindway.server.v2.domain.auth.RefreshToken; +import com.mindway.server.v2.domain.auth.exception.UserNotFoundException; import com.mindway.server.v2.domain.auth.presentation.dto.request.SignInRequest; import com.mindway.server.v2.domain.auth.presentation.dto.response.TokenResponse; import com.mindway.server.v2.domain.auth.repository.RefreshRepository; @@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Value; import java.io.IOException; +import java.util.Objects; import java.util.UUID; @RequiredArgsConstructor @@ -52,6 +54,9 @@ public TokenResponse execute(SignInRequest signInRequest) throws GAuthException{ User user = userRepository.findByEmail(userInfo.getEmail()) .orElseGet(() -> saveUser(userInfo)); + if (user == null) + throw new UserNotFoundException(); + TokenResponse tokenResponse = jwtProvider.generateTokenDto(user.getId()); saveRefreshToken(tokenResponse, user); @@ -82,7 +87,6 @@ private User saveStudent(GAuthUserInfo gAuthUserInfo) { .email(gAuthUserInfo.getEmail()) .name(gAuthUserInfo.getName()) .studentNum(new StudentNum(gAuthUserInfo.getGrade(), gAuthUserInfo.getClassNum(), gAuthUserInfo.getNum())) - .gauth_role(gAuthUserInfo.getRole()) .authority(Authority.ROLE_STUDENT) .build();