diff --git a/member-service/src/main/java/com/freediving/authservice/adapter/in/web/dto/UserLoginResponse.java b/member-service/src/main/java/com/freediving/authservice/adapter/in/web/dto/UserLoginResponse.java index 3bcd61bd..91ce534b 100644 --- a/member-service/src/main/java/com/freediving/authservice/adapter/in/web/dto/UserLoginResponse.java +++ b/member-service/src/main/java/com/freediving/authservice/adapter/in/web/dto/UserLoginResponse.java @@ -1,6 +1,5 @@ package com.freediving.authservice.adapter.in.web.dto; -import com.freediving.authservice.domain.OauthType; import com.freediving.authservice.domain.OauthUser; import io.swagger.v3.oas.annotations.media.Schema; @@ -24,10 +23,7 @@ public class UserLoginResponse { @Schema(description = "유저 식별 키", example = "1") - private String userId; - - @Schema(description = "소셜 로그인 타입", example = "KAKAO") - private OauthType oauthType; + private Long userId; @Schema(description = "이메일", example = "sasca37@naver.com") private String email; @@ -35,11 +31,18 @@ public class UserLoginResponse { @Schema(description = "프로필 이미지 URL", example = "https://aws-s3.com") private String profileImgUrl; + @Schema(description = "닉네임", example = "초보다이버_00001") + private String nickname; + + @Schema(description = "소셜 로그인 타입", example = "KAKAO") + private String oauthType; + @Schema(description = "유저 권한", example = "0") private Integer roleLevel; public static UserLoginResponse from(OauthUser oauthUser) { - return new UserLoginResponse(oauthUser.getUserId(), oauthUser.getOauthType(), oauthUser.getEmail(), - oauthUser.getProfileImgUrl(), oauthUser.getRoleLevel()); + return new UserLoginResponse(Long.valueOf(oauthUser.getUserId()), oauthUser.getEmail(), + oauthUser.getProfileImgUrl(), oauthUser.getNickname(), oauthUser.getOauthType().name(), + oauthUser.getRoleLevel()); } } diff --git a/member-service/src/main/java/com/freediving/authservice/domain/OauthUser.java b/member-service/src/main/java/com/freediving/authservice/domain/OauthUser.java index da1c1c44..a2fe0a1f 100644 --- a/member-service/src/main/java/com/freediving/authservice/domain/OauthUser.java +++ b/member-service/src/main/java/com/freediving/authservice/domain/OauthUser.java @@ -24,6 +24,8 @@ public class OauthUser { private String userId; + private String nickname; + private OauthType oauthType; private String email; private String profileImgUrl; diff --git a/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/CreateUserResponse.java b/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/CreateUserResponse.java index 2b288e95..e5b7f902 100644 --- a/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/CreateUserResponse.java +++ b/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/CreateUserResponse.java @@ -31,7 +31,7 @@ public class CreateUserResponse { @Schema(description = "프로필 이미지 URL", example = "https://aws-s3.com") private String profileImgUrl; - @Schema(description = "닉네임", example = "버디킹") + @Schema(description = "닉네임", example = "초보다이버_00001") private String nickname; @Schema(description = "소셜 로그인 타입", example = "KAKAO") diff --git a/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/FindUserResponse.java b/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/FindUserResponse.java index 9956dfcd..efb9abed 100644 --- a/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/FindUserResponse.java +++ b/member-service/src/main/java/com/freediving/memberservice/adapter/in/web/dto/FindUserResponse.java @@ -36,7 +36,7 @@ public class FindUserResponse { @Schema(description = "프로필 이미지 URL", example = "https://aws-s3.com") private String profileImgUrl; - @Schema(description = "닉네임", example = "버디킹") + @Schema(description = "닉네임", example = "초보다이버_00001") private String nickname; @Schema(description = "소셜 로그인 타입", example = "KAKAO") diff --git a/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/CreateUserPersistenceAdapter.java b/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/CreateUserPersistenceAdapter.java index 600038a0..4ebd6214 100644 --- a/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/CreateUserPersistenceAdapter.java +++ b/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/CreateUserPersistenceAdapter.java @@ -6,6 +6,7 @@ import com.freediving.common.handler.exception.BuddyMeException; import com.freediving.common.response.enumerate.ServiceStatusCode; import com.freediving.memberservice.application.port.in.CreateUserCommand; +import com.freediving.memberservice.application.port.in.NicknameGenerator; import com.freediving.memberservice.application.port.out.CreateUserLicencePort; import com.freediving.memberservice.application.port.out.CreateUserPort; import com.freediving.memberservice.domain.OauthType; @@ -47,10 +48,12 @@ public User createOrGetUser(CreateUserCommand createUserCommand) { // 최초 로그인인 경우 if (ObjectUtils.isEmpty(userJpaEntity)) { - UserJpaEntity saveUserJpaEntity = UserJpaEntity + UserJpaEntity createUserJpaEntity = UserJpaEntity .createSimpleUser(oauthType, email, profileImgUrl, RoleLevel.UNREGISTER); - userJpaRepository.save(saveUserJpaEntity); - return User.fromJpaEntitySimple(saveUserJpaEntity); + UserJpaEntity savedUserJpaEntity = userJpaRepository.save(createUserJpaEntity); + String randomNickname = NicknameGenerator.generateNickname(savedUserJpaEntity.getUserId()); + savedUserJpaEntity.updateUserNickname(randomNickname); + return User.fromJpaEntitySimple(createUserJpaEntity); } return User.fromJpaEntityDetail(userJpaEntity); } diff --git a/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/UserJpaEntity.java b/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/UserJpaEntity.java index 67cd0a86..444984a2 100644 --- a/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/UserJpaEntity.java +++ b/member-service/src/main/java/com/freediving/memberservice/adapter/out/persistence/UserJpaEntity.java @@ -75,6 +75,10 @@ public void updateUserLicenceJpaEntity(UserLicenceJpaEntity userLicenceJpaEntity this.userLicenceJpaEntity = userLicenceJpaEntity; } + public void updateUserNickname(String nickname) { + this.nickname = nickname; + } + public static UserJpaEntity createSimpleUser(OauthType oauthType, String email, String profileImgUrl, RoleLevel roleLevel) { return new UserJpaEntity(oauthType, email, profileImgUrl, roleLevel); diff --git a/member-service/src/main/java/com/freediving/memberservice/application/port/in/NicknameGenerator.java b/member-service/src/main/java/com/freediving/memberservice/application/port/in/NicknameGenerator.java new file mode 100644 index 00000000..5700d0af --- /dev/null +++ b/member-service/src/main/java/com/freediving/memberservice/application/port/in/NicknameGenerator.java @@ -0,0 +1,33 @@ +package com.freediving.memberservice.application.port.in; + +import java.util.Random; + +import org.apache.commons.lang3.StringUtils; + +/** + * @Author : sasca37 + * @Date : 2024/02/27 + * @Description : 신규 가입 시 닉네임 생성 기능을 담당하는 클래스 + * =========================================================== + * DATE AUTHOR NOTE + * =========================================================== + * 2024/02/27 sasca37 최초 생성 + */ +public class NicknameGenerator { + private static final String[] WORDS = { + "빠른", "느린", "높은", "낮은", "멋진", + "작은", "애기", "어른", "예쁜", "얇은", + "행복", "슬픈", "기쁨", "쿨한", "초보", + "고래", "사슴", "토끼", "거북", "상어", + "문어", "해마", "가재", "갈치", "물범", + "펭귄", "참치", "새우", "홍합", "해달" + }; + + private static final Random RANDOM = new Random(); + + public static String generateNickname(Long id) { + String sequence = StringUtils.leftPad(String.valueOf(id), 5, '0'); + String randomAdjective = WORDS[RANDOM.nextInt(WORDS.length)]; + return randomAdjective + "다이버_" + sequence; + } +}