Refactor code
- Rename AppConfiguration -> AccountModuleConfiguration - Refactor RegisterAccountProcessor using cqs principle
This commit is contained in:
@@ -38,10 +38,9 @@ public class AccountFacade {
|
||||
|
||||
@Transactional
|
||||
public void register(RegisterAccountCommand command) {
|
||||
var entity = registerProcessor.register(
|
||||
command.getEmail(),
|
||||
command.getPassword()
|
||||
);
|
||||
registerProcessor.register(command.getEmail(), command.getPassword());
|
||||
var entity = accountReader.findByEmail(command.getEmail())
|
||||
.orElseThrow(() -> new AccountNotFoundException(command.getEmail()));
|
||||
publisher.publishEvent(new RegisterAccountEvent(entity));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class RegisterAccountProcessor {
|
||||
this.passwordEncrypter = passwordEncrypter;
|
||||
}
|
||||
|
||||
public Account register(String email, String password) {
|
||||
public void register(String email, String password) {
|
||||
if (accountReader.existsByEmail(email)) {
|
||||
throw new DuplicateValueException(email);
|
||||
}
|
||||
@@ -23,7 +23,5 @@ public final class RegisterAccountProcessor {
|
||||
String encodedPassword = passwordEncrypter.encode(password);
|
||||
|
||||
accountRepository.save(Account.of(email, encodedPassword));
|
||||
return accountReader.findByEmail(email)
|
||||
.orElseThrow(() -> new AccountNotFoundException(email));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class AppConfiguration {
|
||||
public class AccountModuleConfiguration {
|
||||
|
||||
@Bean
|
||||
@Profile("prod")
|
||||
@@ -2,8 +2,8 @@ package com.yam.app.account.infrastructure;
|
||||
|
||||
import com.yam.app.account.domain.RegisterAccountEvent;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
import org.thymeleaf.context.Context;
|
||||
|
||||
@@ -21,7 +21,7 @@ final class MailManager {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@TransactionalEventListener
|
||||
public void handle(RegisterAccountEvent event) {
|
||||
var newAccount = event.getAccount();
|
||||
var context = new Context();
|
||||
|
||||
Reference in New Issue
Block a user