diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java index 814e0745..ef1db040 100644 --- a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -32,21 +32,15 @@ public void execute(SendMessageByTypeRequest request) { sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); } - private List
formListFilter(FormType formType, Boolean isChangeToRegular) { + private List formListFilter(FormType formType, Boolean isChangedToRegular) { List formList; if (formType.isMeister()) { formList = formRepository.findMeisterTalentFirstRoundForm(); } else { - formList = formRepository.findNotExistsMeisterTalentFirstRoundForm(); - if (isChangeToRegular) { - formList = formList.stream() - .filter(Form::getChangedToRegular) - .toList(); - } else { - formList = formList.stream() - .filter(form -> !form.getChangedToRegular()) - .toList(); - } + if(isChangedToRegular) + formList = formRepository.findChangedToRegularFirstRoundForm(); + else + formList = formRepository.findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm(); } return formList; diff --git a/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java b/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java index 793ee92c..d5841cf6 100644 --- a/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java +++ b/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java @@ -215,14 +215,6 @@ public void assignExaminationNumber(Long examinationNumber) { this.examinationNumber = examinationNumber; } - public FormType getType() { - if (changedToRegular) { - return FormType.REGULAR; - } - - return type; - } - public FormType getOriginalType() { return type; } diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java index ed7dec7e..7c2dd0ab 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java @@ -13,7 +13,8 @@ public interface FormRepositoryCustom { List findReceivedRegularOrSupernumeraryForm(); List findFirstRoundForm(); List findMeisterTalentFirstRoundForm(); - List findNotExistsMeisterTalentFirstRoundForm(); + List findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm(); + List findChangedToRegularFirstRoundForm(); List findSecondRoundForm(); List findByFormIdList(List idList); List findFormUrlByFormIdList(List idList); diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java index f78df470..d8cc004e 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java @@ -97,11 +97,23 @@ public List findMeisterTalentFirstRoundForm() { } @Override - public List findNotExistsMeisterTalentFirstRoundForm() { + public List findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm() { return queryFactory .selectFrom(form) .where(form.status.eq(FormStatus.FIRST_PASSED) - .and(form.type.ne(FormType.MEISTER_TALENT)) + .and(form.type.ne(FormType.MEISTER_TALENT) + .and(form.changedToRegular.isFalse())) + ) + .fetch(); + } + + @Override + public List findChangedToRegularFirstRoundForm() { + return queryFactory + .selectFrom(form) + .where(form.status.eq(FormStatus.FIRST_PASSED) + .and(form.type.eq(FormType.REGULAR) + .and(form.changedToRegular.isTrue())) ) .fetch(); } diff --git a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java index 8eba4f93..281922f4 100644 --- a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java +++ b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java @@ -197,14 +197,14 @@ public class SendMessageUseCaseTest { //given Form form = FormFixture.createForm(FormType.REGULAR); form.firstPass(); - given(formRepository.findNotExistsMeisterTalentFirstRoundForm()).willReturn(List.of(form)); + given(formRepository.findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm()).willReturn(List.of(form)); SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "살려줘요..", FormType.REGULAR, false); //when sendMessageUseCase.execute(request); //then - verify(formRepository, times(1)).findNotExistsMeisterTalentFirstRoundForm(); + verify(formRepository, times(1)).findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm(); verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); } @@ -232,7 +232,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.MEISTER_TALENT); when(calculateFormScoreService.calculateSubjectGradeScore(any())).thenReturn(100.0); - when(formRepository.findNotExistsMeisterTalentFirstRoundForm()).thenReturn(List.of(form)); + when(formRepository.findChangedToRegularFirstRoundForm()).thenReturn(List.of(form)); form.firstPass(); form.changeToRegular(calculateFormScoreService); @@ -243,7 +243,7 @@ public class SendMessageUseCaseTest { System.out.println(form.getUser().getPhoneNumber()); //then - verify(formRepository, times(1)).findNotExistsMeisterTalentFirstRoundForm(); + verify(formRepository, times(1)).findChangedToRegularFirstRoundForm(); verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); }