Commit 2b7355ab authored by Radheshhathwar's avatar Radheshhathwar
Browse files

Changes for examCyclesByCouses

Showing with 14 additions and 11 deletions
+14 -11
......@@ -50,7 +50,10 @@ public interface StudentResultRepository extends JpaRepository<StudentResult, Lo
Optional<StudentResult> findByExamId(Long id);
List<StudentResult> findByExamIdAndInstituteId(Long id, Long instituteId);
@Query("SELECT sr FROM StudentResult sr WHERE sr.exam_name = :examName AND sr.instituteId = :instituteId")
List<StudentResult> findByExamNameAndInstituteId(@Param("examName") String examName, @Param("instituteId") Long instituteId);
List<StudentResult> findByExamExamNameAndInstituteId(String examName, Long instituteId);
List<StudentResult> findByStudent_EnrollmentNumberAndExamCycle_IdAndPublished(String enrollmentNumber, Long examCycleId, boolean b);
}
......
......@@ -367,24 +367,24 @@ public class ExamCycleService {
List<ExamCycleDTO> examCycleDTOs = Collections.EMPTY_LIST;
StringBuilder stringBuilder = new StringBuilder("select * from exam_cycle where date_part('year', start_date) = '")
.append(searchExamCycleDTO.getStartYear()).append("' and obsolete = 0 ");
try{
if(searchExamCycleDTO.getCourseId() != null && !searchExamCycleDTO.getCourseId().isBlank()) {
try {
if (searchExamCycleDTO.getCourseId() != null && !searchExamCycleDTO.getCourseId().isBlank()) {
stringBuilder.append(" and course_id = '").append(searchExamCycleDTO.getCourseId()).append("' ");
}
if(searchExamCycleDTO.getEndYear() != null && searchExamCycleDTO.getEndYear() > 0) {
if (searchExamCycleDTO.getEndYear() != null && searchExamCycleDTO.getEndYear() > 0) {
stringBuilder.append("and date_part('year', end_date) <= '").append(searchExamCycleDTO.getEndYear()).append("' ");
}
List<ExamCycle> examCycles = jdbcTemplate.query(stringBuilder.toString(), new ResultSetExtractor<List<ExamCycle>>() {
@Override
public List<ExamCycle> extractData(ResultSet rs) throws SQLException, DataAccessException {
List<ExamCycle> examCycleList = new ArrayList<>();
while(rs.next()) {
while (rs.next()) {
examCycleList.add(ExamCycle.builder().examCycleName(rs.getString("exam_cycle_name")).id(rs.getLong("id")).build());
}
return examCycleList;
}
});
if(examCycles != null && !examCycles.isEmpty()) {
if (examCycles != null && !examCycles.isEmpty()) {
examCycleDTOs = examCycles.stream().map(record -> toDTO(record)).collect(Collectors.toList());
}
response.put(Constants.MESSAGE, Constants.SUCCESS);
......@@ -399,10 +399,10 @@ public class ExamCycleService {
}
private void validateSearchExamCyclePayload(SearchExamCycleDTO searchExamCycleDTO) {
if(searchExamCycleDTO == null) {
if (searchExamCycleDTO == null) {
throw new InvalidRequestException(Constants.INVALID_REQUEST_ERROR_MESSAGE);
}
if(searchExamCycleDTO.getStartYear() == null || searchExamCycleDTO.getStartYear() <= 0) {
if (searchExamCycleDTO.getStartYear() == null || searchExamCycleDTO.getStartYear() <= 0) {
throw new InvalidRequestException(Constants.MISSING_SEARCH_PARAM_START_ACADEMIC_YEAR);
}
}
......
......@@ -786,7 +786,7 @@ public class StudentResultService {
dto.setLastDateToUploadInternalMarks(exam.getLastDateToUploadMarks());
// Now check for student results for this exam and institute
List<StudentResult> resultsForExam = studentResultRepository.findByExamIdAndInstituteId(exam.getId(), instituteId);
List<StudentResult> resultsForExam = studentResultRepository.findByExamNameAndInstituteId(exam.getExamName(), instituteId);
if (!resultsForExam.isEmpty()) {
// If we find any student result records, it means internal marks have been uploaded
......@@ -804,12 +804,12 @@ public class StudentResultService {
response.put(Constants.RESPONSE, dtos);
response.setResponseCode(HttpStatus.OK);
} else {
ResponseDto.setErrorResponse(response, "NO_EXAMS_FOUND", "No exams found for the provided exam cycle.", HttpStatus.NOT_FOUND);
return ResponseDto.setErrorResponse(response, "NO_EXAMS_FOUND", "No exams found for the provided exam cycle.", HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
// Handle any unexpected errors that might occur during the process.
ResponseDto.setErrorResponse(response, "INTERNAL_SERVER_ERROR", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseDto.setErrorResponse(response, "INTERNAL_SERVER_ERROR", 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