From 47e69c2f5824592f59a617f0966089ed10377e7c Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Sun, 18 Aug 2024 01:35:36 +0900 Subject: [PATCH] Rename: #121 birthDate -> birthYear --- .../auth/dto/request/SignUpRequestDTO.java | 2 +- .../genti/auth/social/KakaoOauthStrategy.java | 11 ---------- .../user/dto/response/SignUpResponseDTO.java | 6 ++--- .../response/UserFindByAdminResponseDto.java | 4 ++-- .../gt/genti/user/service/UserService.java | 8 +++---- .../java/com/gt/genti/util/DateTimeUtil.java | 22 +++---------------- .../com/gt/genti/user/UserSerializer.java | 2 +- .../java/com/gt/genti/user/model/User.java | 5 ++--- 8 files changed, 16 insertions(+), 44 deletions(-) diff --git a/genti-api/src/main/java/com/gt/genti/auth/dto/request/SignUpRequestDTO.java b/genti-api/src/main/java/com/gt/genti/auth/dto/request/SignUpRequestDTO.java index 68530bb6..a7539924 100644 --- a/genti-api/src/main/java/com/gt/genti/auth/dto/request/SignUpRequestDTO.java +++ b/genti-api/src/main/java/com/gt/genti/auth/dto/request/SignUpRequestDTO.java @@ -14,7 +14,7 @@ public class SignUpRequestDTO { @NotBlank @Schema(example = "1999") - String birthDate; + String birthYear; @NotNull @Schema(example = "M") diff --git a/genti-api/src/main/java/com/gt/genti/auth/social/KakaoOauthStrategy.java b/genti-api/src/main/java/com/gt/genti/auth/social/KakaoOauthStrategy.java index 6bb4f5b5..35cd30a5 100644 --- a/genti-api/src/main/java/com/gt/genti/auth/social/KakaoOauthStrategy.java +++ b/genti-api/src/main/java/com/gt/genti/auth/social/KakaoOauthStrategy.java @@ -106,7 +106,6 @@ private SocialWebLoginResponse getUserInfo(OauthPlatform oauthPlatform, String a if (isNewUser(findUser)) { User newUser = userRepository.save(User.builderWithSignIn() .socialId(userResponse.id()) - .birthYear(getBirthDateStringFrom(userResponse)) .oauthPlatform(oauthPlatform) .username(userResponse.kakaoAccount().name()) .nickname(RandomUtil.generateRandomNickname()) @@ -130,16 +129,6 @@ private SocialWebLoginResponse getUserInfo(OauthPlatform oauthPlatform, String a return SocialWebLoginResponse.of(user.getId(), user.getUsername(), user.getEmail(), isNewUser, oauthJwtResponse); } - private static String getBirthDateStringFrom(KakaoUserResponse userResponse) { - String birthDate = null; - String birthYear = userResponse.kakaoAccount().birthyear(); - String birthday = userResponse.kakaoAccount().birthday(); - if (birthYear != null && birthday != null && birthday.length() == 4) { - birthDate = birthYear + "-" + birthday.substring(0, 2) + "-" + birthday.substring(2, 4); - } - return birthDate; - } - public void unlink(String userSocialId) { Long socialId; try{ diff --git a/genti-api/src/main/java/com/gt/genti/user/dto/response/SignUpResponseDTO.java b/genti-api/src/main/java/com/gt/genti/user/dto/response/SignUpResponseDTO.java index e4e01c22..2df7f44b 100644 --- a/genti-api/src/main/java/com/gt/genti/user/dto/response/SignUpResponseDTO.java +++ b/genti-api/src/main/java/com/gt/genti/user/dto/response/SignUpResponseDTO.java @@ -19,16 +19,16 @@ public class SignUpResponseDTO { @Schema(description = "닉네임", example = "다정한 모래") String nickname; @Schema(description = "태어난 년도", example = "1999") - String birthDate; + String birthYear; @Schema(description = "성별", example = "남") Sex sex; @Builder - public SignUpResponseDTO(String email, OauthPlatform lastLoginOauthPlatform, String nickname, String birthDate, Sex sex) { + public SignUpResponseDTO(String email, OauthPlatform lastLoginOauthPlatform, String nickname, String birthYear, Sex sex) { this.email = email; this.lastLoginOauthPlatform = lastLoginOauthPlatform; this.nickname = nickname; - this.birthDate = birthDate; + this.birthYear = birthYear; this.sex = sex; } } diff --git a/genti-api/src/main/java/com/gt/genti/user/dto/response/UserFindByAdminResponseDto.java b/genti-api/src/main/java/com/gt/genti/user/dto/response/UserFindByAdminResponseDto.java index 7018c2a9..ca90dac1 100644 --- a/genti-api/src/main/java/com/gt/genti/user/dto/response/UserFindByAdminResponseDto.java +++ b/genti-api/src/main/java/com/gt/genti/user/dto/response/UserFindByAdminResponseDto.java @@ -53,14 +53,14 @@ public class UserFindByAdminResponseDto { LocalDateTime lastLoginDate; @Builder - public UserFindByAdminResponseDto(Long id, String email, UserRole userRole, String birthDate, Sex sex, + public UserFindByAdminResponseDto(Long id, String email, UserRole userRole, String birthYear, Sex sex, UserStatus userStatus, LocalDateTime createdAt, int requestTaskCount, Creator creator, Deposit deposit, LocalDateTime lastLoginDate) { this.id = id; this.email = email; this.userRole = userRole; - this.age = DateTimeUtil.getAge(birthDate); + this.age = DateTimeUtil.getAge(birthYear); this.sex = sex; this.userStatus = userStatus; this.createdAt = createdAt; diff --git a/genti-api/src/main/java/com/gt/genti/user/service/UserService.java b/genti-api/src/main/java/com/gt/genti/user/service/UserService.java index 3e85fa70..2485f8a1 100644 --- a/genti-api/src/main/java/com/gt/genti/user/service/UserService.java +++ b/genti-api/src/main/java/com/gt/genti/user/service/UserService.java @@ -198,7 +198,7 @@ private Function mapToUserFindByAdminResponseD .id(user.getId()) .email(user.getEmail()) .userRole(user.getUserRole()) - .birthDate(user.getBirthYear()) + .birthYear(user.getBirthYear()) .sex(user.getSex()) .userStatus(user.getUserStatus()) .createdAt(user.getCreatedAt()) @@ -222,7 +222,7 @@ public Page getUserInfoByEmail(String email) { UserFindByAdminResponseDto responseDto = UserFindByAdminResponseDto.builder() .email(foundUser.getEmail()) .userRole(foundUser.getUserRole()) - .birthDate(foundUser.getBirthYear()) + .birthYear(foundUser.getBirthYear()) .deposit(foundUser.getDeposit()) .lastLoginDate(foundUser.getLastLoginDate()) .userStatus(foundUser.getUserStatus()) @@ -240,14 +240,14 @@ public SignUpResponseDTO signUp(Long userId, SignUpRequestDTO signUpRequestDTO) if (!foundUser.isFirstJoinUser()) { throw ExpectedException.withLogging(ResponseCode.UserAlreadySignedUp); } - foundUser.updateBirthAndSex(signUpRequestDTO.getBirthDate(), signUpRequestDTO.getSex()); + foundUser.updateBirthAndSex(signUpRequestDTO.getBirthYear(), signUpRequestDTO.getSex()); foundUser.updateUserRole(UserRole.USER); return SignUpResponseDTO.builder() .email(foundUser.getEmail()) .lastLoginOauthPlatform(foundUser.getLastLoginOauthPlatform()) .nickname(foundUser.getNickname()) - .birthDate(foundUser.getBirthYear()) + .birthYear(foundUser.getBirthYear()) .sex(foundUser.getSex()) .build(); } diff --git a/genti-common/src/main/java/com/gt/genti/util/DateTimeUtil.java b/genti-common/src/main/java/com/gt/genti/util/DateTimeUtil.java index 71c51045..40585248 100644 --- a/genti-common/src/main/java/com/gt/genti/util/DateTimeUtil.java +++ b/genti-common/src/main/java/com/gt/genti/util/DateTimeUtil.java @@ -39,27 +39,11 @@ public static String getZeroTime() { return "00:00:00"; } - public static int getAge(LocalDate birthDate) { - if (birthDate == null) { + public static int getAge(String birthYear) { + if (birthYear == null) { return -1; } - LocalDate now = LocalDate.now(); - int age = now.getYear() - birthDate.getYear(); - - // 현재 날짜가 생일 전이라면 만나이를 하나 줄입니다. - if (now.getMonthValue() < birthDate.getMonthValue() || - (now.getMonthValue() == birthDate.getMonthValue() && - now.getDayOfMonth() < birthDate.getDayOfMonth())) { - age--; - } - return age; - } - - public static int getAge(String birthDate) { - if (birthDate == null) { - return -1; - } - int year = Integer.parseInt(birthDate); + int year = Integer.parseInt(birthYear); int age = LocalDate.now().getYear() - year; return age; } diff --git a/genti-domain/src/main/java/com/gt/genti/user/UserSerializer.java b/genti-domain/src/main/java/com/gt/genti/user/UserSerializer.java index 3447fe5a..645a36c1 100644 --- a/genti-domain/src/main/java/com/gt/genti/user/UserSerializer.java +++ b/genti-domain/src/main/java/com/gt/genti/user/UserSerializer.java @@ -42,7 +42,7 @@ public void serialize(User user, JsonGenerator gen, SerializerProvider provider) } gen.writeNumberField("requestTaskCount", user.getRequestTaskCount()); if (user.getBirthYear() != null) { - gen.writeStringField("birthDate", user.getBirthYear().toString()); + gen.writeStringField("birthYear", user.getBirthYear().toString()); } gen.writeEndObject(); diff --git a/genti-domain/src/main/java/com/gt/genti/user/model/User.java b/genti-domain/src/main/java/com/gt/genti/user/model/User.java index 9e4858c5..95ac7db4 100644 --- a/genti-domain/src/main/java/com/gt/genti/user/model/User.java +++ b/genti-domain/src/main/java/com/gt/genti/user/model/User.java @@ -160,7 +160,6 @@ public static User of(String socialId, String birthYear, OauthPlatform oauthPlat String email) { return base() .socialId(socialId) - .birthYear(birthYear) .lastLoginOauthPlatform(oauthPlatform) .lastLoginDate(LocalDateTime.now()) .userRole(UserRole.OAUTH_FIRST_JOIN) @@ -268,8 +267,8 @@ public void setDeleteAt() { this.deletedAt = LocalDateTime.now().plusDays(USER_RETENTION_PERIOD); } - public void updateBirthAndSex(String birthDate, Sex sex) { - this.birthYear = birthDate; + public void updateBirthAndSex(String birthYear, Sex sex) { + this.birthYear = birthYear; this.sex = sex; }