Skip to content

Commit

Permalink
refactor: #86 - 유저 로그인 시 응답 포맷 내 닉네임 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sasca37 committed Feb 28, 2024
1 parent 3ee1cba commit dc2dfec
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,22 +23,26 @@
public class UserLoginResponse {

@Schema(description = "유저 식별 키", example = "1")
private String userId;

@Schema(description = "소셜 로그인 타입", example = "KAKAO")
private OauthType oauthType;
private Long userId;

@Schema(description = "이메일", example = "[email protected]")
private String email;

@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class OauthUser {

private String userId;

private String nickname;

private OauthType oauthType;
private String email;
private String profileImgUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit dc2dfec

Please sign in to comment.