Unverified Commit 87b53745 authored by Shishir Suman's avatar Shishir Suman Committed by GitHub
Browse files

Merge pull request #8 from jaypratapsingh1/main

adding code for pending verifications of enrolments
No related merge requests found
Showing with 124 additions and 42 deletions
+124 -42
package com.tarento.upsmf.examsAndAdmissions;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class DateTimeFormatConfiguration implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}
}
......@@ -4,6 +4,7 @@ import com.tarento.upsmf.examsAndAdmissions.model.Student;
import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus;
import com.tarento.upsmf.examsAndAdmissions.model.dto.StudentDto;
import com.tarento.upsmf.examsAndAdmissions.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -11,13 +12,14 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
@Autowired
private StudentService studentService;
......@@ -56,7 +58,27 @@ public class StudentController {
return ResponseEntity.badRequest().build();
}
}
@PutMapping("/closePendingFor14Days")
public ResponseEntity<?> updateStudentStatusToClosed() {
try {
List<Student> updatedStudents = studentService.updateStudentStatusToClosed();
return ResponseEntity.ok(updatedStudents);
} catch (Exception e) {
log.error("Error updating student status based on days", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while updating student status.");
}
}
@GetMapping("/pendingFor21Days")
public ResponseEntity<?> getStudentsPendingFor21Days() {
try {
List<Student> students = studentService.getStudentsPendingForMoreThan21Days();
return ResponseEntity.ok(students);
} catch (Exception e) {
log.error("Error fetching students pending for 21 days", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred while fetching students.");
}
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteStudent(@PathVariable Long id) {
try {
......@@ -68,13 +90,11 @@ public class StudentController {
}
@PutMapping("/{studentId}/verify")
public ResponseEntity<Student> verifyStudent(@PathVariable Long studentId, @RequestParam("status") VerificationStatus status) {
Student student = studentService.findById(studentId);
student.setVerificationStatus(status);
studentService.save(student);
return ResponseEntity.ok(student);
public ResponseEntity<Student> verifyStudent(@PathVariable Long studentId, @RequestParam("status") VerificationStatus status, @RequestParam("remarks") String remarks, @RequestParam("verificationDate") LocalDate verificationDate) {
Student updatedStudent = studentService.verifyStudent(studentId, status, remarks, verificationDate);
return ResponseEntity.ok(updatedStudent);
}
@GetMapping("/pending-verification")
@GetMapping("/pendingVerification")
public ResponseEntity<List<Student>> getStudentsPendingVerification() {
List<Student> students = studentService.findByVerificationStatus(VerificationStatus.PENDING);
return ResponseEntity.ok(students);
......
......@@ -51,8 +51,15 @@ public class Student {
private String highSchoolYearOfPassing;
private String intermediateRollNo;
private String intermediateYearOfPassing;
@Enumerated(EnumType.STRING)
private VerificationStatus verificationStatus = VerificationStatus.PENDING;
private String provisionalEnrollmentNumber;
private String adminRemarks;
private LocalDate enrollmentDate;
private LocalDate verificationDate;
private boolean requiresRevision;
private String enrollmentNumber;
@ManyToOne
@JoinColumn(name = "course_id")
private Course course;
......
package com.tarento.upsmf.examsAndAdmissions.model;
public enum VerificationStatus {
PENDING, VERIFIED, REJECTED
PENDING, VERIFIED, REJECTED, CLOSED
}
......@@ -2,6 +2,7 @@ package com.tarento.upsmf.examsAndAdmissions.model.dto;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDate;
@Getter
@Setter
......@@ -15,12 +16,12 @@ public class StudentDto {
private String courseName;
private String session;
private String examBatch;
private String admissionDate;
private LocalDate admissionDate;
private String firstName;
private String surname;
private String motherName;
private String fatherName;
private String dateOfBirth;
private LocalDate dateOfBirth;
private String gender;
private String caste;
private String category;
......@@ -39,10 +40,14 @@ public class StudentDto {
private String highSchoolYearOfPassing;
private String intermediateRollNo;
private String intermediateYearOfPassing;
private String adminRemarks;
private LocalDate enrollmentDate;
private LocalDate verificationDate;
private boolean requiresRevision;
private String enrollmentNumber;
private MultipartFile highSchoolMarksheet;
private MultipartFile highSchoolCertificate;
private MultipartFile intermediateMarksheet;
private MultipartFile intermediateCertificate;
}
......@@ -5,10 +5,14 @@ import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDate;
import java.util.List;
@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
List<Student> findByVerificationStatus(VerificationStatus status);
List<Student> findByEnrollmentDateBeforeAndVerificationStatus(LocalDate date, VerificationStatus status);
List<Student> findByVerificationDateBeforeAndVerificationStatus(LocalDate date, VerificationStatus status);
}
......@@ -2,8 +2,7 @@ package com.tarento.upsmf.examsAndAdmissions.service;
import com.tarento.upsmf.examsAndAdmissions.model.ExamCycle;
import com.tarento.upsmf.examsAndAdmissions.repository.ExamCycleRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -11,41 +10,40 @@ import java.util.Date;
import java.util.List;
@Service
@Slf4j
public class ExamCycleService {
private static final Logger logger = LoggerFactory.getLogger(ExamCycleService.class);
@Autowired
private ExamCycleRepository repository;
// Create a new exam cycle
public ExamCycle createExamCycle(ExamCycle examCycle) {
logger.info("Creating new ExamCycle: {}", examCycle);
log.info("Creating new ExamCycle: {}", examCycle);
examCycle.setObsolete(0);
return repository.save(examCycle);
}
// Fetch all active exam cycles
public List<ExamCycle> getAllExamCycles() {
logger.info("Fetching all active ExamCycles...");
log.info("Fetching all active ExamCycles...");
return repository.findByObsolete(0);
}
// Fetch all soft-deleted exam cycles
public List<ExamCycle> getAllObsoleteExamCycles() {
logger.info("Fetching all soft-deleted ExamCycles...");
log.info("Fetching all soft-deleted ExamCycles...");
return repository.findByObsolete(1);
}
// Fetch a specific exam cycle by its ID
public ExamCycle getExamCycleById(Long id) {
logger.info("Fetching ExamCycle by ID: {}", id);
log.info("Fetching ExamCycle by ID: {}", id);
return repository.findByIdAndObsolete(id, 0).orElse(null);
}
// Update an existing exam cycle
public ExamCycle updateExamCycle(Long id, ExamCycle updatedExamCycle) {
logger.info("Updating ExamCycle with ID: {}", id);
log.info("Updating ExamCycle with ID: {}", id);
ExamCycle existingExamCycle = repository.findById(id).orElse(null);
if (existingExamCycle != null) {
existingExamCycle.setExamCycleName(updatedExamCycle.getExamCycleName());
......@@ -61,31 +59,31 @@ public class ExamCycleService {
return repository.save(existingExamCycle);
}
logger.warn("ExamCycle with ID: {} not found!", id);
log.warn("ExamCycle with ID: {} not found!", id);
return null;
}
// Soft delete an exam cycle
public void deleteExamCycle(Long id) {
logger.info("Soft-deleting ExamCycle with ID: {}", id);
log.info("Soft-deleting ExamCycle with ID: {}", id);
ExamCycle examCycle = repository.findById(id).orElse(null);
if (examCycle != null) {
examCycle.setObsolete(1);
repository.save(examCycle);
} else {
logger.warn("ExamCycle with ID: {} not found for deletion!", id);
log.warn("ExamCycle with ID: {} not found for deletion!", id);
}
}
// Restore a soft-deleted exam cycle
public void restoreExamCycle(Long id) {
logger.info("Restoring soft-deleted ExamCycle with ID: {}", id);
log.info("Restoring soft-deleted ExamCycle with ID: {}", id);
ExamCycle examCycle = repository.findById(id).orElse(null);
if (examCycle != null && examCycle.getObsolete() == 1) {
examCycle.setObsolete(0);
repository.save(examCycle);
} else {
logger.warn("ExamCycle with ID: {} not found for restoration!", id);
log.warn("ExamCycle with ID: {} not found for restoration!", id);
}
}
}
\ No newline at end of file
......@@ -2,39 +2,37 @@ package com.tarento.upsmf.examsAndAdmissions.service;
import com.tarento.upsmf.examsAndAdmissions.model.Exam;
import com.tarento.upsmf.examsAndAdmissions.repository.ExamRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class ExamService {
private static final Logger logger = LoggerFactory.getLogger(ExamService.class);
@Autowired
private ExamRepository repository;
public Exam createExam(Exam exam) {
logger.info("Creating new Exam: {}", exam);
log.info("Creating new Exam: {}", exam);
exam.setObsolete(0);
return repository.save(exam);
}
public List<Exam> getAllExams() {
logger.info("Fetching all active Exams...");
log.info("Fetching all active Exams...");
return repository.findByObsolete(0);
}
public Exam getExamById(Long id) {
logger.info("Fetching Exam by ID: {}", id);
log.info("Fetching Exam by ID: {}", id);
return repository.findByIdAndObsolete(id, 0).orElse(null);
}
public Exam updateExam(Long id, Exam updatedExam) {
logger.info("Updating Exam with ID: {}", id);
log.info("Updating Exam with ID: {}", id);
Exam existingExam = repository.findById(id).orElse(null);
if (existingExam != null) {
existingExam.setExamCycleId(updatedExam.getExamCycleId());
......@@ -49,31 +47,31 @@ public class ExamService {
return repository.save(existingExam);
}
logger.warn("Exam with ID: {} not found!", id);
log.warn("Exam with ID: {} not found!", id);
return null;
}
public void deleteExam(Long id) {
logger.info("Soft-deleting Exam with ID: {}", id);
log.info("Soft-deleting Exam with ID: {}", id);
Exam exam = repository.findById(id).orElse(null);
if (exam != null) {
exam.setObsolete(1);
repository.save(exam);
} else {
logger.warn("Exam with ID: {} not found for deletion!", id);
log.warn("Exam with ID: {} not found for deletion!", id);
}
}
public void restoreExam(Long id) {
logger.info("Restoring soft-deleted Exam with ID: {}", id);
log.info("Restoring soft-deleted Exam with ID: {}", id);
Exam exam = repository.findById(id).orElse(null);
if (exam != null && exam.getObsolete() == 1) {
exam.setObsolete(0);
repository.save(exam);
} else {
logger.warn("Exam with ID: {} not found for restoration!", id);
log.warn("Exam with ID: {} not found for restoration!", id);
}
}
}
\ No newline at end of file
......@@ -6,9 +6,8 @@ import com.tarento.upsmf.examsAndAdmissions.model.VerificationStatus;
import com.tarento.upsmf.examsAndAdmissions.model.dto.StudentDto;
import com.tarento.upsmf.examsAndAdmissions.repository.CourseRepository;
import com.tarento.upsmf.examsAndAdmissions.repository.StudentRepository;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
......@@ -21,15 +20,16 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
@PropertySource("classpath:application.properties")
@Slf4j
public class StudentService {
private static final Logger logger = LoggerFactory.getLogger(StudentService.class);
private final StudentRepository studentRepository;
private final CourseRepository courseRepository;
private final ModelMapper modelMapper;
......@@ -130,6 +130,25 @@ public class StudentService {
return studentRepository.save(existingStudent);
}
public List<Student> updateStudentStatusToClosed() {
LocalDate cutoffDate = LocalDate.now().minusDays(14);
List<Student> rejectedStudents = studentRepository.findByVerificationDateBeforeAndVerificationStatus(cutoffDate, VerificationStatus.REJECTED);
log.info("Rejected students found to potentially close: " + rejectedStudents.size());
List<Student> studentsToUpdate = new ArrayList<>();
for (Student student : rejectedStudents) {
student.setVerificationStatus(VerificationStatus.CLOSED);
studentsToUpdate.add(student);
}
return studentRepository.saveAll(studentsToUpdate);
}
public List<Student> getStudentsPendingForMoreThan21Days() {
LocalDate twentyOneDaysAgo = LocalDate.now().minusDays(21);
return studentRepository.findByEnrollmentDateBeforeAndVerificationStatus(twentyOneDaysAgo, VerificationStatus.PENDING);
}
private void deleteFile(String filePath) {
if (filePath == null || filePath.isEmpty()) {
......@@ -168,6 +187,20 @@ public class StudentService {
student.setVerificationStatus(status);
return studentRepository.save(student);
}
public Student verifyStudent(Long studentId, VerificationStatus status, String remarks, LocalDate verificationDate) {
Student student = this.findById(studentId);
student.setVerificationStatus(status);
student.setAdminRemarks(remarks);
student.setVerificationDate(verificationDate);
if (status == VerificationStatus.VERIFIED) {
String enrollmentNumber = "EN" + LocalDate.now().getYear() + student.getCenterCode() + student.getId();
student.setEnrollmentNumber(enrollmentNumber);
} else if (status == VerificationStatus.REJECTED) {
student.setRequiresRevision(true);
}
return this.save(student);
}
public List<Student> findByVerificationStatus(VerificationStatus status) {
return studentRepository.findByVerificationStatus(status);
}
......
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