-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat-be: Process 관련 API 쿼리 최적화 #711
Changes from 9 commits
945b0bb
d45354d
82ccb18
6760cf7
74b03f8
c74e15d
58387ed
28edda3
acad359
b4ba234
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.cruru.applicant.domain.dto; | ||
|
||
import com.cruru.applicant.controller.response.ApplicantCardResponse; | ||
import java.time.LocalDateTime; | ||
|
||
public record ApplicantCard( | ||
long id, | ||
|
||
String name, | ||
|
||
LocalDateTime createdAt, | ||
|
||
Boolean isRejected, | ||
|
||
long evaluationCount, | ||
|
||
double averageScore, | ||
|
||
long processId | ||
) { | ||
|
||
public ApplicantCardResponse toResponse() { | ||
return new ApplicantCardResponse(id, name, createdAt, isRejected, (int) evaluationCount, averageScore); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
package com.cruru.applicant.domain.repository; | ||
|
||
import com.cruru.applicant.domain.Applicant; | ||
import com.cruru.applicant.domain.dto.ApplicantCard; | ||
import com.cruru.process.domain.Process; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ApplicantRepository extends JpaRepository<Applicant, Long> { | ||
|
||
List<Applicant> findAllByProcess(Process process); | ||
|
||
long countByProcess(Process process); | ||
|
||
Optional<Applicant> findByEmail(String email); | ||
@Query(""" | ||
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 | ||
WHERE a.process IN :processes | ||
GROUP BY a.id, a.name, a.createdDate, a.isRejected, a.process.id | ||
""") | ||
List<ApplicantCard> findApplicantCardsByProcesses(@Param("processes") List<Process> processes); | ||
|
||
@Query(""" | ||
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 | ||
WHERE a.process = :process | ||
GROUP BY a.id, a.name, a.createdDate, a.isRejected | ||
""") | ||
List<ApplicantCard> findApplicantCardsByProcess(@Param("process") Process process); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -64,6 +64,10 @@ private Process toEvaluateProcess(ProcessCreateRequest request, Dashboard dashbo | |||||
return new Process(request.sequence(), request.name(), request.description(), ProcessType.EVALUATE, dashboard); | ||||||
} | ||||||
|
||||||
public List<Process> findAllByDashboard(Long dashboardId) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다형성을 활용하기 위해 메서드명을 같게 했습니다. System.out.printlnString() 안하는 것처럼요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아뇨. ㅎ ㅎ 놓치신 줄 알았습니다. |
||||||
return processRepository.findAllByDashboardId(dashboardId); | ||||||
} | ||||||
|
||||||
public Process findApplyProcessOnDashboard(Dashboard dashboard) { | ||||||
List<Process> processes = findAllByDashboard(dashboard); | ||||||
return processes.stream() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 response 변환 로직은 facade나 service에 있는데,
이 변환 로직은 여기에 두신 이유가 궁금합니다(단순 궁금).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전까지는 facade, service 계층에 dto가 없어서요...? 그리고 controller 패키지에서 도메인을 참조해서요.