Unverified Commit 3b50a9b0 authored by Ankit Verma's avatar Ankit Verma Committed by GitHub
Browse files

Merge pull request #41 from jaypratapsingh1/feature/exam_results_dev

added code to get course name along with other detail
Showing with 71 additions and 9 deletions
+71 -9
package com.tarento.upsmf.examsAndAdmissions.controller;
import com.tarento.upsmf.examsAndAdmissions.model.Course;
import com.tarento.upsmf.examsAndAdmissions.model.Exam;
import com.tarento.upsmf.examsAndAdmissions.model.ExamCycle;
import com.tarento.upsmf.examsAndAdmissions.model.ExamUploadData;
import com.tarento.upsmf.examsAndAdmissions.repository.CourseRepository;
import com.tarento.upsmf.examsAndAdmissions.repository.ExamEntityRepository;
import com.tarento.upsmf.examsAndAdmissions.service.DataImporterService;
import com.tarento.upsmf.examsAndAdmissions.service.ExamCycleService;
......@@ -30,7 +32,8 @@ public class ExamCycleController {
private DataImporterService dataImporterService;
@Autowired
ExamEntityRepository repository;
@Autowired
private CourseRepository courseRepository;
@PostMapping("/create")
public ResponseEntity<?> createExamCycle(@RequestBody ExamCycle examCycle, @RequestAttribute(Constants.Parameters.USER_ID) String userId) {
......@@ -44,7 +47,7 @@ public class ExamCycleController {
@GetMapping("/list")
public ResponseEntity<?> getAllExamCycles() {
try {
List<ExamCycle> examCycles = service.getAllExamCycles();
List<ExamCycleDTO> examCycles = service.getAllExamCycles();
if (examCycles.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
......@@ -139,6 +142,9 @@ public class ExamCycleController {
@PostMapping("/createExamCycleWithExams")
public ResponseEntity<?> createExamCycleWithExams(@RequestBody ExamCycleWithExamsDTO examCycleWithExamsDTO, @RequestAttribute(Constants.Parameters.USER_ID) String userId) {
try {
Course course = courseRepository.findById(examCycleWithExamsDTO.getExamCycle().getCourse().getId())
.orElseThrow(() -> new RuntimeException("Course not found"));
// Create the ExamCycle
ExamCycle createdExamCycle = service.createExamCycle(examCycleWithExamsDTO.getExamCycle(), userId);
......
package com.tarento.upsmf.examsAndAdmissions.model.dto;
import com.tarento.upsmf.examsAndAdmissions.enums.ExamCycleStatus;
import lombok.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
public class ExamCycleDTO {
private Long id;
private String examCycleName;
// Fields related to Course
private Long courseId;
private String courseCode;
private String courseName;
private LocalDate startDate;
private LocalDate endDate;
private String createdBy;
private LocalDateTime createdOn;
private String modifiedBy;
private LocalDateTime modifiedOn;
private ExamCycleStatus status;
private Integer obsolete;
}
......@@ -12,6 +12,9 @@ import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import com.tarento.upsmf.examsAndAdmissions.model.dto.ExamCycleDTO;
@Service
@Slf4j
......@@ -61,15 +64,12 @@ public class ExamCycleService {
}
// Fetch all active exam cycles
public List<ExamCycle> getAllExamCycles() {
public List<ExamCycleDTO> getAllExamCycles() {
log.info("Fetching all active ExamCycles...");
List<ExamCycle> examCycles = repository.findByObsolete(0);
for(ExamCycle examCycle : examCycles) {
if (examCycle.getCourse() != null) {
examCycle.getCourse().getCourseName(); // This will force initialization if it's LAZY
}
}
return examCycles;
return examCycles.stream()
.map(this::toDTO)
.collect(Collectors.toList());
}
// Fetch all soft-deleted exam cycles
......@@ -182,5 +182,29 @@ public class ExamCycleService {
examCycle.setStatus(ExamCycleStatus.PUBLISHED);
return repository.save(examCycle);
}
public ExamCycleDTO toDTO(ExamCycle examCycle) {
ExamCycleDTO dto = new ExamCycleDTO();
dto.setId(examCycle.getId());
dto.setExamCycleName(examCycle.getExamCycleName());
// Set Course related fields
if (examCycle.getCourse() != null) {
dto.setCourseId(examCycle.getCourse().getId());
dto.setCourseCode(examCycle.getCourse().getCourseCode());
dto.setCourseName(examCycle.getCourse().getCourseName()); // Assuming your Course entity has a getCourseName() method
}
dto.setStartDate(examCycle.getStartDate());
dto.setEndDate(examCycle.getEndDate());
dto.setCreatedBy(examCycle.getCreatedBy());
dto.setCreatedOn(examCycle.getCreatedOn());
dto.setModifiedBy(examCycle.getModifiedBy());
dto.setModifiedOn(examCycle.getModifiedOn());
dto.setStatus(examCycle.getStatus());
dto.setObsolete(examCycle.getObsolete());
return dto;
}
}
\ No newline at end of file
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