diff --git a/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCenterController.java b/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCenterController.java index 22402e1320966c62718be20a77915f243de3cd53..8075327c82e9d383d1025608239535f4fe95682b 100644 --- a/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCenterController.java +++ b/src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/ExamCenterController.java @@ -1,18 +1,13 @@ package com.tarento.upsmf.examsAndAdmissions.controller; -import com.tarento.upsmf.examsAndAdmissions.model.ExamCenter; import com.tarento.upsmf.examsAndAdmissions.model.ResponseDto; import com.tarento.upsmf.examsAndAdmissions.model.dto.CCTVStatusUpdateDTO; -import com.tarento.upsmf.examsAndAdmissions.model.dto.ExamCenterDTO; import com.tarento.upsmf.examsAndAdmissions.service.ExamCenterService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.stream.Collectors; - @RestController @RequestMapping("/api/v1/admin") public class ExamCenterController { @@ -21,8 +16,8 @@ public class ExamCenterController { private ExamCenterService examCenterService; @GetMapping("/verifiedExamCenters") - public ResponseEntity<ResponseDto> getVerifiedExamCenters(@RequestParam String district) { - return new ResponseEntity<>(examCenterService.getVerifiedExamCentersInDistrict(district), HttpStatus.OK); + public ResponseEntity<ResponseDto> getVerifiedExamCenters(@RequestParam String district,@RequestParam Long examCycleId) { + return new ResponseEntity<>(examCenterService.getVerifiedExamCentersInDistrict(district,examCycleId), HttpStatus.OK); } @PutMapping("/assignAlternate/{originalExamCenterId}") @@ -35,9 +30,9 @@ public class ExamCenterController { return new ResponseEntity<>(examCenterService.getExamCentersByStatus(examCycleId, isVerifiedStatus), HttpStatus.OK); } - @PutMapping("/updateCctvStatus/{examCenterId}") - public ResponseEntity<ResponseDto> updateCCTVStatus(@PathVariable Long examCenterId, @RequestBody CCTVStatusUpdateDTO updateDTO) { - return new ResponseEntity<>(examCenterService.updateCCTVStatus(examCenterId, updateDTO), HttpStatus.OK); + @PutMapping("/updateCctvStatus") + public ResponseEntity<ResponseDto> updateCCTVStatus(@RequestParam Long examCenterId, @RequestBody CCTVStatusUpdateDTO updateDTO,@RequestParam Long examCycleId) { + return new ResponseEntity<>(examCenterService.updateCCTVStatus(examCenterId, updateDTO,examCycleId), HttpStatus.OK); } @GetMapping("/examCenters/all") @@ -49,8 +44,8 @@ public class ExamCenterController { return new ResponseEntity<>(examCenterService.getExamCentersByExamCycle(examCycleId), HttpStatus.OK); } @GetMapping("/examCenter/verified") - public ResponseDto getVerifiedCenter(@RequestParam String instituteCode) { - return examCenterService.getVerifiedCenterByInstituteCode(instituteCode); + public ResponseDto getVerifiedCenter(@RequestParam String instituteCode, @RequestParam Long examCycleId) { + return examCenterService.getVerifiedCenterByInstituteCode(instituteCode,examCycleId); } @GetMapping("/examCenterStatus") public ResponseEntity<ResponseDto> getExamCenterStatus(@RequestParam Long examCycleId, @RequestParam Long examCenterId) { diff --git a/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ExamCenterRepository.java b/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ExamCenterRepository.java index 9de1071ac5c3cccb05ee9a59cd2d9d58b8611964..5371dd84441963157e9dd058592dcf5e7293f081 100644 --- a/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ExamCenterRepository.java +++ b/src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ExamCenterRepository.java @@ -22,6 +22,8 @@ public interface ExamCenterRepository extends JpaRepository<ExamCenter, Long> { Optional<ExamCenter> findByInstituteCodeAndApprovalStatus(String instituteCode, ApprovalStatus approvalStatus); + ExamCenter getByInstituteCodeAndExamCycleIdAndApprovalStatus(String instituteCode,Long ExamCycleId, ApprovalStatus approvalStatus); List<ExamCenter> findByExamCycle_Id(Long examCycleId); Optional<ExamCenter> findByExamCycleIdAndId(Long examCycleId, Long examCenterId); + List<ExamCenter> findByDistrictAndExamCycleAndApprovalStatus(String district, ExamCycle examCycleId, ApprovalStatus approvalStatus); } diff --git a/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCenterService.java b/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCenterService.java index beb2fa81e542738cd1703725e54bb1e1fd3b0756..73c14f8d172ea1039dff2351d2164262a6a8891f 100644 --- a/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCenterService.java +++ b/src/main/java/com/tarento/upsmf/examsAndAdmissions/service/ExamCenterService.java @@ -33,9 +33,11 @@ public class ExamCenterService { @Autowired private ExamCenterMapper examCenterMapper; - public ResponseDto getVerifiedExamCentersInDistrict(String district) { + public ResponseDto getVerifiedExamCentersInDistrict(String district,Long examCycleId) { ResponseDto response = new ResponseDto(Constants.API_GET_VERIFIED_EXAM_CENTERS); - List<ExamCenter> examCenters = examCenterRepository.findByDistrictAndApprovalStatus(district, ApprovalStatus.APPROVED); + ExamCycle examCycle = examCycleRepository.findById(examCycleId).orElseThrow(); + List<ExamCenter> examCenters = examCenterRepository.findByDistrictAndExamCycleAndApprovalStatus(district,examCycle, ApprovalStatus.APPROVED); + System.out.println("Print size in console"+examCenters.size()); if (!examCenters.isEmpty()) { List<ExamCenterDTO> examCenterDTOs = examCenterMapper.toDTOs(examCenters); response.put(Constants.MESSAGE, "Successful."); @@ -96,14 +98,15 @@ public class ExamCenterService { return response; } - public ResponseDto updateCCTVStatus(Long examCenterId, CCTVStatusUpdateDTO updateDTO) { + public ResponseDto updateCCTVStatus(Long examCenterId, CCTVStatusUpdateDTO updateDTO,Long examCycleId) { ResponseDto response = new ResponseDto(Constants.API_UPDATE_CCTV_STATUS); ExamCenter center = examCenterRepository.findById(examCenterId).orElse(null); if (center == null) { ResponseDto.setErrorResponse(response, "CENTER_NOT_FOUND", "Exam center not found.", HttpStatus.NOT_FOUND); return response; } - + ExamCycle examCycle = examCycleRepository.findById(examCycleId).orElseThrow(); + center.setExamCycle(examCycle); center.setIpAddress(updateDTO.getIpAddress()); center.setRemarks(updateDTO.getRemarks()); center.setApprovalStatus(updateDTO.getApprovalStatus()); @@ -179,18 +182,18 @@ public class ExamCenterService { } return response; } - public ResponseDto getVerifiedCenterByInstituteCode(String instituteCode) { + public ResponseDto getVerifiedCenterByInstituteCode(String instituteCode,Long examCycleId) { ResponseDto response = new ResponseDto(Constants.API_GET_VERIFIED_EXAM_CENTER); - Optional<ExamCenter> examCenterOpt = examCenterRepository.findByInstituteCodeAndApprovalStatus(instituteCode, ApprovalStatus.APPROVED); + ExamCenter examCenterOpt = examCenterRepository.getByInstituteCodeAndExamCycleIdAndApprovalStatus(instituteCode,examCycleId, ApprovalStatus.APPROVED); - if (examCenterOpt.isPresent()) { - ExamCenterDTO examCenterDTO = examCenterMapper.toDTO(examCenterOpt.get()); + if (examCenterOpt != null) { + ExamCenterDTO examCenterDTO = examCenterMapper.toDTO(examCenterOpt); response.put(Constants.MESSAGE, "Successful."); response.put(Constants.RESPONSE, examCenterDTO); response.setResponseCode(HttpStatus.OK); } else { - ResponseDto.setErrorResponse(response, "NO_VERIFIED_CENTER_FOUND", "No verified exam center found for the provided institute code.", HttpStatus.NOT_FOUND); + ResponseDto.setErrorResponse(response, "NO_VERIFIED_CENTER_FOUND", "No verified exam center found for the provided institute code and examCycle.", HttpStatus.NOT_FOUND); } return response; diff --git a/src/main/java/com/tarento/upsmf/examsAndAdmissions/util/RedisUtil.java b/src/main/java/com/tarento/upsmf/examsAndAdmissions/util/RedisUtil.java index 77441eb8eea645984b7636371ee1e55cb6450539..46d69831c356acf51a6933f9f11640e7857c3c3f 100644 --- a/src/main/java/com/tarento/upsmf/examsAndAdmissions/util/RedisUtil.java +++ b/src/main/java/com/tarento/upsmf/examsAndAdmissions/util/RedisUtil.java @@ -46,7 +46,7 @@ public class RedisUtil { throw new RuntimeException("Invalid Request"); } // check in redis - boolean keyExists = hashOperations.getOperations().hasKey(id); + boolean keyExists = Boolean.TRUE.equals(hashOperations.getOperations().hasKey(id)); if(keyExists) { return hashOperations.get(userRedisHashKey, id); }