Skip to content

Commit

Permalink
Merge pull request #29 from januschung/alloffer
Browse files Browse the repository at this point in the history
make allOffer to return jobApplication properly
  • Loading branch information
januschung authored Dec 21, 2024
2 parents 4fdb113 + b6a8486 commit d465ebf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/tnite/jobwinner/service/InterviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ public Flux<Interview> getInterviewByJobApplicationId(Integer jobApplicationId)
}

public Flux<Interview> allInterview() {
// return interviewRepository.findAll()
// .doOnComplete(() -> log.info("Retrieved all interviews"))
// .doOnError(e -> log.error("Failed to retrieve interviews", e));
return interviewRepository.findAll()
.flatMap(interview ->
jobApplicationRepository.findById(interview.getJobApplicationId())
.map(jobApplication -> {
interview.setJobApplication(jobApplication);
return interview;
})
.defaultIfEmpty(interview) // If JobApplication not found, just return the offer without setting JobApplication
.doOnSuccess(o -> log.info("Retrieved interview with job application: {}", o))
.doOnError(e -> log.error("Failed to fetch job application for interview", e))
)
.doOnComplete(() -> log.info("Retrieved all interviews"))
.doOnError(e -> log.error("Failed to retrieve interviews", e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void testGetInterview() {
@Test
void testAllInterview() {
when(interviewRepository.findAll()).thenReturn(Flux.just(interview1, interview2));
when(jobApplicationRepository.findById(1)).thenReturn(Mono.just(jobApplication));

Flux<Interview> result = interviewService.allInterview();

Expand All @@ -143,5 +144,6 @@ void testAllInterview() {
.verifyComplete();

verify(interviewRepository, times(1)).findAll();
verify(jobApplicationRepository, times(2)).findById(anyInt());
}
}

0 comments on commit d465ebf

Please sign in to comment.