Skip to content

Commit

Permalink
feat-be: 이메일 전송 로직 중 지원자 일괄 조회 로직 구현 (#869)
Browse files Browse the repository at this point in the history
Co-authored-by: HyungHoKim00 <hkim1109@naver.com>
  • Loading branch information
github-actions[bot] and HyungHoKim00 authored Oct 22, 2024
1 parent ad3ac7b commit 826be35
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public Applicant create(ApplicantCreateRequest request, Process firstProcess) {
return applicantRepository.save(new Applicant(request.name(), request.email(), request.phone(), firstProcess));
}

public List<Applicant> findAllByProcess(Process process) {
return applicantRepository.findAllByProcess(process);
}

@Transactional
public void updateApplicantInformation(long applicantId, ApplicantUpdateRequest request) {
Applicant applicant = findById(applicantId);
Expand Down Expand Up @@ -147,8 +143,16 @@ public List<Applicant> findAllByProcesses(List<Process> processes) {
.toList();
}

public List<Applicant> findAllByProcess(Process process) {
return applicantRepository.findAllByProcess(process);
}

@Transactional
public void deleteAllInBatch(List<Applicant> applicants) {
applicantRepository.deleteAllInBatch(applicants);
}

public List<Applicant> findAllByIds(List<Long> ids) {
return applicantRepository.findAllById(ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public class EmailFacade {

public void send(EmailRequest request) {
Club from = clubService.findById(request.clubId());
List<Applicant> applicants = request.applicantIds()
.stream()
.map(applicantService::findById)
.toList();
List<Applicant> applicants = applicantService.findAllByIds(request.applicantIds());
sendAndSave(from, applicants, request.subject(), request.content(), request.files());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,31 @@ void deleteAllInBatch() {
assertThat(applicantRepository.findAll()).contains(applicant3)
.doesNotContain(applicant1, applicant2);
}

@DisplayName("IN절을 활용하여 id로 지원자를 찾는다.")
@Test
void findAllByIds() {
// given
List<Applicant> applicants = applicantRepository.saveAll(List.of(
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby(),
ApplicantFixture.pendingDobby(), ApplicantFixture.pendingDobby()
));
List<Long> ids = applicants.stream()
.map(Applicant::getId)
.toList();

// when
List<Applicant> found = applicantRepository.findAllById(ids);

// then
assertThat(found).containsExactlyInAnyOrderElementsOf(applicants);
}
}

0 comments on commit 826be35

Please sign in to comment.