Skip to content

Commit

Permalink
fix-be: applicantCard 조회 시 평가 점수와 갯수가 모든 프로세스에 대해 나오는 버그 수정 (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungHoKim00 authored Oct 23, 2024
1 parent b8ebff3 commit ddd7041
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public interface ApplicantRepository extends JpaRepository<Applicant, Long> {
long countByProcess(Process process);

@Query("""
SELECT new com.cruru.applicant.domain.dto.ApplicantCard(
SELECT new com.cruru.applicant.domain.dto.ApplicantCard(
a.id, a.name, a.createdDate, a.isRejected, COUNT(e), COALESCE(AVG(e.score), 0.00), a.process.id
)
FROM Applicant a
LEFT JOIN Evaluation e ON e.applicant = a
LEFT JOIN Evaluation e ON e.applicant = a AND e.process = a.process
WHERE a.process IN :processes
GROUP BY a.id, a.name, a.createdDate, a.isRejected, a.process.id
""")
Expand All @@ -39,7 +39,7 @@ a.id, a.name, a.createdDate, a.isRejected, COUNT(e), COALESCE(AVG(e.score), 0.00
a.id, a.name, a.createdDate, a.isRejected, COUNT(e), COALESCE(AVG(e.score), 0.00), a.process.id
)
FROM Applicant a
LEFT JOIN Evaluation e ON e.applicant = a
LEFT JOIN Evaluation e ON e.applicant = a AND e.process = a.process
WHERE a.process = :process
GROUP BY a.id, a.name, a.createdDate, a.isRejected
""")
Expand Down
38 changes: 19 additions & 19 deletions backend/src/main/java/com/cruru/config/DataSourceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@ public class DataSourceConfig {
private static final String WRITE_DATASOURCE = "writeDataSource";
private static final String ROUTE_DATASOURCE = "routeDataSource";

@Bean(name = READ_DATASOURCE)
@ConfigurationProperties(prefix = "spring.datasource.read")
public DataSource readDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
}

@Bean(name = WRITE_DATASOURCE)
@ConfigurationProperties(prefix = "spring.datasource.write")
public DataSource writeDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
@Bean
@Primary
@DependsOn(ROUTE_DATASOURCE)
public DataSource defaultDataSource() {
return new LazyConnectionDataSourceProxy(routeDataSource());
}

@Bean(name = ROUTE_DATASOURCE)
Expand All @@ -50,10 +41,19 @@ public DataSourceRouter routeDataSource() {
return dataSourceRouter;
}

@Bean
@Primary
@DependsOn(ROUTE_DATASOURCE)
public DataSource defaultDataSource() {
return new LazyConnectionDataSourceProxy(routeDataSource());
@Bean(name = WRITE_DATASOURCE)
@ConfigurationProperties(prefix = "spring.datasource.write")
public DataSource writeDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
}

@Bean(name = READ_DATASOURCE)
@ConfigurationProperties(prefix = "spring.datasource.read")
public DataSource readDataSource() {
return DataSourceBuilder.create()
.type(HikariDataSource.class)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@ void saveNoId() {
@Test
void findApplicantCardsByProcesses() {
// given
Process process = processRepository.save(ProcessFixture.applyType());
Process process1 = processRepository.save(ProcessFixture.applyType());
Process process2 = processRepository.save(ProcessFixture.interview(null));

Applicant applicant1 = ApplicantFixture.pendingDobby(process);
Applicant applicant2 = ApplicantFixture.pendingRush(process);
Applicant applicant1 = ApplicantFixture.pendingDobby(process1);
Applicant applicant2 = ApplicantFixture.pendingRush(process1);
applicantRepository.saveAll(List.of(applicant1, applicant2));

List<Evaluation> evaluations = List.of(
EvaluationFixture.fivePoints(process, applicant1),
EvaluationFixture.fivePoints(process, applicant1),
EvaluationFixture.fivePoints(process, applicant2)
EvaluationFixture.fourPoints(process1, applicant1),
EvaluationFixture.fivePoints(process2, applicant1),
EvaluationFixture.fivePoints(process1, applicant2)
);
evaluationRepository.saveAll(evaluations);

// when
List<ApplicantCard> applicantCards = applicantRepository.findApplicantCardsByProcesses(List.of(process));
List<ApplicantCard> applicantCards = applicantRepository.findApplicantCardsByProcesses(List.of(process1));

// then
assertThat(applicantCards).hasSize(2);

ApplicantCard applicantCard1 = applicantCards.get(0);
assertAll(
() -> assertThat(applicantCard1.id()).isEqualTo(applicant1.getId()),
() -> assertThat(applicantCard1.name()).isEqualTo(applicant1.getName()),
() -> assertThat(applicantCard1.evaluationCount()).isEqualTo(2),
() -> assertThat(applicantCard1.averageScore()).isEqualTo(5.0)
() -> assertThat(applicantCard1.evaluationCount()).isEqualTo(1),
() -> assertThat(applicantCard1.averageScore()).isEqualTo(4.0)
);

ApplicantCard applicantCard2 = applicantCards.get(1);
Expand Down Expand Up @@ -140,39 +140,31 @@ void findApplicantCardsByProcesses_noEvaluations() {
@Test
void findApplicantCardsByProcess() {
// given
Process process = processRepository.save(ProcessFixture.applyType());
Process process1 = processRepository.save(ProcessFixture.applyType());
Process process2 = processRepository.save(ProcessFixture.interview(null));

Applicant applicant1 = ApplicantFixture.pendingDobby(process);
Applicant applicant2 = ApplicantFixture.pendingRush(process);
Applicant applicant1 = ApplicantFixture.pendingDobby(process1);
Applicant applicant2 = ApplicantFixture.pendingRush(process2);
applicantRepository.saveAll(List.of(applicant1, applicant2));

List<Evaluation> evaluations = List.of(
EvaluationFixture.fivePoints(process, applicant1),
EvaluationFixture.fivePoints(process, applicant1),
EvaluationFixture.fivePoints(process, applicant2)
EvaluationFixture.fourPoints(process1, applicant1),
EvaluationFixture.fivePoints(process2, applicant1),
EvaluationFixture.fivePoints(process1, applicant2)
);
evaluationRepository.saveAll(evaluations);

// when
List<ApplicantCard> applicantCards = applicantRepository.findApplicantCardsByProcess(process);
List<ApplicantCard> applicantCards = applicantRepository.findApplicantCardsByProcess(process1);

// then
assertThat(applicantCards).hasSize(2);

ApplicantCard applicantCard1 = applicantCards.get(0);
assertAll(
() -> assertThat(applicantCard1.id()).isEqualTo(applicant1.getId()),
() -> assertThat(applicantCard1.name()).isEqualTo(applicant1.getName()),
() -> assertThat(applicantCard1.evaluationCount()).isEqualTo(2),
() -> assertThat(applicantCard1.averageScore()).isEqualTo(5.0)
);

ApplicantCard applicantCard2 = applicantCards.get(1);
assertThat(applicantCards).hasSize(1);
ApplicantCard applicantCard = applicantCards.get(0);
assertAll(
() -> assertThat(applicantCard2.id()).isEqualTo(applicant2.getId()),
() -> assertThat(applicantCard2.name()).isEqualTo(applicant2.getName()),
() -> assertThat(applicantCard2.evaluationCount()).isEqualTo(1),
() -> assertThat(applicantCard2.averageScore()).isEqualTo(5.0)
() -> assertThat(applicantCard.id()).isEqualTo(applicant1.getId()),
() -> assertThat(applicantCard.name()).isEqualTo(applicant1.getName()),
() -> assertThat(applicantCard.evaluationCount()).isEqualTo(1),
() -> assertThat(applicantCard.averageScore()).isEqualTo(4.0)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ void findAllByProcess_filterAndOrder() {
Applicant applicant2 = applicantRepository.save(ApplicantFixture.pendingRush(process1));
applicantRepository.save(ApplicantFixture.pendingDobby(process2));

evaluationRepository.save(EvaluationFixture.fivePoints(process1, applicant1));
evaluationRepository.save(EvaluationFixture.fourPoints(process1, applicant2));
evaluationRepository.save(EvaluationFixture.fourPoints(process1, applicant1));
evaluationRepository.save(EvaluationFixture.fivePoints(process1, applicant2));

String evaluationStatus = "EVALUATED";
String sortByCreatedAt = "DESC";
String sortByScore = null;
String sortByCreatedAt = null;
String sortByScore = "DESC";

// when
List<ApplicantCard> applicantCards = applicantService.findApplicantCards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ void readAllByDashboardId() {
evaluationRepository.saveAll(evaluations1);

List<Evaluation> evaluations2 = List.of(
EvaluationFixture.fivePoints(process2, applicant2),
EvaluationFixture.fivePoints(process2, applicant2),
EvaluationFixture.fivePoints(process2, applicant2),
EvaluationFixture.fourPoints(process2, applicant2)
EvaluationFixture.fivePoints(process1, applicant2),
EvaluationFixture.fivePoints(process1, applicant2),
EvaluationFixture.fivePoints(process1, applicant2),
EvaluationFixture.fourPoints(process1, applicant2)
);
evaluationRepository.saveAll(evaluations2);
String sortByCreatedAt = "DESC";
String sortByScore = null;
String sortByCreatedAt = null;
String sortByScore = "DESC";

// when
ProcessResponses processResponses = processFacade.readAllByDashboardId(
Expand All @@ -114,7 +114,7 @@ void readAllByDashboardId() {
() -> assertThat(processResponses.processResponses()).hasSize(2),
() -> assertThat(processId).isEqualTo(process1.getId()),
() -> assertThat(applicantCardResponse.id()).isEqualTo(applicant2.getId()),
() -> assertThat(applicantCardResponse.evaluationCount()).isEqualTo(evaluations1.size()),
() -> assertThat(applicantCardResponse.evaluationCount()).isEqualTo(evaluations2.size()),
() -> assertThat(applicantCardResponse.averageScore()).isEqualTo(4.75)
);
}
Expand Down

0 comments on commit ddd7041

Please sign in to comment.