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