Refactor code

This commit is contained in:
Rebwon
2021-09-08 19:27:56 +09:00
committed by MaengSol
parent 6841f40cc9
commit ca12815e42
6 changed files with 62 additions and 29 deletions

View File

@@ -15,35 +15,36 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class AccountFacade {
private final RegisterAccountProcessor processor;
private final RegisterAccountProcessor registerProcessor;
private final AccountTranslator translator;
private final ApplicationEventPublisher publisher;
private final ConfirmRegisterAccountProcessor confirmRegisterProcessor;
private final LoginAccountProcessor loginAccountProcessor;
private final LoginAccountProcessor loginProcessor;
public AccountFacade(RegisterAccountProcessor processor,
public AccountFacade(RegisterAccountProcessor registerProcessor,
AccountTranslator translator, ApplicationEventPublisher publisher,
ConfirmRegisterAccountProcessor confirmRegisterProcessor,
LoginAccountProcessor loginAccountProcessor) {
this.processor = processor;
LoginAccountProcessor loginProcessor) {
this.registerProcessor = registerProcessor;
this.translator = translator;
this.publisher = publisher;
this.confirmRegisterProcessor = confirmRegisterProcessor;
this.loginAccountProcessor = loginAccountProcessor;
this.loginProcessor = loginProcessor;
}
@Transactional
public AccountResponse register(RegisterAccountRequest request) {
var entity = processor.process(translator.toCommand(request));
var entity = registerProcessor.process(translator.toCommand(request));
publisher.publishEvent(new RegisterAccountEvent(entity));
return translator.toResponse(entity);
}
@Transactional
public void registerConfirm(ConfirmRegisterAccountRequest request) {
confirmRegisterProcessor.registerConfirm(translator.toCommand(request));
}
public void login(LoginAccountRequest request) {
loginAccountProcessor.login(translator.toCommand(request));
loginProcessor.login(translator.toCommand(request));
}
}

View File

@@ -22,5 +22,5 @@ alter table account
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(), true, now(), now(), 'jiwon', 'password!',
values ('jiwonDev@gmail.com', 'emailchecktoken', now(), false, now(), now(), 'jiwon', 'password!',
false, 'DEFAULT');

View File

@@ -0,0 +1,30 @@
package com.yam.app;
import static com.tngtech.archunit.library.Architectures.layeredArchitecture;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
@AnalyzeClasses(packagesOf = YouAndMeApplication.class)
final class ArchUnitTests {
@ArchTest
ArchRule cycleCheck = slices().matching("com.yam.app.(*)..")
.should().beFreeOfCycles();
@ArchTest
ArchRule layerCheck = layeredArchitecture()
.layer("Application").definedBy("..application..")
.layer("Domain").definedBy("..domain..")
.layer("Presentation").definedBy("..presentation..")
.layer("Infrastructure").definedBy("..infrastructure..")
.layer("Integration").definedBy("..integration..")
.whereLayer("Presentation").mayOnlyBeAccessedByLayers("Application", "Integration")
.whereLayer("Application").mayOnlyBeAccessedByLayers("Presentation", "Domain")
.whereLayer("Domain").mayOnlyBeAccessedByLayers("Application", "Infrastructure")
.whereLayer("Infrastructure").mayNotBeAccessedByAnyLayer()
.whereLayer("Integration").mayNotBeAccessedByAnyLayer();
}

View File

@@ -1,17 +0,0 @@
package com.yam.app;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.jupiter.api.Disabled;
@AnalyzeClasses(packagesOf = YouAndMeApplication.class)
@Disabled
final class CircularDependencyTests {
@ArchTest
ArchRule cycleCheck = slices().matching("com.yam.app.(*)..")
.should().beFreeOfCycles();
}

View File

@@ -1,7 +1,5 @@
package com.yam.app.account.integration;
package com.yam.app.account.infrastructure;
import com.yam.app.account.infrastructure.MailDispatcher;
import com.yam.app.account.infrastructure.MailMessage;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

View File

@@ -1,8 +1,10 @@
package com.yam.app.account.integration;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -52,4 +54,23 @@ final class AccountIntegrationTests {
.andExpect(jsonPath("$.email").isString())
.andExpect(jsonPath("$.nickname").isString());
}
@Test
@DisplayName("이메일과 토큰을 검증하고 회원의 상태를 업데이트하는 시나리오")
void register_confirm() throws Exception {
// Act
final var actions = mockMvc.perform(get("/api/accounts/authorize")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.param("token", "emailchecktoken")
.param("email", "jiwonDev@gmail.com")
);
// Assert
actions
.andDo(print())
.andExpect(status().isSeeOther())
.andExpect(redirectedUrl("http://localhost:3000/login"));
}
}