Commit 04ea2826 authored by jay pratap singh's avatar jay pratap singh
Browse files

fixed dispatch proof errors

Showing with 24 additions and 26 deletions
+24 -26
......@@ -219,52 +219,50 @@ public class DispatchTrackerService {
return response;
}
public ResponseDto getDispatchStatusForAllInstitutes(Long examCycleId, Long examId) {
ResponseDto response = new ResponseDto(Constants.API_DISPATCH_STATUS_FOR_ALL_INSTITUTES);
List<ExamCenter> allInstitutes = examCenterRepository.findByExamCycle_Id(examCycleId);
List<DispatchTracker> uploadedProofsForExam = dispatchTrackerRepository.findByExamIdAndExamCycleId(examId, examCycleId);
Exam exam = examRepository.findById(examId).orElse(null); // Fetch the exam details
Exam exam = examRepository.findById(examId).orElse(null);
if (exam == null) {
return ResponseDto.setErrorResponse(response, "EXAM_NOT_FOUND", "Exam not found.", HttpStatus.NOT_FOUND);
}
// Creating a map of Institute ID to DispatchTracker for quick lookup
Map<Long, DispatchTracker> dispatchTrackerMap = uploadedProofsForExam.stream()
.collect(Collectors.toMap(dispatch -> dispatch.getExamCenter().getId(), Function.identity()));
List<InstituteDispatchStatusDto> result = new ArrayList<>();
for (ExamCenter institute : allInstitutes) {
InstituteDispatchStatusDto statusDto = new InstituteDispatchStatusDto();
statusDto.setInstituteId(institute.getId());
statusDto.setInstituteName(institute.getName());
statusDto.setExamName(exam != null ? exam.getExamName() : null);
DispatchTracker matchedDispatch = dispatchTrackerMap.get(institute.getId());
if (matchedDispatch != null) {
statusDto.setProofUploaded(true);
statusDto.setUpdatedDate(matchedDispatch.getDispatchDate());
statusDto.setDispatchProofFileLocation(generateSignedUrl(matchedDispatch.getDispatchProofFileLocation()));
} else {
statusDto.setProofUploaded(false);
// Here you can set default values or placeholders for other fields if needed
}
result.add(statusDto);
}
List<InstituteDispatchStatusDto> result = allInstitutes.stream()
.map(institute -> {
DispatchTracker dispatchTracker = dispatchTrackerMap.get(institute.getId());
InstituteDispatchStatusDto statusDto = new InstituteDispatchStatusDto();
statusDto.setInstituteId(institute.getId());
statusDto.setInstituteName(institute.getName());
statusDto.setExamName(exam.getExamName());
if (dispatchTracker != null) {
statusDto.setProofUploaded(true);
statusDto.setUpdatedDate(dispatchTracker.getDispatchDate());
statusDto.setDispatchProofFileLocation(generateSignedUrl(dispatchTracker.getDispatchProofFileLocation()));
} else {
statusDto.setProofUploaded(false);
// Set default values or placeholders for other fields if needed
}
return statusDto;
})
.collect(Collectors.toList());
if (!result.isEmpty()) {
response.put(Constants.MESSAGE, Constants.SUCCESSMESSAGE);
response.put(Constants.RESPONSE, result);
response.setResponseCode(HttpStatus.OK);
} else {
ResponseDto.setErrorResponse(response, "NO_DATA_FOUND", "No dispatch data found for the given exam and exam cycle across all institutes.", HttpStatus.NOT_FOUND);
ResponseDto.setErrorResponse(response, "NO_DATA_FOUND", "No institutes found for the given exam cycle.", HttpStatus.NOT_FOUND);
}
return response;
}
private String generateSignedUrl(String blobName) {
try {
// Define resource
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment