Skip to content

Commit b229556

Browse files
authored
Merge pull request #24 from Sportize/refactor/user
♻️Refactor: user entity에 nickName필드 추가
2 parents 2213696 + da26bcc commit b229556

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

src/main/java/com/be/sportizebe/domain/user/dto/request/SignUpRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public record SignUpRequest(
1414
@Schema(description = "비밀번호", example = "password123")
1515
@NotBlank(message = "비밀번호를 입력해주세요.")
1616
// @Size(min = 8, message = "비밀번호는 8자 이상이어야 합니다.")
17-
String password
17+
String password,
18+
19+
@Schema(description = "닉네임", example = "스포티")
20+
@NotBlank(message = "사용할 닉네임을 입력해주세요.")
21+
String nickName
1822
) {
1923
}

src/main/java/com/be/sportizebe/domain/user/dto/response/SignUpResponse.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ public record SignUpResponse(
1212
String username,
1313

1414
@Schema(description = "사용자 권한", example = "USER")
15-
Role role
15+
Role role,
16+
17+
@Schema(description = "사용자 별명", example = "스포티")
18+
String nickName
1619
) {
1720
public static SignUpResponse from(User user) {
18-
return new SignUpResponse(user.getId(), user.getUsername(), user.getRole());
21+
return new SignUpResponse(user.getId(), user.getUsername(), user.getRole(), user.getNickname());
1922
}
2023
}

src/main/java/com/be/sportizebe/domain/user/entity/User.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class User extends BaseTimeEntity {
3131
@JsonIgnore // 응답 시 데이터를 json 형식으로 보낼때 이 부분은 보내지 않는다
3232
private String password;
3333

34+
@Column(nullable = false, unique = true)
35+
private String nickname; // 사용자 별명 (서비스 내에서는 별명으로 활동)
36+
3437
@JsonIgnore
3538
private String refreshToken;
3639

src/main/java/com/be/sportizebe/domain/user/exception/UserErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum UserErrorCode implements BaseErrorCode {
1111
EXAMPLE_ERROR_CODE("USER_0000", "예시 에러코드로 커스터마이징이 필요합니다.", HttpStatus.BAD_REQUEST),
1212

1313
DUPLICATE_USERNAME("USER_0001", "이미 사용 중인 아이디입니다.", HttpStatus.BAD_REQUEST),
14+
DUPLICATE_NICKNAME("USER_0008", "이미 사용 중인 닉네임입니다.", HttpStatus.BAD_REQUEST),
1415
INVALID_PASSWORD("USER_0002", "비밀번호가 올바르지 않습니다.", HttpStatus.BAD_REQUEST),
1516
IMAGE_UPLOAD_FAILED("USER_0003", "프로필 이미지 업로드에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
1617
USER_SAVE_FAILED("USER_0004", "회원 정보 저장에 실패했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),

src/main/java/com/be/sportizebe/domain/user/repository/UserRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
99
Optional<User> findByUsername(String username);
1010

1111
boolean existsByUsername(String username);
12+
13+
boolean existsByNickname(String nickname);
1214
}

src/main/java/com/be/sportizebe/domain/user/service/UserService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,25 @@ public class UserService {
2323

2424
@Transactional
2525
public SignUpResponse signUp(SignUpRequest request) {
26+
27+
// 사용자 아이디 중복 체크
2628
if (userRepository.existsByUsername(request.username())) {
2729
throw new CustomException(UserErrorCode.DUPLICATE_USERNAME);
2830
}
2931

32+
// 사용자 닉네임 중복 체크
33+
if (userRepository.existsByNickname(request.nickName())) {
34+
throw new CustomException(UserErrorCode.DUPLICATE_NICKNAME);
35+
}
36+
3037
String encodedPassword = passwordEncoder.encode(request.password());
3138

3239
User user = User.builder()
33-
.username(request.username())
34-
.password(encodedPassword)
35-
.role(Role.USER)
36-
.build();
40+
.username(request.username())
41+
.password(encodedPassword)
42+
.nickname(request.nickName())
43+
.role(Role.USER)
44+
.build();
3745

3846
User savedUser = userRepository.save(user);
3947
log.info("새로운 사용자 생성: {}", savedUser.getUsername());

0 commit comments

Comments
 (0)