Commit 37c5a892 authored by Radheshhathwar's avatar Radheshhathwar
Browse files

updateCctvStatus

examCenter/verified
verifiedExamCenters
Showing with 22 additions and 22 deletions
+22 -22
package com.tarento.upsmf.examsAndAdmissions.controller; 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.ResponseDto;
import com.tarento.upsmf.examsAndAdmissions.model.dto.CCTVStatusUpdateDTO; import com.tarento.upsmf.examsAndAdmissions.model.dto.CCTVStatusUpdateDTO;
import com.tarento.upsmf.examsAndAdmissions.model.dto.ExamCenterDTO;
import com.tarento.upsmf.examsAndAdmissions.service.ExamCenterService; import com.tarento.upsmf.examsAndAdmissions.service.ExamCenterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/api/v1/admin") @RequestMapping("/api/v1/admin")
public class ExamCenterController { public class ExamCenterController {
...@@ -21,8 +16,8 @@ public class ExamCenterController { ...@@ -21,8 +16,8 @@ public class ExamCenterController {
private ExamCenterService examCenterService; private ExamCenterService examCenterService;
@GetMapping("/verifiedExamCenters") @GetMapping("/verifiedExamCenters")
public ResponseEntity<ResponseDto> getVerifiedExamCenters(@RequestParam String district) { public ResponseEntity<ResponseDto> getVerifiedExamCenters(@RequestParam String district,@RequestParam Long examCycleId) {
return new ResponseEntity<>(examCenterService.getVerifiedExamCentersInDistrict(district), HttpStatus.OK); return new ResponseEntity<>(examCenterService.getVerifiedExamCentersInDistrict(district,examCycleId), HttpStatus.OK);
} }
@PutMapping("/assignAlternate/{originalExamCenterId}") @PutMapping("/assignAlternate/{originalExamCenterId}")
...@@ -35,9 +30,9 @@ public class ExamCenterController { ...@@ -35,9 +30,9 @@ public class ExamCenterController {
return new ResponseEntity<>(examCenterService.getExamCentersByStatus(examCycleId, isVerifiedStatus), HttpStatus.OK); return new ResponseEntity<>(examCenterService.getExamCentersByStatus(examCycleId, isVerifiedStatus), HttpStatus.OK);
} }
@PutMapping("/updateCctvStatus/{examCenterId}") @PutMapping("/updateCctvStatus")
public ResponseEntity<ResponseDto> updateCCTVStatus(@PathVariable Long examCenterId, @RequestBody CCTVStatusUpdateDTO updateDTO) { public ResponseEntity<ResponseDto> updateCCTVStatus(@RequestParam Long examCenterId, @RequestBody CCTVStatusUpdateDTO updateDTO,@RequestParam Long examCycleId) {
return new ResponseEntity<>(examCenterService.updateCCTVStatus(examCenterId, updateDTO), HttpStatus.OK); return new ResponseEntity<>(examCenterService.updateCCTVStatus(examCenterId, updateDTO,examCycleId), HttpStatus.OK);
} }
@GetMapping("/examCenters/all") @GetMapping("/examCenters/all")
...@@ -49,8 +44,8 @@ public class ExamCenterController { ...@@ -49,8 +44,8 @@ public class ExamCenterController {
return new ResponseEntity<>(examCenterService.getExamCentersByExamCycle(examCycleId), HttpStatus.OK); return new ResponseEntity<>(examCenterService.getExamCentersByExamCycle(examCycleId), HttpStatus.OK);
} }
@GetMapping("/examCenter/verified") @GetMapping("/examCenter/verified")
public ResponseDto getVerifiedCenter(@RequestParam String instituteCode) { public ResponseDto getVerifiedCenter(@RequestParam String instituteCode, @RequestParam Long examCycleId) {
return examCenterService.getVerifiedCenterByInstituteCode(instituteCode); return examCenterService.getVerifiedCenterByInstituteCode(instituteCode,examCycleId);
} }
@GetMapping("/examCenterStatus") @GetMapping("/examCenterStatus")
public ResponseEntity<ResponseDto> getExamCenterStatus(@RequestParam Long examCycleId, @RequestParam Long examCenterId) { public ResponseEntity<ResponseDto> getExamCenterStatus(@RequestParam Long examCycleId, @RequestParam Long examCenterId) {
......
...@@ -22,6 +22,8 @@ public interface ExamCenterRepository extends JpaRepository<ExamCenter, Long> { ...@@ -22,6 +22,8 @@ public interface ExamCenterRepository extends JpaRepository<ExamCenter, Long> {
Optional<ExamCenter> findByInstituteCodeAndApprovalStatus(String instituteCode, ApprovalStatus approvalStatus); Optional<ExamCenter> findByInstituteCodeAndApprovalStatus(String instituteCode, ApprovalStatus approvalStatus);
ExamCenter getByInstituteCodeAndExamCycleIdAndApprovalStatus(String instituteCode,Long ExamCycleId, ApprovalStatus approvalStatus);
List<ExamCenter> findByExamCycle_Id(Long examCycleId); List<ExamCenter> findByExamCycle_Id(Long examCycleId);
Optional<ExamCenter> findByExamCycleIdAndId(Long examCycleId, Long examCenterId); Optional<ExamCenter> findByExamCycleIdAndId(Long examCycleId, Long examCenterId);
List<ExamCenter> findByDistrictAndExamCycleAndApprovalStatus(String district, ExamCycle examCycleId, ApprovalStatus approvalStatus);
} }
...@@ -33,9 +33,11 @@ public class ExamCenterService { ...@@ -33,9 +33,11 @@ public class ExamCenterService {
@Autowired @Autowired
private ExamCenterMapper examCenterMapper; 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); 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()) { if (!examCenters.isEmpty()) {
List<ExamCenterDTO> examCenterDTOs = examCenterMapper.toDTOs(examCenters); List<ExamCenterDTO> examCenterDTOs = examCenterMapper.toDTOs(examCenters);
response.put(Constants.MESSAGE, "Successful."); response.put(Constants.MESSAGE, "Successful.");
...@@ -96,14 +98,15 @@ public class ExamCenterService { ...@@ -96,14 +98,15 @@ public class ExamCenterService {
return response; 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); ResponseDto response = new ResponseDto(Constants.API_UPDATE_CCTV_STATUS);
ExamCenter center = examCenterRepository.findById(examCenterId).orElse(null); ExamCenter center = examCenterRepository.findById(examCenterId).orElse(null);
if (center == null) { if (center == null) {
ResponseDto.setErrorResponse(response, "CENTER_NOT_FOUND", "Exam center not found.", HttpStatus.NOT_FOUND); ResponseDto.setErrorResponse(response, "CENTER_NOT_FOUND", "Exam center not found.", HttpStatus.NOT_FOUND);
return response; return response;
} }
ExamCycle examCycle = examCycleRepository.findById(examCycleId).orElseThrow();
center.setExamCycle(examCycle);
center.setIpAddress(updateDTO.getIpAddress()); center.setIpAddress(updateDTO.getIpAddress());
center.setRemarks(updateDTO.getRemarks()); center.setRemarks(updateDTO.getRemarks());
center.setApprovalStatus(updateDTO.getApprovalStatus()); center.setApprovalStatus(updateDTO.getApprovalStatus());
...@@ -179,18 +182,18 @@ public class ExamCenterService { ...@@ -179,18 +182,18 @@ public class ExamCenterService {
} }
return response; return response;
} }
public ResponseDto getVerifiedCenterByInstituteCode(String instituteCode) { public ResponseDto getVerifiedCenterByInstituteCode(String instituteCode,Long examCycleId) {
ResponseDto response = new ResponseDto(Constants.API_GET_VERIFIED_EXAM_CENTER); 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()) { if (examCenterOpt != null) {
ExamCenterDTO examCenterDTO = examCenterMapper.toDTO(examCenterOpt.get()); ExamCenterDTO examCenterDTO = examCenterMapper.toDTO(examCenterOpt);
response.put(Constants.MESSAGE, "Successful."); response.put(Constants.MESSAGE, "Successful.");
response.put(Constants.RESPONSE, examCenterDTO); response.put(Constants.RESPONSE, examCenterDTO);
response.setResponseCode(HttpStatus.OK); response.setResponseCode(HttpStatus.OK);
} else { } 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; return response;
......
...@@ -46,7 +46,7 @@ public class RedisUtil { ...@@ -46,7 +46,7 @@ public class RedisUtil {
throw new RuntimeException("Invalid Request"); throw new RuntimeException("Invalid Request");
} }
// check in redis // check in redis
boolean keyExists = hashOperations.getOperations().hasKey(id); boolean keyExists = Boolean.TRUE.equals(hashOperations.getOperations().hasKey(id));
if(keyExists) { if(keyExists) {
return hashOperations.get(userRedisHashKey, id); return hashOperations.get(userRedisHashKey, id);
} }
......
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