refactor: properties message 다국어 적용
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ticketing.server.global.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||||
|
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MessagesConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ResourceBundleMessageSource messageSource() {
|
||||||
|
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||||
|
messageSource.setBasename("i18n/messages");
|
||||||
|
messageSource.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
|
return messageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LocalValidatorFactoryBean getValidator() {
|
||||||
|
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
||||||
|
factoryBean.setValidationMessageSource(messageSource());
|
||||||
|
|
||||||
|
return factoryBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,18 +9,18 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class SignUpRequest {
|
public class SignUpRequest {
|
||||||
|
|
||||||
@NotEmpty(message = "이름은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.name}")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@NotEmpty(message = "이메일은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.email}")
|
||||||
@Email(message = "이메일이 올바르지 않습니다.")
|
@Email(message = "{validation.email}")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotEmpty(message = "패스워드는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotEmpty(message = "휴대번호는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||||
@Phone(message = "휴대번호가 올바르지 않습니다.")
|
@Phone(message = "{validation.phone}")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
public SignUp toSignUp() {
|
public SignUp toSignUp() {
|
||||||
|
|||||||
@@ -19,26 +19,26 @@ import lombok.NoArgsConstructor;
|
|||||||
public class User extends AbstractEntity {
|
public class User extends AbstractEntity {
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
@NotEmpty(message = "이름은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.name}")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name = "email")
|
@Column(name = "email")
|
||||||
@NotEmpty(message = "이메일은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.email}")
|
||||||
@Email(message = "이메일이 올바르지 않습니다.")
|
@Email(message = "{validation.email}")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Column(name = "password")
|
@Column(name = "password")
|
||||||
@NotEmpty(message = "패스워드는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Column(name = "grade")
|
@Column(name = "grade")
|
||||||
@NotNull(message = "사용자 등급은 필수 입니다.")
|
@NotNull(message = "{validation.not.empty.grade}")
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private UserGrade grade;
|
private UserGrade grade;
|
||||||
|
|
||||||
@Column(name = "phone")
|
@Column(name = "phone")
|
||||||
@NotEmpty(message = "휴대번호는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||||
@Phone(message = "휴대번호가 올바르지 않습니다.")
|
@Phone(message = "{validation.phone}")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
private boolean isDeleted = false;
|
private boolean isDeleted = false;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public User register(@Valid SignUp signUpDto) {
|
public User register(@Valid SignUp signUpDto) {
|
||||||
validateEmail(signUpDto.getEmail());
|
validateEmail(signUpDto.getEmail());
|
||||||
|
|||||||
@@ -9,18 +9,18 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
@Getter
|
@Getter
|
||||||
public class SignUp {
|
public class SignUp {
|
||||||
|
|
||||||
@NotEmpty(message = "이름은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.name}")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@NotEmpty(message = "이메일은 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.email}")
|
||||||
@Email(message = "이메일이 올바르지 않습니다.")
|
@Email(message = "{validation.email}")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotEmpty(message = "패스워드는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotEmpty(message = "휴대번호는 필수 입니다.")
|
@NotEmpty(message = "{validation.not.empty.phone}")
|
||||||
@Phone(message = "휴대번호가 올바르지 않습니다.")
|
@Phone(message = "{validation.phone}")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
public SignUp(String name, String email, String password, String phone) {
|
public SignUp(String name, String email, String password, String phone) {
|
||||||
|
|||||||
7
server/src/main/resources/i18n/messages.properties
Normal file
7
server/src/main/resources/i18n/messages.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||||
|
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||||
7
server/src/main/resources/i18n/messages_en.properties
Normal file
7
server/src/main/resources/i18n/messages_en.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
validation.not.empty.name="name is required."
|
||||||
|
validation.not.empty.email="email is required."
|
||||||
|
validation.not.empty.password="password is required."
|
||||||
|
validation.not.empty.grade="user grade is required."
|
||||||
|
validation.not.empty.phone="phone is required."
|
||||||
|
validation.email="email is not valid."
|
||||||
|
validation.phone="phone is not valid."
|
||||||
7
server/src/main/resources/i18n/messages_ko.properties
Normal file
7
server/src/main/resources/i18n/messages_ko.properties
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
||||||
|
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||||
|
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.ticketing.server.user.domain;
|
package com.ticketing.server.user.domain;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
@@ -23,6 +22,7 @@ class UserTest {
|
|||||||
void init() {
|
void init() {
|
||||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
||||||
validator = factory.getValidator();
|
validator = factory.getValidator();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -49,10 +49,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("이름은 필수 입니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -66,10 +63,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("이메일은 필수 입니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -83,10 +77,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("이메일이 올바르지 않습니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -100,10 +91,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("패스워드는 필수 입니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -116,10 +104,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("사용자 등급은 필수 입니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -133,10 +118,7 @@ class UserTest {
|
|||||||
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertAll(
|
assertThat(constraintViolations).hasSize(1);
|
||||||
() -> assertThat(constraintViolations).hasSize(1),
|
|
||||||
() -> assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("휴대번호는 필수 입니다.")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@@ -151,7 +133,6 @@ class UserTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(constraintViolations).hasSize(1);
|
assertThat(constraintViolations).hasSize(1);
|
||||||
assertThat(constraintViolations.iterator().next().getMessage()).isEqualTo("휴대번호가 올바르지 않습니다.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user