Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,28 @@ WHERE a.job IN (
"""
)
List<Object[]> countApplicationsByJobAndStateForInterviewProcesses(@Param("professorId") UUID professorId);

/**
* Counts applications grouped by job and state for jobs with interview
* processes
* that are accessible to the user (professor or research group member).
*
* @param userId the ID of the user
* @return List of Object arrays containing [Job, ApplicationState, Count]
*/
@Query(
"""
SELECT a.job, a.state, COUNT(a)
FROM Application a
WHERE EXISTS (
SELECT 1 FROM InterviewProcess ip
JOIN ip.job j
JOIN j.researchGroup rg
JOIN rg.userRoles ur
WHERE ip.job = a.job AND ur.user.userId = :userId
)
GROUP BY a.job, a.state
"""
)
List<Object[]> countApplicationsByJobAndStateForUserAccess(@Param("userId") UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ public interface InterviewProcessRepository extends JpaRepository<InterviewProce
)
List<InterviewProcess> findAllByProfessorId(@Param("professorId") UUID professorId);

/**
* Find all InterviewProcesses for jobs where the user is a member of the
* research group.
* This covers both the supervising professor and other employees in the group.
*
* @param userId the ID of the user
* @return list of InterviewProcesses accessible to the user
*/
@Query(
"""
SELECT ip
FROM InterviewProcess ip
JOIN ip.job j
JOIN j.researchGroup rg
JOIN rg.userRoles ur
WHERE ur.user.userId = :userId
"""
)
List<InterviewProcess> findAllByUserAccess(@Param("userId") UUID userId);

/**
* Finds an interview process by the associated job identifier.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ public class InterviewService {
*/

public List<InterviewOverviewDTO> getInterviewOverview() {
// 1. Get the ID of the currently logged-in professor
UUID professorId = currentUserService.getUserId();
// 1. Get the ID of the currently logged-in user
UUID currentUserId = currentUserService.getUserId();

// 2. Load all active interview processes for this professor
List<InterviewProcess> interviewProcesses = interviewProcessRepository.findAllByProfessorId(professorId);
// 2. Load all active interview processes accessible to this user
List<InterviewProcess> interviewProcesses = interviewProcessRepository.findAllByUserAccess(currentUserId);

// 2. If no interview processes exist, return an empty list
if (interviewProcesses.isEmpty()) {
return Collections.emptyList();
}

// 4. Fetch aggregated data: count of applications per job and ApplicationState
List<Object[]> countResults = applicationRepository.countApplicationsByJobAndStateForInterviewProcesses(professorId);
List<Object[]> countResults = applicationRepository.countApplicationsByJobAndStateForUserAccess(currentUserId);

// 5.Build a map structure with jobId as key
// The inner map contains the count of applications per ApplicationState
Expand Down Expand Up @@ -155,7 +155,7 @@ public InterviewOverviewDTO getInterviewProcessDetails(UUID processId) {
// 3. Fetch aggregated data for this specific job
UUID jobId = interviewProcess.getJob().getJobId();
UUID currentUserId = currentUserService.getUserId();
List<Object[]> countResults = applicationRepository.countApplicationsByJobAndStateForInterviewProcesses(currentUserId);
List<Object[]> countResults = applicationRepository.countApplicationsByJobAndStateForUserAccess(currentUserId);

// Filter for this specific job
Map<ApplicationState, Long> stateCounts = new EnumMap<>(ApplicationState.class);
Expand Down
Loading
Loading