Skip to content

Commit

Permalink
Merge branch 'staging' into main-test
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed Aug 17, 2024
2 parents acabd22 + e15822b commit cd853f3
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class SignUpRequestDTO {
@NotBlank
@Schema(example = "1999")
String birthDate;
String birthYear;

@NotNull
@Schema(example = "M")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private Function<User, UserFindByAdminResponseDto> 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())
Expand All @@ -222,7 +222,7 @@ public Page<UserFindByAdminResponseDto> 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())
Expand All @@ -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();
}
Expand Down
22 changes: 3 additions & 19 deletions genti-common/src/main/java/com/gt/genti/util/DateTimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
5 changes: 2 additions & 3 deletions genti-domain/src/main/java/com/gt/genti/user/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit cd853f3

Please sign in to comment.