Refactor code
- Exclude account domain property nickname - Add account response property
This commit is contained in:
@@ -38,9 +38,8 @@ public class AccountFacade {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void register(RegisterAccountCommand command) {
|
public void register(RegisterAccountCommand command) {
|
||||||
var entity = registerProcessor.process(
|
var entity = registerProcessor.register(
|
||||||
command.getEmail(),
|
command.getEmail(),
|
||||||
command.getNickname(),
|
|
||||||
command.getPassword()
|
command.getPassword()
|
||||||
);
|
);
|
||||||
publisher.publishEvent(new RegisterAccountEvent(entity));
|
publisher.publishEvent(new RegisterAccountEvent(entity));
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ final class AccountTranslator {
|
|||||||
|
|
||||||
public AccountResponse toResponse(Account entity) {
|
public AccountResponse toResponse(Account entity) {
|
||||||
return new AccountResponse(entity.getId(), entity.getEmail(),
|
return new AccountResponse(entity.getId(), entity.getEmail(),
|
||||||
entity.getNickname());
|
entity.isEmailVerified(), entity.getJoinedAt(), entity.getLastModifiedAt(),
|
||||||
|
entity.getWithdrawalAt(), entity.isWithdraw(), entity.getRole().name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ public final class Account {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private String email;
|
private String email;
|
||||||
private String nickname;
|
|
||||||
private String password;
|
private String password;
|
||||||
private String emailCheckToken;
|
private String emailCheckToken;
|
||||||
private LocalDateTime emailCheckTokenGeneratedAt;
|
private LocalDateTime emailCheckTokenGeneratedAt;
|
||||||
@@ -22,15 +21,14 @@ public final class Account {
|
|||||||
private boolean withdraw = false;
|
private boolean withdraw = false;
|
||||||
private Role role;
|
private Role role;
|
||||||
|
|
||||||
private Account(String email, String nickname, String password) {
|
private Account(String email, String password) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.nickname = nickname;
|
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.role = Role.DEFAULT;
|
this.role = Role.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account of(String email, String nickname, String password) {
|
public static Account of(String email, String password) {
|
||||||
Account account = new Account(email, nickname, password);
|
Account account = new Account(email, password);
|
||||||
account.generateEmailCheckToken();
|
account.generateEmailCheckToken();
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,5 @@ public interface AccountReader {
|
|||||||
|
|
||||||
boolean existsByEmail(String email);
|
boolean existsByEmail(String email);
|
||||||
|
|
||||||
boolean existsByNickname(String nickname);
|
|
||||||
|
|
||||||
Optional<Account> findByEmail(String email);
|
Optional<Account> findByEmail(String email);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,14 @@ public final class RegisterAccountProcessor {
|
|||||||
this.passwordEncrypter = passwordEncrypter;
|
this.passwordEncrypter = passwordEncrypter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account process(String email, String nickname, String password) {
|
public Account register(String email, String password) {
|
||||||
if (accountReader.existsByEmail(email)) {
|
if (accountReader.existsByEmail(email)) {
|
||||||
throw new DuplicateValueException(email);
|
throw new DuplicateValueException(email);
|
||||||
}
|
}
|
||||||
if (accountReader.existsByNickname(nickname)) {
|
|
||||||
throw new DuplicateValueException(nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
String encodedPassword = passwordEncrypter.encode(password);
|
String encodedPassword = passwordEncrypter.encode(password);
|
||||||
|
|
||||||
accountRepository.save(Account.of(email, nickname, encodedPassword));
|
accountRepository.save(Account.of(email, encodedPassword));
|
||||||
return accountReader.findByEmail(email)
|
return accountReader.findByEmail(email)
|
||||||
.orElseThrow(() -> new AccountNotFoundException(email));
|
.orElseThrow(() -> new AccountNotFoundException(email));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ final class MailManager {
|
|||||||
context.setVariable("link",
|
context.setVariable("link",
|
||||||
"/api/accounts/authorize?token=" + newAccount.getEmailCheckToken()
|
"/api/accounts/authorize?token=" + newAccount.getEmailCheckToken()
|
||||||
+ "&email=" + newAccount.getEmail());
|
+ "&email=" + newAccount.getEmail());
|
||||||
context.setVariable("nickname", newAccount.getNickname());
|
var username = newAccount.getEmail().split("@")[0];
|
||||||
|
context.setVariable("username", username);
|
||||||
context.setVariable("linkName", "이메일 인증하기");
|
context.setVariable("linkName", "이메일 인증하기");
|
||||||
context.setVariable("message", "YouAndMe 서비스를 사용하려면 링크를 클릭하세요.");
|
context.setVariable("message", "YouAndMe 서비스를 사용하려면 링크를 클릭하세요.");
|
||||||
context.setVariable("host", host);
|
context.setVariable("host", host);
|
||||||
|
|||||||
@@ -31,11 +31,6 @@ public final class MybatisAccountRepository implements AccountRepository, Accoun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean existsByNickname(String nickname) {
|
|
||||||
return template.getMapper(AccountReader.class).existsByNickname(nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Account entity) {
|
public void save(Account entity) {
|
||||||
int result = template.insert(SAVE_FQCN, entity);
|
int result = template.insert(SAVE_FQCN, entity);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.yam.app.account.presentation;
|
package com.yam.app.account.presentation;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -7,11 +8,23 @@ public final class AccountResponse {
|
|||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String email;
|
private final String email;
|
||||||
private final String nickname;
|
private final boolean emailVerified;
|
||||||
|
private final LocalDateTime joinedAt;
|
||||||
|
private final LocalDateTime lastModifiedAt;
|
||||||
|
private final LocalDateTime withdrawalAt;
|
||||||
|
private final boolean withdraw;
|
||||||
|
private final String role;
|
||||||
|
|
||||||
public AccountResponse(Long id, String email, String nickname) {
|
public AccountResponse(Long id, String email, boolean emailVerified,
|
||||||
|
LocalDateTime joinedAt, LocalDateTime lastModifiedAt, LocalDateTime withdrawalAt,
|
||||||
|
boolean withdraw, String role) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.nickname = nickname;
|
this.emailVerified = emailVerified;
|
||||||
|
this.joinedAt = joinedAt;
|
||||||
|
this.lastModifiedAt = lastModifiedAt;
|
||||||
|
this.withdrawalAt = withdrawalAt;
|
||||||
|
this.withdraw = withdraw;
|
||||||
|
this.role = role;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ public final class RegisterAccountCommand {
|
|||||||
@NotBlank
|
@NotBlank
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Pattern(regexp = "^[A-Za-z1-9~!@#$%^&*()+|=]{8,12}$",
|
@Pattern(regexp = "^[A-Za-z1-9~!@#$%^&*()+|=]{8,12}$",
|
||||||
message = "Please enter the password in English, numbers, "
|
message = "Please enter the password in English, numbers, "
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
email_check_token = #{emailCheckToken},
|
email_check_token = #{emailCheckToken},
|
||||||
email_check_token_generated_at = #{emailCheckTokenGeneratedAt},
|
email_check_token_generated_at = #{emailCheckTokenGeneratedAt},
|
||||||
email_verified = #{emailVerified},
|
email_verified = #{emailVerified},
|
||||||
nickname = #{nickname},
|
|
||||||
password = #{password},
|
password = #{password},
|
||||||
withdraw = #{withdraw},
|
withdraw = #{withdraw},
|
||||||
joined_at = #{joinedAt},
|
joined_at = #{joinedAt},
|
||||||
@@ -20,9 +19,9 @@
|
|||||||
<insert id="save" parameterType="com.yam.app.account.domain.Account">
|
<insert id="save" parameterType="com.yam.app.account.domain.Account">
|
||||||
INSERT
|
INSERT
|
||||||
INTO ACCOUNT(email, email_check_token, email_check_token_generated_at, email_verified,
|
INTO ACCOUNT(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||||
nickname, password, withdraw, role)
|
password, withdraw, role)
|
||||||
VALUES (#{email}, #{emailCheckToken}, #{emailCheckTokenGeneratedAt}, #{emailVerified},
|
VALUES (#{email}, #{emailCheckToken}, #{emailCheckTokenGeneratedAt}, #{emailVerified},
|
||||||
#{nickname}, #{password}, #{withdraw}, #{role})
|
#{password}, #{withdraw}, #{role})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ create table account
|
|||||||
joined_at timestamp,
|
joined_at timestamp,
|
||||||
last_modified_at timestamp,
|
last_modified_at timestamp,
|
||||||
role varchar(255) not null,
|
role varchar(255) not null,
|
||||||
nickname varchar(255) not null,
|
|
||||||
password varchar(255) not null,
|
password varchar(255) not null,
|
||||||
withdraw boolean not null,
|
withdraw boolean not null,
|
||||||
withdrawal_at timestamp,
|
withdrawal_at timestamp,
|
||||||
@@ -17,13 +16,11 @@ create table account
|
|||||||
|
|
||||||
alter table account
|
alter table account
|
||||||
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||||
alter table account
|
|
||||||
add constraint UK_s2a5omeaik0sruawqpvs18qfk unique (nickname);
|
|
||||||
|
|
||||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||||
joined_at, last_modified_at, nickname, password, withdraw, role)
|
joined_at, last_modified_at, password, withdraw, role)
|
||||||
values ('jiwonDev@gmail.com', 'emailchecktoken', now(), false, now(), now(), 'jiwon', 'password!',
|
values ('jiwonDev@gmail.com', 'emailchecktoken', now(), false, now(), now(), 'password!',
|
||||||
false, 'DEFAULT'),
|
false, 'DEFAULT'),
|
||||||
('loginCheck@gmail.com', 'emailchecktoken1', now(), true, now(), now(), 'loginCheck',
|
('loginCheck@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||||
false, 'DEFAULT');
|
false, 'DEFAULT');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<p>안녕하세요. <span th:text="${nickname}"></span>님</p>
|
<p>안녕하세요. <span th:text="${username}"></span>님</p>
|
||||||
|
|
||||||
<h2 th:text="${message}">메시지</h2>
|
<h2 th:text="${message}">메시지</h2>
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ final class ConfirmRegisterAccountProcessorTest {
|
|||||||
final var confirmRegisterAccountProcessor = new ConfirmRegisterAccountProcessor(
|
final var confirmRegisterAccountProcessor = new ConfirmRegisterAccountProcessor(
|
||||||
accountReader, accountRepository, tokenVerifier);
|
accountReader, accountRepository, tokenVerifier);
|
||||||
|
|
||||||
accountRepository.save(Account.of("jiwonDev@gmail.com", "jiwon", "password!"));
|
accountRepository.save(Account.of("jiwonDev@gmail.com", "password!"));
|
||||||
final var account = accountReader.findByEmail("jiwonDev@gmail.com").get();
|
final var account = accountReader.findByEmail("jiwonDev@gmail.com").get();
|
||||||
|
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
|
|||||||
@@ -28,12 +28,6 @@ public final class FakeAccountRepository implements AccountRepository, AccountRe
|
|||||||
data.putIfAbsent(entity.getId(), entity);
|
data.putIfAbsent(entity.getId(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean existsByNickname(String nickname) {
|
|
||||||
return data.values().stream()
|
|
||||||
.anyMatch(account -> account.getNickname().equals(nickname));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Account entity) {
|
public void save(Account entity) {
|
||||||
entity.setId(idGenerator.incrementAndGet());
|
entity.setId(idGenerator.incrementAndGet());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ final class RegisterAccountProcessorTest {
|
|||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
DynamicTest.dynamicTest("회원가입에 성공한다.", () -> {
|
DynamicTest.dynamicTest("회원가입에 성공한다.", () -> {
|
||||||
// Act
|
// Act
|
||||||
var account = processor.process("rebwon@gmail.com", "rebwon", "password!");
|
var account = processor.register("rebwon@gmail.com", "password!");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertThat(account.getId()).isEqualTo(1L);
|
assertThat(account.getId()).isEqualTo(1L);
|
||||||
@@ -32,12 +32,7 @@ final class RegisterAccountProcessorTest {
|
|||||||
DynamicTest.dynamicTest("이메일 검증에 실패하여 예외를 리턴한다.", () -> {
|
DynamicTest.dynamicTest("이메일 검증에 실패하여 예외를 리턴한다.", () -> {
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
assertThatExceptionOfType(DuplicateValueException.class)
|
assertThatExceptionOfType(DuplicateValueException.class)
|
||||||
.isThrownBy(() -> processor.process("rebwon@gmail.com", "rebwon", "password!"));
|
.isThrownBy(() -> processor.register("rebwon@gmail.com", "password!"));
|
||||||
}),
|
|
||||||
DynamicTest.dynamicTest("닉네임 검증에 실패하여 예외를 리턴한다.", () -> {
|
|
||||||
// Act & Assert
|
|
||||||
assertThatExceptionOfType(DuplicateValueException.class)
|
|
||||||
.isThrownBy(() -> processor.process("kitty@gmail.com", "rebwon", "password!"));
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ final class TokenVerifierTest {
|
|||||||
//Arrange
|
//Arrange
|
||||||
var accountRepository = new FakeAccountRepository();
|
var accountRepository = new FakeAccountRepository();
|
||||||
var tokenVerifier = new TokenVerifier(accountRepository);
|
var tokenVerifier = new TokenVerifier(accountRepository);
|
||||||
accountRepository.save(Account.of("jiwon@gmail.com", "jiwon", "password!"));
|
accountRepository.save(Account.of("jiwon@gmail.com", "password!"));
|
||||||
var account = accountRepository.findByEmail("jiwon@gmail.com").get();
|
var account = accountRepository.findByEmail("jiwon@gmail.com").get();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
|||||||
@@ -25,10 +25,8 @@ final class SessionBasedLoginAccountProcessorTest {
|
|||||||
var fakeObject = new FakeAccountRepository();
|
var fakeObject = new FakeAccountRepository();
|
||||||
final var accountRepository = fakeObject;
|
final var accountRepository = fakeObject;
|
||||||
final var accountReader = fakeObject;
|
final var accountReader = fakeObject;
|
||||||
var accountNotYetConfirm = Account.of("hello1@naver.com", "hello1",
|
var accountNotYetConfirm = Account.of("hello1@naver.com", "password!");
|
||||||
"password!");
|
var accountCompleted = Account.of("hello@naver.com", "password!");
|
||||||
var accountCompleted = Account.of("hello@naver.com", "hello",
|
|
||||||
"password!");
|
|
||||||
accountCompleted.completeRegister();
|
accountCompleted.completeRegister();
|
||||||
accountRepository.save(accountCompleted);
|
accountRepository.save(accountCompleted);
|
||||||
accountRepository.save(accountNotYetConfirm);
|
accountRepository.save(accountNotYetConfirm);
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ final class AccountIntegrationTests {
|
|||||||
// Arrange
|
// Arrange
|
||||||
var command = new RegisterAccountCommand();
|
var command = new RegisterAccountCommand();
|
||||||
command.setEmail("msolo021015@gmail.com");
|
command.setEmail("msolo021015@gmail.com");
|
||||||
command.setNickname("rebwon");
|
|
||||||
command.setPassword("password!");
|
command.setPassword("password!");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -100,6 +99,7 @@ final class AccountIntegrationTests {
|
|||||||
command.setEmail("loginCheck@gmail.com");
|
command.setEmail("loginCheck@gmail.com");
|
||||||
command.setPassword("password!");
|
command.setPassword("password!");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
mockMvc.perform(post(LOGIN)
|
mockMvc.perform(post(LOGIN)
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
@@ -119,7 +119,9 @@ final class AccountIntegrationTests {
|
|||||||
.andExpect(jsonPath("$.message").doesNotExist())
|
.andExpect(jsonPath("$.message").doesNotExist())
|
||||||
.andExpect(jsonPath("$.data.id").isNumber())
|
.andExpect(jsonPath("$.data.id").isNumber())
|
||||||
.andExpect(jsonPath("$.data.email").isString())
|
.andExpect(jsonPath("$.data.email").isString())
|
||||||
.andExpect(jsonPath("$.data.nickname").isString());
|
.andExpect(jsonPath("$.data.emailVerified").value(true))
|
||||||
|
.andExpect(jsonPath("$.data.withdraw").value(false))
|
||||||
|
.andExpect(jsonPath("$.data.role").value("DEFAULT"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ final class AccountCommandApiTests {
|
|||||||
// Arrange
|
// Arrange
|
||||||
var command = new RegisterAccountCommand();
|
var command = new RegisterAccountCommand();
|
||||||
command.setEmail(arg);
|
command.setEmail(arg);
|
||||||
command.setNickname(arg);
|
|
||||||
command.setPassword(arg);
|
command.setPassword(arg);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -211,7 +210,6 @@ final class AccountCommandApiTests {
|
|||||||
// Arrange
|
// Arrange
|
||||||
var command = new RegisterAccountCommand();
|
var command = new RegisterAccountCommand();
|
||||||
command.setEmail(arg);
|
command.setEmail(arg);
|
||||||
command.setNickname(arg);
|
|
||||||
command.setPassword(arg);
|
command.setPassword(arg);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -232,7 +230,6 @@ final class AccountCommandApiTests {
|
|||||||
// Arrange
|
// Arrange
|
||||||
var command = new RegisterAccountCommand();
|
var command = new RegisterAccountCommand();
|
||||||
command.setEmail(arg);
|
command.setEmail(arg);
|
||||||
command.setNickname("jiwon");
|
|
||||||
command.setPassword("password1!");
|
command.setPassword("password1!");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -253,7 +250,6 @@ final class AccountCommandApiTests {
|
|||||||
// Arrange
|
// Arrange
|
||||||
var command = new RegisterAccountCommand();
|
var command = new RegisterAccountCommand();
|
||||||
command.setEmail("jiwon@naver.com");
|
command.setEmail("jiwon@naver.com");
|
||||||
command.setNickname("jiwon");
|
|
||||||
command.setPassword(args);
|
command.setPassword(args);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
Reference in New Issue
Block a user