Skip to content

Commit

Permalink
Merge pull request #95 from Bamdoliro/refactor/#94
Browse files Browse the repository at this point in the history
[개선] 단체 그룹 메시지 보내기 기능 리팩토링
  • Loading branch information
cabbage16 authored Jul 6, 2024
2 parents 3034f17 + e56c936 commit a0be604
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@ public void execute(SendMessageByTypeRequest request) {
sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle());
}

private List<Form> formListFilter(FormType formType, Boolean isChangeToRegular) {
private List<Form> formListFilter(FormType formType, Boolean isChangedToRegular) {
List<Form> 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;
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public interface FormRepositoryCustom {
List<Form> findReceivedRegularOrSupernumeraryForm();
List<Form> findFirstRoundForm();
List<Form> findMeisterTalentFirstRoundForm();
List<Form> findNotExistsMeisterTalentFirstRoundForm();
List<Form> findNotExistsMeisterTalentAndChangedToRegularFirstRoundForm();
List<Form> findChangedToRegularFirstRoundForm();
List<Form> findSecondRoundForm();
List<Form> findByFormIdList(List<Long> idList);
List<FormUrlVo> findFormUrlByFormIdList(List<Long> idList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,23 @@ public List<Form> findMeisterTalentFirstRoundForm() {
}

@Override
public List<Form> findNotExistsMeisterTalentFirstRoundForm() {
public List<Form> 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<Form> findChangedToRegularFirstRoundForm() {
return queryFactory
.selectFrom(form)
.where(form.status.eq(FormStatus.FIRST_PASSED)
.and(form.type.eq(FormType.REGULAR)
.and(form.changedToRegular.isTrue()))
)
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
Expand All @@ -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());
}

Expand Down

0 comments on commit a0be604

Please sign in to comment.