Unverified Commit 4d9d7894 authored by Ankit Verma's avatar Ankit Verma Committed by GitHub
Browse files

Merge pull request #178 from Radheshhathwar/development

Showing with 28 additions and 28 deletions
+28 -28
......@@ -20,9 +20,9 @@ public class ExamCenterController {
return new ResponseEntity<>(examCenterService.getVerifiedExamCentersInDistrict(district,examCycleId), HttpStatus.OK);
}
@PutMapping("/assignAlternate/{originalExamCenterId}")
public ResponseEntity<ResponseDto> assignAlternateExamCenter(@PathVariable Long originalExamCenterId, @RequestParam Long alternateInstituteId) {
return new ResponseEntity<>(examCenterService.assignAlternateExamCenter(originalExamCenterId, alternateInstituteId), HttpStatus.OK);
@PutMapping("/assignAlternate")
public ResponseEntity<ResponseDto> assignAlternateExamCenter(@RequestParam Long originalExamCenterId, @RequestParam Long alternateInstituteId, @RequestParam Long examCycleId) {
return new ResponseEntity<>(examCenterService.assignAlternateExamCenter(originalExamCenterId, alternateInstituteId, examCycleId), HttpStatus.OK);
}
@GetMapping("/examCenters")
......
......@@ -26,4 +26,5 @@ public interface ExamCenterRepository extends JpaRepository<ExamCenter, Long> {
List<ExamCenter> findByExamCycle_Id(Long examCycleId);
Optional<ExamCenter> findByExamCycleIdAndId(Long examCycleId, Long examCenterId);
List<ExamCenter> findByDistrictAndExamCycleAndApprovalStatus(String district, ExamCycle examCycleId, ApprovalStatus approvalStatus);
Optional<ExamCenter> getByIdAndExamCycle(Long unverifiedExamCenterId, ExamCycle examCycle);
}
......@@ -49,44 +49,44 @@ public class ExamCenterService {
return response;
}
@Transactional
public ResponseDto assignAlternateExamCenter(Long unverifiedExamCenterId, Long alternateExamCenterId) {
public ResponseDto assignAlternateExamCenter(Long unverifiedExamCenterId, Long alternateExamCenterId, Long examCycleId) {
ResponseDto response = new ResponseDto("API_ASSIGN_ALTERNATE_EXAM_CENTER");
ExamCycle examCycle = examCycleRepository.findById(examCycleId).orElseThrow();
try {
// Fetch the unverified exam center
ExamCenter unverifiedExamCenter = examCenterRepository.findById(unverifiedExamCenterId)
.orElseThrow(() -> new EntityNotFoundException("Unverified Exam Center not found"));
ExamCenter unverifiedExamCenter = examCenterRepository.getByIdAndExamCycle(unverifiedExamCenterId, examCycle)
.orElseThrow(() -> new EntityNotFoundException("Unverified Exam Center not found for examCycle:" + examCycle.getId()));
// Fetch the alternate exam center
ExamCenter alternateExamCenter = examCenterRepository.findById(alternateExamCenterId)
.orElseThrow(() -> new EntityNotFoundException("Alternate Exam Center not found"));
ExamCenter alternateExamCenter = examCenterRepository.getByIdAndExamCycle(alternateExamCenterId, examCycle)
.orElseThrow(() -> new EntityNotFoundException("Alternate Exam Center not found for examCycle:" + examCycle.getId()));
// Ensure both the exam centers belong to the same district
if (!unverifiedExamCenter.getDistrict().equals(alternateExamCenter.getDistrict())) {
throw new IllegalArgumentException("Unverified and Alternate Exam Centers do not belong to the same district.");
}
} else if (unverifiedExamCenter.getExamCycle().getId().equals(alternateExamCenter.getExamCycle().getId())) {
// Fetch all student registrations where the exam center is null
List<StudentExamRegistration> affectedRegistrations = studentExamRegistrationRepository.findByExamCenterIsNullAndInstitute(unverifiedExamCenter.getInstitute());
// Fetch all student registrations where the exam center is null
List<StudentExamRegistration> affectedRegistrations = studentExamRegistrationRepository.findByExamCenterIsNullAndInstitute(unverifiedExamCenter.getInstitute());
// Update the exam center for these registrations
for (StudentExamRegistration registration : affectedRegistrations) {
registration.setExamCenter(alternateExamCenter);
registration.setAlternateExamCenterAssigned(true); // This is the new change
}
// Update the exam center for these registrations
for (StudentExamRegistration registration : affectedRegistrations) {
registration.setExamCenter(alternateExamCenter);
registration.setAlternateExamCenterAssigned(true); // This is the new change
}
// Set the alternate exam center for the unverified exam center
unverifiedExamCenter.setAlternateExamCenter(alternateExamCenter);
unverifiedExamCenter.setAlternateExamCenterAssigned(true);
examCenterRepository.save(unverifiedExamCenter);
// Set the alternate exam center for the unverified exam center
unverifiedExamCenter.setAlternateExamCenter(alternateExamCenter);
unverifiedExamCenter.setAlternateExamCenterAssigned(true);
examCenterRepository.save(unverifiedExamCenter);
// Save the updated registrations
List<StudentExamRegistration> updatedRegistrations = studentExamRegistrationRepository.saveAll(affectedRegistrations);
response.put("message", "Alternate Exam Center assigned successfully.");
response.put(Constants.RESPONSE, updatedRegistrations);
response.setResponseCode(HttpStatus.OK);
// Save the updated registrations
List<StudentExamRegistration> updatedRegistrations = studentExamRegistrationRepository.saveAll(affectedRegistrations);
response.put("message", "Alternate Exam Center assigned successfully.");
response.put(Constants.RESPONSE, updatedRegistrations);
response.setResponseCode(HttpStatus.OK);
}
} catch (EntityNotFoundException e) {
ResponseDto.setErrorResponse(response, "NOT_FOUND", e.getMessage(), HttpStatus.NOT_FOUND);
} catch (IllegalArgumentException e) {
......@@ -94,7 +94,6 @@ public class ExamCenterService {
} catch (Exception e) {
ResponseDto.setErrorResponse(response, "GENERAL_ERROR", "An unexpected error occurred: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return response;
}
......
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