From d7d30bb79add0ce3a88bb65feeee6fe8a281127d Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 16:51:58 +0900 Subject: [PATCH 01/15] =?UTF-8?q?refactor:=20new=20throw=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EC=8B=B1=EA=B8=80=ED=86=A4=20=EA=B0=9D=EC=B2=B4=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applicant/event/domainevent/ApplicantStateEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/event/domainevent/ApplicantStateEvents.java b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/event/domainevent/ApplicantStateEvents.java index 62ef1e59..a5391644 100644 --- a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/event/domainevent/ApplicantStateEvents.java +++ b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/event/domainevent/ApplicantStateEvents.java @@ -22,6 +22,6 @@ public static ApplicantStateEvents find(String event){ return Arrays.stream(ApplicantStateEvents.values()) .filter(e -> e.getEvent().equals(event)) .findFirst() - .orElseThrow(ApplicantWrongStateException::new); + .orElseThrow(()->ApplicantWrongStateException.wrongStatusException); } } From e1a9f913f2547abd93cca62234ffcfb934031850 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 16:52:43 +0900 Subject: [PATCH 02/15] =?UTF-8?q?refactor:=20ApplicationState=EA=B0=80=20n?= =?UTF-8?q?ull=EC=9D=B8=EC=A7=80=20=EC=B2=B4=ED=81=AC,=20null=EC=9D=B4?= =?UTF-8?q?=EB=A9=B4=20default=EB=A1=9C=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domains/applicant/domain/MongoAnswer.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java index abd8b24a..51e28809 100644 --- a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java +++ b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java @@ -9,6 +9,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.checkerframework.checker.units.qual.A; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.index.TextIndexed; import org.springframework.data.mongodb.core.mapping.Document; @@ -47,6 +48,14 @@ public void nonPass(PeriodStates period){ this.applicantState.nonPass(period); } + public boolean stateUpdateValidate(){ + if(this.applicantState==null) { + this.applicantState = new ApplicantState(); + return true; + } + return false; + } + public MongoAnswer(String id, Integer year, Map qna) { this.id = id; this.year = year; From e5755785a11a0ed7b91ff338e86495cfd29684d6 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 16:54:19 +0900 Subject: [PATCH 03/15] =?UTF-8?q?refactor:=20stateEmptyCheckAndInit?= =?UTF-8?q?=EB=A1=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitdomain/domains/applicant/domain/MongoAnswer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java index 51e28809..1a0575aa 100644 --- a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java +++ b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java @@ -9,7 +9,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.checkerframework.checker.units.qual.A; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.index.TextIndexed; import org.springframework.data.mongodb.core.mapping.Document; @@ -48,7 +47,7 @@ public void nonPass(PeriodStates period){ this.applicantState.nonPass(period); } - public boolean stateUpdateValidate(){ + public boolean stateEmptyCheckAndInit(){ if(this.applicantState==null) { this.applicantState = new ApplicantState(); return true; From 63f0c0f6fac6db46ebe25b4e4f1da574e0e13364 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 22:43:01 +0900 Subject: [PATCH 04/15] =?UTF-8?q?refactor:=20=EC=A7=80=EC=9B=90=20?= =?UTF-8?q?=ED=98=84=ED=99=A9=20=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=20sta?= =?UTF-8?q?te=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/api/applicant/service/ApplicantService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java index 1bef0ded..9f0aa352 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java @@ -19,6 +19,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.econovation.recruitcommon.consts.RecruitStatic.PASS_STATE_KEY; + @Service @RequiredArgsConstructor public class ApplicantService implements ApplicantQueryUseCase { @@ -46,6 +48,7 @@ public Map execute(String answerId) { public AnswersResponseDto execute(Integer year, Integer page, String sortType) { PageInfo pageInfo = getPageInfo(year, page); List result = answerAdaptor.findByYear(year, page); + result.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantState())); sortHelper.sort(result, sortType); List> sortedResult = result.stream().map(MongoAnswer::getQna).toList(); @@ -104,6 +107,7 @@ public Map> findAllApplicantVo(List fields) @Override public AnswersResponseDto search(Integer page, String searchKeyword) { List answers = answerAdaptor.findBySearchKeyword(page, searchKeyword); + answers.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantState())); return AnswersResponseDto.of( answers.stream().map(MongoAnswer::getQna).toList(), new PageInfo(answers.size(), page)); From bb0567089fb5e659f0301812347e86e4f4242e63 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 22:45:18 +0900 Subject: [PATCH 05/15] =?UTF-8?q?refactor:=20getApplicantState=20=EC=9E=AC?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/econovation/recruit/api/card/service/CardService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java index 03e3290a..00a5c3ef 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java @@ -73,7 +73,7 @@ public List getByNavigationId(Integer navigationId, Intege Map stateByAnswerIdMap = mongoAnswers.stream() .collect(Collectors.toMap(MongoAnswer::getId, - answer -> answer.getApplicantState()!=null ? answer.getApplicantState() : new ApplicantState())); + MongoAnswer::getApplicantState)); List cards = cardLoadPort.findAll(); From 08d6ae83c383e9cdb6f589362c339f868651e882 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 22:46:21 +0900 Subject: [PATCH 06/15] =?UTF-8?q?refactor:=20state=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=8B=9C=20null=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/ApplicantStateUpdateEventHandler.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java index ae145454..abaeaae7 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java @@ -3,17 +3,11 @@ import com.econovation.recruit.api.applicant.state.support.PeriodCalculator; import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer; import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswerAdaptor; -import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantRegisterEvent; import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantStateEvents; import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantStateModifyEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.event.TransactionPhase; -import org.springframework.transaction.event.TransactionalEventListener; @Component @RequiredArgsConstructor @@ -31,6 +25,8 @@ public class ApplicantStateUpdateEventHandler { public String handle(ApplicantStateModifyEvent event){ MongoAnswer answer = answerAdaptor.findById(event.getApplicantId()).get(); ApplicantStateEvents command = event.getEvent(); + boolean result = answer.stateEmptyCheckAndInit(); + log.error(String.format("validate : %s", (result ? "새로운 state 초기화" : "state 초기화 하지 않고 변경"))); switch (command) { case PASS: answer.pass(periodCalculator.execute()); From 526dad090fb91e26bcc54f9616d69901eec2982c Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Sun, 15 Sep 2024 22:47:01 +0900 Subject: [PATCH 07/15] =?UTF-8?q?refactor:=20Applicant=20State=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=8B=9C=20=EC=9D=91=EB=8B=B5=20=ED=98=95=EC=8B=9D?= =?UTF-8?q?=20JSON=20=EA=B5=AC=EC=A1=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/applicant/controller/ApplicantController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/controller/ApplicantController.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/controller/ApplicantController.java index fbea6002..fe047b58 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/controller/ApplicantController.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/controller/ApplicantController.java @@ -1,6 +1,7 @@ package com.econovation.recruit.api.applicant.controller; import static com.econovation.recruitcommon.consts.RecruitStatic.APPLICANT_SUCCESS_REGISTER_MESSAGE; +import static com.econovation.recruitcommon.consts.RecruitStatic.PASS_STATE_KEY; import com.econovation.recruit.api.applicant.command.CreateAnswerCommand; import com.econovation.recruit.api.applicant.docs.CreateApplicantExceptionDocs; @@ -20,6 +21,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import java.time.LocalDateTime; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -146,10 +148,12 @@ public ResponseEntity sendEmail(@RequestBody EmailSendDto emailSendDto) { @Operation(summary = "지원자의 합/불 상태를 변경합니다.") @PatchMapping("/applicants/{applicant-id}/state") - public ResponseEntity updateStatus(@PathVariable("applicant-id") String applicantId, + public ResponseEntity> updateStatus(@PathVariable("applicant-id") String applicantId, @RequestParam("afterState") String afterState){ // commandGateway.send(new UpdateApplicantStateCommand(applicantId, afterState)); String state = applicantCommandUseCase.execute(applicantId, afterState); - return new ResponseEntity(state,HttpStatus.OK); + Map response = new HashMap<>(); + response.put(PASS_STATE_KEY, state); + return new ResponseEntity(response,HttpStatus.OK); } } From d60336d05bb4fd31abf971360ba1a44fabd4d5fc Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 00:48:20 +0900 Subject: [PATCH 08/15] =?UTF-8?q?refactor:=20qna=20Map=EA=B3=BC=20id?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/AnswerCommandService.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java index 1e52c0c1..10f7b185 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java @@ -29,6 +29,20 @@ public class AnswerCommandService implements ApplicantCommandUseCase { @Transactional public UUID execute(Map qna) { UUID id = UUID.randomUUID(); + execute(qna, id); + return id; + } + + @Override + @Transactional + public String execute(String applicantId, String afterState) { + ApplicantStateModifyEvent stateModifyEventEvents = + ApplicantStateModifyEvent.of(applicantId, afterState); + return applicantStateUpdateEventHandler.handle(stateModifyEventEvents); // 동기로 처리 + } + + @Override + public UUID execute(Map qna, UUID id) { ApplicantState nonPassed = new ApplicantState(); MongoAnswer answer = MongoAnswer.builder().id(id.toString()).qna(qna).year(year).applicantState(nonPassed).build(); // 학번으로 중복 체크 @@ -42,14 +56,6 @@ public UUID execute(Map qna) { ApplicantRegisterEvent applicantRegisterEvent = ApplicantRegisterEvent.of(answer.getId(), name, hopeField, email); Events.raise(applicantRegisterEvent); - return id; - } - - @Override - @Transactional - public String execute(String applicantId, String afterState) { - ApplicantStateModifyEvent stateModifyEventEvents = - ApplicantStateModifyEvent.of(applicantId, afterState); - return applicantStateUpdateEventHandler.handle(stateModifyEventEvents); // 동기로 처리 + return null; } } From 8e5264b89a19d0309832f0fac1bb4d1887c3df5b Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 00:49:07 +0900 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20qna=20=EB=A7=B5=EA=B3=BC=20id?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/api/applicant/usecase/ApplicantCommandUseCase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/usecase/ApplicantCommandUseCase.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/usecase/ApplicantCommandUseCase.java index 3c2e4e39..52b53fd2 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/usecase/ApplicantCommandUseCase.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/usecase/ApplicantCommandUseCase.java @@ -9,4 +9,6 @@ public interface ApplicantCommandUseCase { UUID execute(Map blocks); String execute(String applicantId, String state); + + UUID execute(Map blocks, UUID id); } From 69d7c05ea96bad511f7e933c069c5f4571ad6b4b Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 00:53:39 +0900 Subject: [PATCH 10/15] =?UTF-8?q?feat:=20=EC=A7=80=EC=9B=90=EC=84=9C?= =?UTF-8?q?=EC=9D=98=20state=20=ED=95=84=EB=93=9C=EA=B0=80=20null=EC=9D=BC?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20=EB=94=94=ED=8F=B4=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=B1=84=EC=9A=B0=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/utils/ApplicantStateCheck.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java new file mode 100644 index 00000000..11a0ac27 --- /dev/null +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java @@ -0,0 +1,64 @@ +package com.econovation.recruit.utils; + +import com.econovation.recruit.api.applicant.usecase.ApplicantCommandUseCase; +import com.econovation.recruit.api.applicant.usecase.ApplicantQueryUseCase; +import io.vavr.concurrent.Future; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ApplicantStateCheck implements ApplicationRunner { + + private final ApplicantCommandUseCase applicantCommandUseCase; + private final ApplicantQueryUseCase applicantQueryUseCase; + + @PostConstruct + public void init() throws IOException, SQLException { + // init.sql 파일을 읽어와서 실행합니다. + log.info("MongoDB Applicant State 체크를 시작합니다."); + } + + @Override + public void run(ApplicationArguments args) throws Exception { + List> answers = applicantQueryUseCase.execute(); + Future.of(() -> answers) + .map( + answer -> { + return answer.stream() + .map( + map -> { + Map qna = + map.entrySet().stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue)); + applicantCommandUseCase.execute(qna, UUID.fromString((String)qna.get("id"))); + return qna; + }) + .collect(Collectors.toList()); + }) + .onSuccess( + (qna) -> { + log.info("MongoDB Applicant State Check를 완료했습니다."); + }) + .onFailure( + (exception) -> { + exception.printStackTrace(); + log.error("MongoDB Applicant State Check를 실패했습니다."); + }); + } +} From 6783e2c669e1066f3bf18e0396a6cfecc0e98368 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 00:56:31 +0900 Subject: [PATCH 11/15] =?UTF-8?q?refactor:=20getApplicantStateOrDefault=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruitdomain/domains/applicant/domain/MongoAnswer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java index 1a0575aa..922212e8 100644 --- a/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java +++ b/server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/applicant/domain/MongoAnswer.java @@ -54,6 +54,11 @@ public boolean stateEmptyCheckAndInit(){ } return false; } + + public ApplicantState getApplicantStateOrDefault(){ + if(this.applicantState==null) return new ApplicantState(); + return this.applicantState; + } public MongoAnswer(String id, Integer year, Map qna) { this.id = id; From 7ba194c099f8dd5ff87b8f5f02620ee062407a64 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 00:57:37 +0900 Subject: [PATCH 12/15] =?UTF-8?q?refactor:=20getApplicantStateOrDefault?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aggregate/ApplicantStateUpdateEventListener.java | 2 +- .../applicant/handler/ApplicantStateUpdateEventHandler.java | 2 +- .../recruit/api/applicant/service/ApplicantService.java | 4 ++-- .../com/econovation/recruit/api/card/service/CardService.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/aggregate/ApplicantStateUpdateEventListener.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/aggregate/ApplicantStateUpdateEventListener.java index 3c78ce1a..28c397f5 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/aggregate/ApplicantStateUpdateEventListener.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/aggregate/ApplicantStateUpdateEventListener.java @@ -34,7 +34,7 @@ public String handle(ApplicantStateUpdateEvent event){ } answerAdaptor.save(answer); - return answer.getApplicantState().getPassState(); + return answer.getApplicantStateOrDefault().getPassState(); } } diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java index abaeaae7..281a1cde 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/handler/ApplicantStateUpdateEventHandler.java @@ -37,7 +37,7 @@ public String handle(ApplicantStateModifyEvent event){ } answerAdaptor.save(answer); - return answer.getApplicantState().getPassState(); + return answer.getApplicantStateOrDefault().getPassState(); } } diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java index 9f0aa352..7f7805fb 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/ApplicantService.java @@ -48,7 +48,7 @@ public Map execute(String answerId) { public AnswersResponseDto execute(Integer year, Integer page, String sortType) { PageInfo pageInfo = getPageInfo(year, page); List result = answerAdaptor.findByYear(year, page); - result.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantState())); + result.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantStateOrDefault())); sortHelper.sort(result, sortType); List> sortedResult = result.stream().map(MongoAnswer::getQna).toList(); @@ -107,7 +107,7 @@ public Map> findAllApplicantVo(List fields) @Override public AnswersResponseDto search(Integer page, String searchKeyword) { List answers = answerAdaptor.findBySearchKeyword(page, searchKeyword); - answers.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantState())); + answers.forEach(answer -> answer.getQna().put(PASS_STATE_KEY, answer.getApplicantStateOrDefault())); return AnswersResponseDto.of( answers.stream().map(MongoAnswer::getQna).toList(), new PageInfo(answers.size(), page)); diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java index 00a5c3ef..c64523a3 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/card/service/CardService.java @@ -73,7 +73,7 @@ public List getByNavigationId(Integer navigationId, Intege Map stateByAnswerIdMap = mongoAnswers.stream() .collect(Collectors.toMap(MongoAnswer::getId, - MongoAnswer::getApplicantState)); + MongoAnswer::getApplicantStateOrDefault)); List cards = cardLoadPort.findAll(); From 3589fdd15c19ebb9bbf0077da89631d226512a8d Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 10:54:14 +0900 Subject: [PATCH 13/15] =?UTF-8?q?refactor:=20state=EA=B0=80=20null?= =?UTF-8?q?=EC=9D=B8=20=EC=A7=80=EC=9B=90=EC=84=9C=EC=97=90=20=ED=95=9C?= =?UTF-8?q?=ED=95=B4=EC=84=9C=EB=A7=8C=20default=20=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/utils/ApplicantStateCheck.java | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java index 11a0ac27..b804c269 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java @@ -2,6 +2,8 @@ import com.econovation.recruit.api.applicant.usecase.ApplicantCommandUseCase; import com.econovation.recruit.api.applicant.usecase.ApplicantQueryUseCase; +import com.econovation.recruitdomain.domains.applicant.adaptor.AnswerAdaptor; +import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer; import io.vavr.concurrent.Future; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -22,8 +24,7 @@ @Slf4j public class ApplicantStateCheck implements ApplicationRunner { - private final ApplicantCommandUseCase applicantCommandUseCase; - private final ApplicantQueryUseCase applicantQueryUseCase; + private final AnswerAdaptor answerAdaptor; @PostConstruct public void init() throws IOException, SQLException { @@ -33,32 +34,14 @@ public void init() throws IOException, SQLException { @Override public void run(ApplicationArguments args) throws Exception { - List> answers = applicantQueryUseCase.execute(); - Future.of(() -> answers) - .map( - answer -> { - return answer.stream() - .map( - map -> { - Map qna = - map.entrySet().stream() - .collect( - Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue)); - applicantCommandUseCase.execute(qna, UUID.fromString((String)qna.get("id"))); - return qna; - }) - .collect(Collectors.toList()); - }) - .onSuccess( - (qna) -> { - log.info("MongoDB Applicant State Check를 완료했습니다."); - }) - .onFailure( - (exception) -> { - exception.printStackTrace(); - log.error("MongoDB Applicant State Check를 실패했습니다."); - }); + try { + List answers = answerAdaptor.findAll(); + answers.forEach(MongoAnswer::stateEmptyCheckAndInit); + answerAdaptor.saveAll(answers); + log.info("MongoDB Applicant State Check를 완료했습니다."); + } catch (Exception e){ + e.printStackTrace(); + log.error("MongoDB Applicant State Check를 실패했습니다."); + } } } From fccc9f0d176ab4b6111e98c6dc2d511931d3d695 Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 10:55:17 +0900 Subject: [PATCH 14/15] =?UTF-8?q?refactor:=20nonPassed=20->=20nonProcessed?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recruit/api/applicant/service/AnswerCommandService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java index 10f7b185..32524319 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/api/applicant/service/AnswerCommandService.java @@ -43,8 +43,8 @@ public String execute(String applicantId, String afterState) { @Override public UUID execute(Map qna, UUID id) { - ApplicantState nonPassed = new ApplicantState(); - MongoAnswer answer = MongoAnswer.builder().id(id.toString()).qna(qna).year(year).applicantState(nonPassed).build(); + ApplicantState nonProcessed = new ApplicantState(); + MongoAnswer answer = MongoAnswer.builder().id(id.toString()).qna(qna).year(year).applicantState(nonProcessed).build(); // 학번으로 중복 체크 // validateRegisterApplicant(qna); answerAdaptor.save(answer); From 90f40f7a42082f118b5272a94fc9749188dcbd1f Mon Sep 17 00:00:00 2001 From: KimJongMin Date: Mon, 16 Sep 2024 11:03:32 +0900 Subject: [PATCH 15/15] =?UTF-8?q?refactor:=20stream=20API=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=B4=EC=84=9C=20filter=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/econovation/recruit/utils/ApplicantStateCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java index b804c269..fbad39a9 100644 --- a/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java +++ b/server/Recruit-Api/src/main/java/com/econovation/recruit/utils/ApplicantStateCheck.java @@ -35,7 +35,7 @@ public void init() throws IOException, SQLException { @Override public void run(ApplicationArguments args) throws Exception { try { - List answers = answerAdaptor.findAll(); + List answers = answerAdaptor.findAll().stream().filter(answer -> answer.getApplicantState()==null).toList(); answers.forEach(MongoAnswer::stateEmptyCheckAndInit); answerAdaptor.saveAll(answers); log.info("MongoDB Applicant State Check를 완료했습니다.");