Skip to content

Commit 875d31e

Browse files
committed
[#10] feat: User 관련 길이 제한을 도메인으로 이동
1 parent f7c9fad commit 875d31e

File tree

9 files changed

+34
-18
lines changed

9 files changed

+34
-18
lines changed

src/main/java/com/nexters/teamace/auth/application/LoginCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;
44

5+
import com.nexters.teamace.user.domain.User;
56
import org.springframework.util.StringUtils;
67

78
public record LoginCommand(String username) {
89
public LoginCommand {
910
if (!StringUtils.hasText(username)) {
1011
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
1112
}
12-
if (username.length() > 20) {
13+
if (username.length() > User.MAX_USERNAME_LENGTH) {
1314
throw new IllegalArgumentException(USERNAME_SIZE);
1415
}
1516
}

src/main/java/com/nexters/teamace/auth/application/SignupCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;
44

5+
import com.nexters.teamace.user.domain.User;
56
import org.springframework.util.StringUtils;
67

78
public record SignupCommand(String username, String nickname) {
89
public SignupCommand {
910
if (!StringUtils.hasText(username)) {
1011
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
1112
}
12-
if (username.length() > 20) {
13+
if (username.length() > User.MAX_USERNAME_LENGTH) {
1314
throw new IllegalArgumentException(USERNAME_SIZE);
1415
}
1516
if (!StringUtils.hasText(nickname)) {
1617
throw new IllegalArgumentException(NICKNAME_NOT_BLANK);
1718
}
18-
if (nickname.length() > 20) {
19+
if (nickname.length() > User.MAX_NICKNAME_LENGTH) {
1920
throw new IllegalArgumentException(NICKNAME_SIZE);
2021
}
2122
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package com.nexters.teamace.auth.presentation;
22

33
import com.nexters.teamace.common.exception.ValidationErrorMessage;
4+
import com.nexters.teamace.user.domain.User;
45
import jakarta.validation.constraints.NotBlank;
56
import jakarta.validation.constraints.Size;
67

78
public record SignupRequest(
89
@NotBlank(message = ValidationErrorMessage.USERNAME_NOT_BLANK)
9-
@Size(min = 1, max = 20, message = ValidationErrorMessage.USERNAME_SIZE)
10+
@Size(
11+
min = 1,
12+
max = User.MAX_USERNAME_LENGTH,
13+
message = ValidationErrorMessage.USERNAME_SIZE)
1014
String username,
1115
@NotBlank(message = ValidationErrorMessage.NICKNAME_NOT_BLANK)
12-
@Size(min = 1, max = 20, message = ValidationErrorMessage.NICKNAME_SIZE)
16+
@Size(
17+
min = 1,
18+
max = User.MAX_NICKNAME_LENGTH,
19+
message = ValidationErrorMessage.NICKNAME_SIZE)
1320
String nickname) {}

src/main/java/com/nexters/teamace/common/exception/ValidationErrorMessage.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.nexters.teamace.common.exception;
22

3+
import com.nexters.teamace.user.domain.User;
4+
35
public class ValidationErrorMessage {
46

57
/** Auth */
@@ -9,9 +11,11 @@ public class ValidationErrorMessage {
911
public static final String USER_ID_NOT_NULL = "User ID cannot be null";
1012

1113
public static final String USER_ID_POSITIVE = "User ID must be greater than or equal to 1";
12-
public static final String USERNAME_SIZE = "Username must be between 1 and 20 characters";
14+
public static final String USERNAME_SIZE =
15+
"Username must be between 1 and " + User.MAX_USERNAME_LENGTH + " characters";
1316

14-
public static final String NICKNAME_SIZE = "Nickname must be between 1 and 20 characters";
17+
public static final String NICKNAME_SIZE =
18+
"Nickname must be between 1 and " + User.MAX_NICKNAME_LENGTH + " characters";
1519
public static final String USERNAME_NOT_BLANK = "username must not be blank";
1620
public static final String NICKNAME_NOT_BLANK = "nickname must not be blank";
1721

src/main/java/com/nexters/teamace/user/application/CreateUserCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.nexters.teamace.common.exception.ValidationErrorMessage.*;
44

5+
import com.nexters.teamace.user.domain.User;
56
import org.springframework.util.StringUtils;
67

78
public record CreateUserCommand(String username, String nickname) {
@@ -10,15 +11,15 @@ public record CreateUserCommand(String username, String nickname) {
1011
if (!StringUtils.hasText(username)) {
1112
throw new IllegalArgumentException(USERNAME_NOT_BLANK);
1213
}
13-
if (username.length() > 20) {
14+
if (username.length() > User.MAX_USERNAME_LENGTH) {
1415
throw new IllegalArgumentException(USERNAME_SIZE);
1516
}
1617
}
1718
if (nickname != null) {
1819
if (!StringUtils.hasText(nickname)) {
1920
throw new IllegalArgumentException(NICKNAME_NOT_BLANK);
2021
}
21-
if (nickname.length() > 20) {
22+
if (nickname.length() > User.MAX_NICKNAME_LENGTH) {
2223
throw new IllegalArgumentException(NICKNAME_SIZE);
2324
}
2425
}

src/main/java/com/nexters/teamace/user/domain/User.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@NoArgsConstructor(access = PROTECTED)
1010
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
1111
public class User {
12+
public static final int MAX_USERNAME_LENGTH = 50;
13+
public static final int MAX_NICKNAME_LENGTH = 20;
1214

1315
@Getter @EqualsAndHashCode.Include private Long id;
1416
@Getter private String username;

src/test/java/com/nexters/teamace/auth/application/LoginCommandTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ void it_throws_IllegalArgumentException() {
5050
}
5151

5252
@Nested
53-
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
53+
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
5454
class Context_when_creating_with_username_longer_than_20_characters {
5555

5656
@Test
5757
@DisplayName("IllegalArgumentException을 던진다")
5858
void it_throws_IllegalArgumentException() {
59-
final String longUsername = "a".repeat(21);
59+
final String longUsername = "a".repeat(51);
6060

6161
thenThrownBy(() -> new LoginCommand(longUsername))
6262
.isInstanceOf(IllegalArgumentException.class)
63-
.hasMessage("Username must be between 1 and 20 characters");
63+
.hasMessage("Username must be between 1 and 50 characters");
6464
}
6565
}
6666
}

src/test/java/com/nexters/teamace/auth/application/SignupCommandTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ void it_throws_IllegalArgumentException() {
5151
}
5252

5353
@Nested
54-
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
54+
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
5555
class Context_when_creating_with_username_longer_than_20_characters {
5656

5757
@Test
5858
@DisplayName("IllegalArgumentException을 던진다")
5959
void it_throws_IllegalArgumentException() {
60-
final String longUsername = "a".repeat(21);
60+
final String longUsername = "a".repeat(51);
6161

6262
thenThrownBy(() -> new SignupCommand(longUsername, "Valid User"))
6363
.isInstanceOf(IllegalArgumentException.class)
64-
.hasMessage("Username must be between 1 and 20 characters");
64+
.hasMessage("Username must be between 1 and 50 characters");
6565
}
6666
}
6767

src/test/java/com/nexters/teamace/user/application/CreateUserCommandTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ void it_throws_IllegalArgumentException() {
6666
}
6767

6868
@Nested
69-
@DisplayName("20자보다 긴 사용자명으로 생성할 때")
69+
@DisplayName("50자보다 긴 사용자명으로 생성할 때")
7070
class Context_when_creating_with_username_longer_than_20_characters {
7171

7272
@Test
7373
@DisplayName("IllegalArgumentException을 던진다")
7474
void it_throws_IllegalArgumentException() {
75-
final String longUsername = "a".repeat(21);
75+
final String longUsername = "a".repeat(51);
7676

7777
thenThrownBy(() -> new CreateUserCommand(longUsername, "Valid User"))
7878
.isInstanceOf(IllegalArgumentException.class)
79-
.hasMessage("Username must be between 1 and 20 characters");
79+
.hasMessage("Username must be between 1 and 50 characters");
8080
}
8181
}
8282

0 commit comments

Comments
 (0)