From 4f05ba82d1af69eb132b9307c64b8f174007b892 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Mon, 9 Dec 2024 23:06:56 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[feat]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20DTO=EC=97=90=20existingUser=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존에 회원가입한 사용자인 경우: true - 처음으로 로그인하여 회원가입을 해야 하는 경우: false --- .../global/security/auth/dto/AuthenticationResponse.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationResponse.java b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationResponse.java index f875be9..960009a 100644 --- a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationResponse.java +++ b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationResponse.java @@ -39,6 +39,9 @@ public static class SendTokens { // AuthenticationRequest.ToLogin과 대응 @Schema(description = "전화번호", example = "01012341234") private String phoneNumber; // 전화번호 + @Schema(description = "기존에 회원가입했던 사용자: true / 첫 로그인하는 사용자: false") + private Boolean existingUser; // 기존에 회원가입했던 사용자: true / 첫 로그인하는 사용자: false + @Schema(description = "액세스 토큰") private String accessToken; // 액세스 토큰 From ba9aae271325d64eb45a4e081b683eb4027470b0 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Mon, 9 Dec 2024 23:09:52 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[feat]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20DTO=EC=97=90=20existingUser=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/AuthenticationService.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/service/AuthenticationService.java b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/service/AuthenticationService.java index 3976af3..11b5dfd 100644 --- a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/service/AuthenticationService.java +++ b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/service/AuthenticationService.java @@ -11,6 +11,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor public class AuthenticationService { @@ -44,12 +46,12 @@ public AuthenticationResponse.SendTokens login(String phoneNumber, String otpNum } // 전화번호로 사용자를 로드, 존재하지 않으면 새 사용자 생성 - final User user = userRepository.findFirstByPhoneNumber(phoneNumber) - .orElseGet(() -> userRepository.save(User.builder() // 사용자 정보가 없으면 새로 생성 + final Optional existingUser = userRepository.findFirstByPhoneNumber(phoneNumber); + final User user = existingUser.orElseGet(() -> + userRepository.save(User.builder() // 사용자 정보가 없으면 새로 생성 .phoneNumber(phoneNumber) - .build() - )); - + .build()) + ); // JWT 액세스 토큰 발급 final String accessToken = jwtUtil.generateAccessToken(user); // JWT 리프레시 토큰 발급 @@ -59,6 +61,7 @@ public AuthenticationResponse.SendTokens login(String phoneNumber, String otpNum return AuthenticationResponse.SendTokens.builder() .userId(user.getId()) // 사용자 ID .phoneNumber(user.getPhoneNumber()) // 전화번호 + .existingUser(existingUser.isPresent()) // 기존에 회원가입을 했던 사용자인지 여부 .accessToken(accessToken) // 액세스 토큰 .refreshToken(refreshToken) // 리프레시 토큰 .build(); From 9831994a57d55a586a740a93c0e083377e3467d1 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Fri, 13 Dec 2024 23:35:59 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[refactor]=20=EC=B6=94=EA=B0=80=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=8A=94=20null=EA=B0=92=EC=9D=84=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserServiceImpl.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java index d4afd0d..7987b8e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.java @@ -156,22 +156,15 @@ public AuthenticationResponse.AdditionalInfo saveAdditionalInfo(UserDto.AuthUser // null 확인 및 초기화 List hashtagIds = Optional.ofNullable(dto.getHashtagIds()).orElse(Collections.emptyList()); - dto.getHashtagIds().stream().map(it -> { - log.info("hashtagId: {}", it); - return null; - }); + User foundUser = userRepository.findById(user.getId()) + .orElseThrow(() -> new IllegalArgumentException("Not found user")); - User foundUser = userRepository.findById(user.getId()).orElseThrow(() -> new IllegalArgumentException("Not found user")); - -// log.info("user id: {}", foundUser.getId()); -// log.info("user name: {}", foundUser.getName()); -// log.info("user phoneNumber: {}", foundUser.getPhoneNumber()); -// log.info("user age: {}", foundUser.getAge()); -// log.info("user gender: {}", foundUser.getGender()); -// log.info("user mobileCarrier: {}", foundUser.getMobileCarrier()); -// log.info("user region: {}", foundUser.getRegion()); + // MobileCarrier와 Region 값 설정 + String mobileCarrier = dto.getMobileCarrier() != null ? dto.getMobileCarrier() : null; + String region = dto.getRegion() != null ? dto.getRegion() : null; - foundUser.setAdditionalInfo(dto.getMobileCarrier(), dto.getRegion()); + // 추가 정보 설정 + foundUser.setAdditionalInfo(mobileCarrier, region); foundUser = userRepository.save(foundUser); From 774ebd628bffabeb5aae326159d0105850f37876 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Fri, 13 Dec 2024 23:37:00 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[refactor]=20AuthController=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9C=A0=EC=A0=80=EA=B0=80=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=ED=95=9C=20=ED=95=B4=EC=8B=9C=ED=83=9C=EA=B7=B8=EA=B0=80=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0?= =?UTF-8?q?=EC=97=90=EB=A7=8C=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/auth/controller/AuthenticationController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/controller/AuthenticationController.java b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/controller/AuthenticationController.java index a9718eb..49e30dd 100644 --- a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/controller/AuthenticationController.java +++ b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/controller/AuthenticationController.java @@ -107,9 +107,10 @@ public ApiResponse saveAdditionalInfo( // 유저 정보 저장 AuthenticationResponse.AdditionalInfo savedUser = userService.saveAdditionalInfo(user, dto); - // 유저가 선택한 해시태그를 저장 - userService.saveFavoriteHashtags(savedUser.getId(), dto.getHashtagIds()); - + // 유저가 선택한 해시태그가 존재하는 경우에만 저장 + if (dto.getHashtagIds() != null) { + userService.saveFavoriteHashtags(savedUser.getId(), dto.getHashtagIds()); + } return ApiResponse.onSuccess(savedUser); } From 762e26c73b80e71a50bbd439e133f0682bee91f8 Mon Sep 17 00:00:00 2001 From: kangseungmin Date: Fri, 13 Dec 2024 23:37:56 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[feat]=20AuthenticationRequest=20DTO?= =?UTF-8?q?=EC=97=90=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/security/auth/dto/AuthenticationRequest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationRequest.java b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationRequest.java index acda3f1..db3fff5 100644 --- a/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationRequest.java +++ b/src/main/java/com/bbteam/budgetbuddies/global/security/auth/dto/AuthenticationRequest.java @@ -35,6 +35,8 @@ public static class ToLogin { @Getter @Builder + @AllArgsConstructor + @NoArgsConstructor public static class StandardInfo { private String name; private Gender gender; @@ -44,6 +46,8 @@ public static class StandardInfo { @Getter @Builder + @AllArgsConstructor + @NoArgsConstructor public static class AdditionalInfo { private String mobileCarrier; private String region;