i will share materials backend classes give me frontend pages in nextjs my port number is 8081package com.example.Tutionbackend.Courses.Model; import java.time.LocalDateTime; import com.example.Tutionbackend.Teacher.Model.Teacher; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Entity @Table(name = "materials") @Data @NoArgsConstructor @AllArgsConstructor public class Material { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String title; @Column(length = 1000) private String description; @Column(name = "file_path") private String filePath; @Column(name = "file_type") private String fileType; @Column(name = "file_size") private Long fileSize; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id", nullable = false) private Course course; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "teacher_id") private Teacher uploadedBy; @Column(name = "upload_date") private java.time.LocalDateTime uploadDate; @Column(name = "created_at") private java.time.LocalDateTime createdAt; @Column(name = "updated_at") private java.time.LocalDateTime updatedAt; @PrePersist protected void onCreate() { createdAt = java.time.LocalDateTime.now(); updatedAt = createdAt; uploadDate = createdAt; } @PreUpdate protected void onUpdate() { updatedAt = java.time.LocalDateTime.now(); } public Material(Long id, String title, String description, String filePath, String fileType, Long fileSize, Course course, Teacher uploadedBy, LocalDateTime uploadDate, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.title = title; this.description = description; this.filePath = filePath; this.fileType = fileType; this.fileSize = fileSize; this.course = course; this.uploadedBy = uploadedBy; this.uploadDate = uploadDate; this.createdAt = createdAt; this.updatedAt = updatedAt; } public Material() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public String getFileType() { return fileType; } public void setFileType(String fileType) { this.fileType = fileType; } public Long getFileSize() { return fileSize; } public void setFileSize(Long fileSize) { this.fileSize = fileSize; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public Teacher getUploadedBy() { return uploadedBy; } public void setUploadedBy(Teacher uploadedBy) { this.uploadedBy = uploadedBy; } public java.time.LocalDateTime getUploadDate() { return uploadDate; } public void setUploadDate(java.time.LocalDateTime uploadDate) { this.uploadDate = uploadDate; } public java.time.LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(java.time.LocalDateTime createdAt) { this.createdAt = createdAt; } public java.time.LocalDateTime getUpdatedAt() { return updatedAt; } public void setUpdatedAt(java.time.LocalDateTime updatedAt) { this.updatedAt = updatedAt; } } package com.example.Tutionbackend.Courses.DTO; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; @Data @NoArgsConstructor @AllArgsConstructor public class MaterialDTO { private Long id; private String title; private String description; private String filePath; private String fileType; private Long fileSize; private Long courseId; private Long uploadedById; private String uploadedByName; private LocalDateTime uploadDate; public MaterialDTO(Long id, String title, String description, String filePath, String fileType, Long fileSize, Long courseId, Long uploadedById, String uploadedByName, LocalDateTime uploadDate) { this.id = id; this.title = title; this.description = description; this.filePath = filePath; this.fileType = fileType; this.fileSize = fileSize; this.courseId = courseId; this.uploadedById = uploadedById; this.uploadedByName = uploadedByName; this.uploadDate = uploadDate; } public MaterialDTO() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public String getFileType() { return fileType; } public void setFileType(String fileType) { this.fileType = fileType; } public Long getFileSize() { return fileSize; } public void setFileSize(Long fileSize) { this.fileSize = fileSize; } public Long getCourseId() { return courseId; } public void setCourseId(Long courseId) { this.courseId = courseId; } public Long getUploadedById() { return uploadedById; } public void setUploadedById(Long uploadedById) { this.uploadedById = uploadedById; } public String getUploadedByName() { return uploadedByName; } public void setUploadedByName(String uploadedByName) { this.uploadedByName = uploadedByName; } public LocalDateTime getUploadDate() { return uploadDate; } public void setUploadDate(LocalDateTime uploadDate) { this.uploadDate = uploadDate; } } package com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.example.Tutionbackend.Courses.DTO.MaterialDTO; import com.example.Tutionbackend.Courses.Services.MaterialService; import java.io.IOException; import java.util.List; @RestController @RequestMapping("/api/materials") @CrossOrigin(origins = "http://localhost:3000") public class MaterialController { @Autowired private MaterialService materialService; @GetMapping("/course/{courseId}") public ResponseEntity<List<MaterialDTO>> getMaterialsByCourseId(@PathVariable Long courseId) { return ResponseEntity.ok(materialService.getMaterialsByCourseId(courseId)); } @GetMapping("/{id}") public ResponseEntity<MaterialDTO> getMaterialById(@PathVariable Long id) { return ResponseEntity.ok(materialService.getMaterialById(id)); } @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<MaterialDTO> uploadMaterial( @RequestParam("file") MultipartFile file, @RequestParam("title") String title, @RequestParam("description") String description, @RequestParam("courseId") Long courseId, @RequestParam("uploadedById") Long uploadedById) throws IOException { MaterialDTO materialDTO = new MaterialDTO(); materialDTO.setTitle(title); materialDTO.setDescription(description); materialDTO.setCourseId(courseId); materialDTO.setUploadedById(uploadedById); return new ResponseEntity<>(materialService.uploadMaterial(file, materialDTO), HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity<MaterialDTO> updateMaterial( @PathVariable Long id, @RequestBody MaterialDTO materialDTO) { return ResponseEntity.ok(materialService.updateMaterial(id, materialDTO)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteMaterial(@PathVariable Long id) throws IOException { materialService.deleteMaterial(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.MaterialDTO; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Model.Material; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Courses.Repository.MaterialRepository; import com.example.Tutionbackend.Teacher.Model.Teacher; import com.example.Tutionbackend.Teacher.Repository.TeacherRepository; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @Service public class MaterialService { @Autowired private MaterialRepository materialRepository; @Autowired private CourseRepository courseRepository; @Autowired private TeacherRepository teacherRepository; @Value("${file.upload-dir:uploads/materials}") private String uploadDir; public List<MaterialDTO> getMaterialsByCourseId(Long courseId) { return materialRepository.findByCourseId(courseId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public MaterialDTO getMaterialById(Long id) { Material material = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); return convertToDTO(material); } @Transactional public MaterialDTO uploadMaterial(MultipartFile file, MaterialDTO materialDTO) throws IOException { Course course = courseRepository.findById(materialDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + materialDTO.getCourseId())); Teacher teacher = teacherRepository.findById(materialDTO.getUploadedById()) .orElseThrow(() -> new ResourceNotFoundException("Teacher not found with id: " + materialDTO.getUploadedById())); // Create directory if it doesn't exist Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectories(uploadPath); } // Generate unique filename String originalFilename = file.getOriginalFilename(); String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); String uniqueFilename = UUID.randomUUID().toString() + fileExtension; // Save file to disk Path filePath = uploadPath.resolve(uniqueFilename); Files.copy(file.getInputStream(), filePath); // Create and save material entity Material material = new Material(); material.setTitle(materialDTO.getTitle()); material.setDescription(materialDTO.getDescription()); material.setFilePath(uniqueFilename); material.setFileType(file.getContentType()); material.setFileSize(file.getSize()); material.setCourse(course); material.setUploadedBy(teacher); material.setUploadDate(LocalDateTime.now()); Material savedMaterial = materialRepository.save(material); return convertToDTO(savedMaterial); } @Transactional public MaterialDTO updateMaterial(Long id,MaterialDTO materialDTO) { Material existingMaterial = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); // If course is being changed, verify it exists if (!existingMaterial.getCourse().getId().equals(materialDTO.getCourseId())) { Course newCourse = courseRepository.findById(materialDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + materialDTO.getCourseId())); existingMaterial.setCourse(newCourse); } existingMaterial.setTitle(materialDTO.getTitle()); existingMaterial.setDescription(materialDTO.getDescription()); Material updatedMaterial = materialRepository.save(existingMaterial); return convertToDTO(updatedMaterial); } @Transactional public void deleteMaterial(Long id) throws IOException { Material material = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); // Delete the file from disk Path filePath = Paths.get(uploadDir).resolve(material.getFilePath()); if (Files.exists(filePath)) { Files.delete(filePath); } materialRepository.deleteById(id); } private MaterialDTO convertToDTO(Material material) { MaterialDTO dto = new MaterialDTO(); dto.setId(material.getId()); dto.setTitle(material.getTitle()); dto.setDescription(material.getDescription()); dto.setFilePath(material.getFilePath()); dto.setFileType(material.getFileType()); dto.setFileSize(material.getFileSize()); dto.setCourseId(material.getCourse().getId()); dto.setUploadDate(material.getUploadDate()); if (material.getUploadedBy() != null) { dto.setUploadedById(material.getUploadedBy().getId()); dto.setUploadedByName(material.getUploadedBy().getName() + " " + material.getUploadedBy().getName()); } return dto; } }
I'll create a Next.js frontend for your course materials management system based on the Spring Boot backend you've shared. The frontend will connect to your backend running on port 8081.
I've created a Next.js frontend for your course materials management system that connects to your Spring Boot backend running on port 8081. Here's what the application includes:
Course Materials Page - Shows all materials for a specific course with options to:
The code includes commented-out API calls that you can uncomment to connect to your Spring Boot backend. Currently, it uses mock data for demonstration purposes. To connect to your backend:
To run this application:
npm install to install dependenciesnpm run dev to start the development serverThe application will connect to your backend running on http://localhost:8081.
i will share all course realted files create all pages and no mock data required only data coming from api which i will sharepackage com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.example.Tutionbackend.Courses.DTO.CourseDTO; import com.example.Tutionbackend.Courses.Services.CourseService; import java.util.List; @RestController @RequestMapping("/api/courses") @CrossOrigin(origins = "http://localhost:3000") public class CourseController { @Autowired private CourseService courseService; @GetMapping public ResponseEntity<List<CourseDTO>> getAllCourses() { return ResponseEntity.ok(courseService.getAllCourses()); } @GetMapping("/active") public ResponseEntity<List<CourseDTO>> getActiveCourses() { return ResponseEntity.ok(courseService.getActiveCourses()); } @GetMapping("/{id}") public ResponseEntity<CourseDTO> getCourseById(@PathVariable Long id) { return ResponseEntity.ok(courseService.getCourseById(id)); } @GetMapping("/code/{code}") public ResponseEntity<CourseDTO> getCourseByCode(@PathVariable String code) { return ResponseEntity.ok(courseService.getCourseByCode(code)); } @GetMapping("/teacher/{teacherId}") public ResponseEntity<List<CourseDTO>> getCoursesByTeacherId(@PathVariable Long teacherId) { return ResponseEntity.ok(courseService.getCoursesByTeacherId(teacherId)); } @PostMapping public ResponseEntity<CourseDTO> createCourse(@RequestBody CourseDTO courseDTO) { return new ResponseEntity<>(courseService.createCourse(courseDTO), HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity<CourseDTO> updateCourse(@PathVariable Long id, @RequestBody CourseDTO courseDTO) { return ResponseEntity.ok(courseService.updateCourse(id, courseDTO)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteCourse(@PathVariable Long id) { courseService.deleteCourse(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.example.Tutionbackend.Courses.DTO.AssignmentDTO; import com.example.Tutionbackend.Courses.Services.AssignmentService; import java.io.IOException; import java.time.LocalDateTime; import java.util.List; @RestController @RequestMapping("/api/assignments") @CrossOrigin(origins = "http://localhost:3000") public class AssignmentController { @Autowired private AssignmentService assignmentService; @GetMapping("/course/{courseId}") public ResponseEntity<List<AssignmentDTO>> getAssignmentsByCourseId(@PathVariable Long courseId) { return ResponseEntity.ok(assignmentService.getAssignmentsByCourseId(courseId)); } @GetMapping("/date-range") public ResponseEntity<List<AssignmentDTO>> getAssignmentsByDateRange( @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime start, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime end) { return ResponseEntity.ok(assignmentService.getAssignmentsByDateRange(start, end)); } @GetMapping("/{id}") public ResponseEntity<AssignmentDTO> getAssignmentById(@PathVariable Long id) { return ResponseEntity.ok(assignmentService.getAssignmentById(id)); } @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<AssignmentDTO> createAssignment( @RequestParam(value = "file", required = false) MultipartFile file, @RequestParam("title") String title, @RequestParam("description") String description, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dueDate, @RequestParam("totalMarks") Double totalMarks, @RequestParam("courseId") Long courseId, @RequestParam(value = "createdById", required = false) Long createdById) throws IOException { AssignmentDTO assignmentDTO = new AssignmentDTO(); assignmentDTO.setTitle(title); assignmentDTO.setDescription(description); assignmentDTO.setDueDate(dueDate); assignmentDTO.setTotalMarks(totalMarks); assignmentDTO.setCourseId(courseId); assignmentDTO.setCreatedById(createdById); return new ResponseEntity<>(assignmentService.createAssignment(file, assignmentDTO), HttpStatus.CREATED); } @PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<AssignmentDTO> updateAssignment( @PathVariable Long id, @RequestParam(value = "file", required = false) MultipartFile file, @RequestParam("title") String title, @RequestParam("description") String description, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dueDate, @RequestParam("totalMarks") Double totalMarks, @RequestParam("courseId") Long courseId) throws IOException { AssignmentDTO assignmentDTO = new AssignmentDTO(); assignmentDTO.setTitle(title); assignmentDTO.setDescription(description); assignmentDTO.setDueDate(dueDate); assignmentDTO.setTotalMarks(totalMarks); assignmentDTO.setCourseId(courseId); return ResponseEntity.ok(assignmentService.updateAssignment(id, assignmentDTO, file)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteAssignment(@PathVariable Long id) throws IOException { assignmentService.deleteAssignment(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.example.Tutionbackend.Courses.DTO.CurriculumDTO; import com.example.Tutionbackend.Courses.Services.CurriculumService; import java.util.List; @RestController @RequestMapping("/api/curriculum") @CrossOrigin(origins = "http://localhost:3000") public class CurriculumController { @Autowired private CurriculumService curriculumService; @GetMapping("/course/{courseId}") public ResponseEntity<List<CurriculumDTO>> getCurriculumByCourseId(@PathVariable Long courseId) { return ResponseEntity.ok(curriculumService.getCurriculumByCourseId(courseId)); } @GetMapping("/{id}") public ResponseEntity<CurriculumDTO> getCurriculumById(@PathVariable Long id) { return ResponseEntity.ok(curriculumService.getCurriculumById(id)); } @PostMapping public ResponseEntity<CurriculumDTO> createCurriculum(@RequestBody CurriculumDTO curriculumDTO) { return new ResponseEntity<>(curriculumService.createCurriculum(curriculumDTO), HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity<CurriculumDTO> updateCurriculum(@PathVariable Long id, @RequestBody CurriculumDTO curriculumDTO) { return ResponseEntity.ok(curriculumService.updateCurriculum(id, curriculumDTO)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteCurriculum(@PathVariable Long id) { curriculumService.deleteCurriculum(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.example.Tutionbackend.Courses.DTO.ExamDTO; import com.example.Tutionbackend.Courses.Services.ExamService; import java.time.LocalDateTime; import java.util.List; @RestController @RequestMapping("/api/exams") @CrossOrigin(origins = "http://localhost:3000") public class ExamController { @Autowired private ExamService examService; @GetMapping("/course/{courseId}") public ResponseEntity<List<ExamDTO>> getExamsByCourseId(@PathVariable Long courseId) { return ResponseEntity.ok(examService.getExamsByCourseId(courseId)); } @GetMapping("/date-range") public ResponseEntity<List<ExamDTO>> getExamsByDateRange( @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime start, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime end) { return ResponseEntity.ok(examService.getExamsByDateRange(start, end)); } @GetMapping("/{id}") public ResponseEntity<ExamDTO> getExamById(@PathVariable Long id) { return ResponseEntity.ok(examService.getExamById(id)); } @PostMapping public ResponseEntity<ExamDTO> createExam(@RequestBody ExamDTO examDTO) { return new ResponseEntity<>(examService.createExam(examDTO), HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity<ExamDTO> updateExam(@PathVariable Long id, @RequestBody ExamDTO examDTO) { return ResponseEntity.ok(examService.updateExam(id, examDTO)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteExam(@PathVariable Long id) { examService.deleteExam(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import com.example.Tutionbackend.Courses.DTO.MaterialDTO; import com.example.Tutionbackend.Courses.Services.MaterialService; import java.io.IOException; import java.util.List; @RestController @RequestMapping("/api/materials") @CrossOrigin(origins = "http://localhost:3000") public class MaterialController { @Autowired private MaterialService materialService; @GetMapping("/course/{courseId}") public ResponseEntity<List<MaterialDTO>> getMaterialsByCourseId(@PathVariable Long courseId) { return ResponseEntity.ok(materialService.getMaterialsByCourseId(courseId)); } @GetMapping("/{id}") public ResponseEntity<MaterialDTO> getMaterialById(@PathVariable Long id) { return ResponseEntity.ok(materialService.getMaterialById(id)); } @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<MaterialDTO> uploadMaterial( @RequestParam("file") MultipartFile file, @RequestParam("title") String title, @RequestParam("description") String description, @RequestParam("courseId") Long courseId, @RequestParam("uploadedById") Long uploadedById) throws IOException { MaterialDTO materialDTO = new MaterialDTO(); materialDTO.setTitle(title); materialDTO.setDescription(description); materialDTO.setCourseId(courseId); materialDTO.setUploadedById(uploadedById); return new ResponseEntity<>(materialService.uploadMaterial(file, materialDTO), HttpStatus.CREATED); } @PutMapping("/{id}") public ResponseEntity<MaterialDTO> updateMaterial( @PathVariable Long id, @RequestBody MaterialDTO materialDTO) { return ResponseEntity.ok(materialService.updateMaterial(id, materialDTO)); } @DeleteMapping("/{id}") public ResponseEntity<Void> deleteMaterial(@PathVariable Long id) throws IOException { materialService.deleteMaterial(id); return ResponseEntity.noContent().build(); } } package com.example.Tutionbackend.Courses.Services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.AssignmentDTO; import com.example.Tutionbackend.Courses.Model.Assignment; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Repository.AssignmentRepository; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Teacher.Model.Teacher; import com.example.Tutionbackend.Teacher.Repository.TeacherRepository; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @Service public class AssignmentService { @Autowired private AssignmentRepository assignmentRepository; @Autowired private CourseRepository courseRepository; @Autowired private TeacherRepository teacherRepository; @Value("${file.upload-dir:uploads/assignments}") private String uploadDir; public List<AssignmentDTO> getAssignmentsByCourseId(Long courseId) { return assignmentRepository.findByCourseId(courseId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public List<AssignmentDTO> getAssignmentsByDateRange(LocalDateTime start, LocalDateTime end) { return assignmentRepository.findByDueDateBetween(start, end).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public AssignmentDTO getAssignmentById(Long id) { Assignment assignment = assignmentRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Assignment not found with id: " + id)); return convertToDTO(assignment); } @Transactional public AssignmentDTO createAssignment(MultipartFile file, AssignmentDTO assignmentDTO) throws IOException { Course course = courseRepository.findById(assignmentDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + assignmentDTO.getCourseId())); Teacher teacher = null; if (assignmentDTO.getCreatedById() != null) { teacher = teacherRepository.findById(assignmentDTO.getCreatedById()) .orElseThrow(() -> new ResourceNotFoundException("Teacher not found with id: " + assignmentDTO.getCreatedById())); } String filePath = null; if (file != null && !file.isEmpty()) { // Create directory if it doesn't exist Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectories(uploadPath); } // Generate unique filename String originalFilename = file.getOriginalFilename(); String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); String uniqueFilename = UUID.randomUUID().toString() + fileExtension; // Save file to disk Path path = uploadPath.resolve(uniqueFilename); Files.copy(file.getInputStream(), path); filePath = uniqueFilename; } Assignment assignment = new Assignment(); assignment.setTitle(assignmentDTO.getTitle()); assignment.setDescription(assignmentDTO.getDescription()); assignment.setDueDate(assignmentDTO.getDueDate()); assignment.setTotalMarks(assignmentDTO.getTotalMarks()); assignment.setFilePath(filePath); assignment.setCourse(course); assignment.setCreatedBy(teacher); Assignment savedAssignment = assignmentRepository.save(assignment); return convertToDTO(savedAssignment); } @Transactional public AssignmentDTO updateAssignment(Long id, AssignmentDTO assignmentDTO, MultipartFile file) throws IOException { Assignment existingAssignment = assignmentRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Assignment not found with id: " + id)); // If course is being changed, verify it exists if (!existingAssignment.getCourse().getId().equals(assignmentDTO.getCourseId())) { Course newCourse = courseRepository.findById(assignmentDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + assignmentDTO.getCourseId())); existingAssignment.setCourse(newCourse); } existingAssignment.setTitle(assignmentDTO.getTitle()); existingAssignment.setDescription(assignmentDTO.getDescription()); existingAssignment.setDueDate(assignmentDTO.getDueDate()); existingAssignment.setTotalMarks(assignmentDTO.getTotalMarks()); // Update file if provided if (file != null && !file.isEmpty()) { // Delete old file if exists if (existingAssignment.getFilePath() != null) { Path oldFilePath = Paths.get(uploadDir).resolve(existingAssignment.getFilePath()); if (Files.exists(oldFilePath)) { Files.delete(oldFilePath); } } // Create directory if it doesn't exist Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectories(uploadPath); } // Generate unique filename String originalFilename = file.getOriginalFilename(); String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); String uniqueFilename = UUID.randomUUID().toString() + fileExtension; // Save file to disk Path path = uploadPath.resolve(uniqueFilename); Files.copy(file.getInputStream(), path); existingAssignment.setFilePath(uniqueFilename); } Assignment updatedAssignment = assignmentRepository.save(existingAssignment); return convertToDTO(updatedAssignment); } @Transactional public void deleteAssignment(Long id) throws IOException { Assignment assignment = assignmentRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Assignment not found with id: " + id)); // Delete the file from disk if exists if (assignment.getFilePath() != null) { Path filePath = Paths.get(uploadDir).resolve(assignment.getFilePath()); if (Files.exists(filePath)) { Files.delete(filePath); } } assignmentRepository.deleteById(id); } private AssignmentDTO convertToDTO(Assignment assignment) { AssignmentDTO dto = new AssignmentDTO(); dto.setId(assignment.getId()); dto.setTitle(assignment.getTitle()); dto.setDescription(assignment.getDescription()); dto.setDueDate(assignment.getDueDate()); dto.setTotalMarks(assignment.getTotalMarks()); dto.setFilePath(assignment.getFilePath()); dto.setCourseId(assignment.getCourse().getId()); dto.setCourseName(assignment.getCourse().getName()); if (assignment.getCreatedBy() != null) { dto.setCreatedById(assignment.getCreatedBy().getId()); dto.setCreatedByName(assignment.getCreatedBy().getName() + " " + assignment.getCreatedBy().getName()); } return dto; } } package com.example.Tutionbackend.Courses.Services; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.CourseDTO; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Teacher.Model.Teacher; import com.example.Tutionbackend.Teacher.Repository.TeacherRepository; import jakarta.transaction.Transactional; @Service public class CourseService { @Autowired private CourseRepository courseRepository; @Autowired private TeacherRepository teacherRepository; public List<CourseDTO> getAllCourses() { return courseRepository.findAll().stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public List<CourseDTO> getActiveCourses() { return courseRepository.findByActiveTrue().stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public CourseDTO getCourseById(Long id) { Course course = courseRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + id)); return convertToDTO(course); } public CourseDTO getCourseByCode(String code) { Course course = courseRepository.findByCode(code) .orElseThrow(() -> new ResourceNotFoundException("Course not found with code: " + code)); return convertToDTO(course); } @Transactional public CourseDTO createCourse(CourseDTO courseDTO) { if (courseRepository.existsByCode(courseDTO.getCode())) { throw new IllegalArgumentException("Course with code " + courseDTO.getCode() + " already exists"); } Course course = convertToEntity(courseDTO); // Set teachers if provided if (courseDTO.getTeacherIds() != null && !courseDTO.getTeacherIds().isEmpty()) { List<Teacher> teachers = teacherRepository.findAllById(courseDTO.getTeacherIds()); course.setTeachers(teachers); } Course savedCourse = courseRepository.save(course); return convertToDTO(savedCourse); } @Transactional public CourseDTO updateCourse(Long id, CourseDTO courseDTO) { Course existingCourse = courseRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + id)); // Check if code is being changed and if new code already exists if (!existingCourse.getCode().equals(courseDTO.getCode()) && courseRepository.existsByCode(courseDTO.getCode())) { throw new IllegalArgumentException("Course with code " + courseDTO.getCode() + " already exists"); } existingCourse.setName(courseDTO.getName()); existingCourse.setDescription(courseDTO.getDescription()); existingCourse.setCode(courseDTO.getCode()); existingCourse.setCreditHours(courseDTO.getCreditHours()); existingCourse.setActive(courseDTO.isActive()); // Update teachers if provided if (courseDTO.getTeacherIds() != null) { List<Teacher> teachers = teacherRepository.findAllById(courseDTO.getTeacherIds()); existingCourse.setTeachers(teachers); } Course updatedCourse = courseRepository.save(existingCourse); return convertToDTO(updatedCourse); } @Transactional public void deleteCourse(Long id) { if (!courseRepository.existsById(id)) { throw new ResourceNotFoundException("Course not found with id: " + id); } courseRepository.deleteById(id); } public List<CourseDTO> getCoursesByTeacherId(Long teacherId) { return courseRepository.findCoursesByTeacherId(teacherId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } private CourseDTO convertToDTO(Course course) { CourseDTO dto = new CourseDTO(); dto.setId(course.getId()); dto.setName(course.getName()); dto.setDescription(course.getDescription()); dto.setCode(course.getCode()); dto.setCreditHours(course.getCreditHours()); dto.setActive(course.isActive()); dto.setCreatedAt(course.getCreatedAt()); dto.setUpdatedAt(course.getUpdatedAt()); // Set teacher IDs if (course.getTeachers() != null) { dto.setTeacherIds(course.getTeachers().stream() .map(Teacher::getId) .collect(Collectors.toList())); } else { dto.setTeacherIds(new ArrayList<>()); } return dto; } private Course convertToEntity(CourseDTO dto) { Course course = new Course(); course.setName(dto.getName()); course.setDescription(dto.getDescription()); course.setCode(dto.getCode()); course.setCreditHours(dto.getCreditHours()); course.setActive(dto.isActive()); return course; } } package com.example.Tutionbackend.Courses.Services; import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.CurriculumDTO; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Model.Curriculum; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Courses.Repository.CurriculumRepository; import jakarta.transaction.Transactional; @Service public class CurriculumService { @Autowired private CurriculumRepository curriculumRepository; @Autowired private CourseRepository courseRepository; public List<CurriculumDTO> getCurriculumByCourseId(Long courseId) { return curriculumRepository.findByCourseIdOrderBySequenceAsc(courseId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public CurriculumDTO getCurriculumById(Long id) { Curriculum curriculum = curriculumRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Curriculum item not found with id: " + id)); return convertToDTO(curriculum); } @Transactional public CurriculumDTO createCurriculum(CurriculumDTO curriculumDTO) { Course course = courseRepository.findById(curriculumDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + curriculumDTO.getCourseId())); Curriculum curriculum = convertToEntity(curriculumDTO); curriculum.setCourse(course); Curriculum savedCurriculum = curriculumRepository.save(curriculum); return convertToDTO(savedCurriculum); } @Transactional public CurriculumDTO updateCurriculum(Long id, CurriculumDTO curriculumDTO) { Curriculum existingCurriculum = curriculumRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Curriculum item not found with id: " + id)); // If course is being changed, verify it exists if (!existingCurriculum.getCourse().getId().equals(curriculumDTO.getCourseId())) { Course newCourse = courseRepository.findById(curriculumDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + curriculumDTO.getCourseId())); existingCurriculum.setCourse(newCourse); } existingCurriculum.setTitle(curriculumDTO.getTitle()); existingCurriculum.setDescription(curriculumDTO.getDescription()); existingCurriculum.setSequence(curriculumDTO.getSequence()); Curriculum updatedCurriculum = curriculumRepository.save(existingCurriculum); return convertToDTO(updatedCurriculum); } @Transactional public void deleteCurriculum(Long id) { if (!curriculumRepository.existsById(id)) { throw new ResourceNotFoundException("Curriculum item not found with id: " + id); } curriculumRepository.deleteById(id); } private CurriculumDTO convertToDTO(Curriculum curriculum) { CurriculumDTO dto = new CurriculumDTO(); dto.setId(curriculum.getId()); dto.setTitle(curriculum.getTitle()); dto.setDescription(curriculum.getDescription()); dto.setSequence(curriculum.getSequence()); dto.setCourseId(curriculum.getCourse().getId()); return dto; } private Curriculum convertToEntity(CurriculumDTO dto) { Curriculum curriculum = new Curriculum(); curriculum.setTitle(dto.getTitle()); curriculum.setDescription(dto.getDescription()); curriculum.setSequence(dto.getSequence()); return curriculum; } } package com.example.Tutionbackend.Courses.Services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.ExamDTO; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Model.Exam; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Courses.Repository.ExamRepository; import com.example.Tutionbackend.Teacher.Model.Teacher; import com.example.Tutionbackend.Teacher.Repository.TeacherRepository; import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @Service public class ExamService { @Autowired private ExamRepository examRepository; @Autowired private CourseRepository courseRepository; @Autowired private TeacherRepository teacherRepository; public List<ExamDTO> getExamsByCourseId(Long courseId) { return examRepository.findByCourseId(courseId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public List<ExamDTO> getExamsByDateRange(LocalDateTime start, LocalDateTime end) { return examRepository.findByExamDateBetween(start, end).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public ExamDTO getExamById(Long id) { Exam exam = examRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Exam not found with id: " + id)); return convertToDTO(exam); } @Transactional public ExamDTO createExam(ExamDTO examDTO) { Course course = courseRepository.findById(examDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + examDTO.getCourseId())); Teacher teacher = null; if (examDTO.getCreatedById() != null) { teacher = teacherRepository.findById(examDTO.getCreatedById()) .orElseThrow(() -> new ResourceNotFoundException("Teacher not found with id: " + examDTO.getCreatedById())); } Exam exam = convertToEntity(examDTO); exam.setCourse(course); exam.setCreatedBy(teacher); Exam savedExam = examRepository.save(exam); return convertToDTO(savedExam); } @Transactional public ExamDTO updateExam(Long id, ExamDTO examDTO) { Exam existingExam = examRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Exam not found with id: " + id)); // If course is being changed, verify it exists if (!existingExam.getCourse().getId().equals(examDTO.getCourseId())) { Course newCourse = courseRepository.findById(examDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + examDTO.getCourseId())); existingExam.setCourse(newCourse); } existingExam.setTitle(examDTO.getTitle()); existingExam.setDescription(examDTO.getDescription()); existingExam.setExamDate(examDTO.getExamDate()); existingExam.setDurationMinutes(examDTO.getDurationMinutes()); existingExam.setTotalMarks(examDTO.getTotalMarks()); existingExam.setPassingMarks(examDTO.getPassingMarks()); existingExam.setExamType(examDTO.getExamType()); Exam updatedExam = examRepository.save(existingExam); return convertToDTO(updatedExam); } @Transactional public void deleteExam(Long id) { if (!examRepository.existsById(id)) { throw new ResourceNotFoundException("Exam not found with id: " + id); } examRepository.deleteById(id); } private ExamDTO convertToDTO(Exam exam) { ExamDTO dto = new ExamDTO(); dto.setId(exam.getId()); dto.setTitle(exam.getTitle()); dto.setDescription(exam.getDescription()); dto.setExamDate(exam.getExamDate()); dto.setDurationMinutes(exam.getDurationMinutes()); dto.setTotalMarks(exam.getTotalMarks()); dto.setPassingMarks(exam.getPassingMarks()); dto.setExamType(exam.getExamType()); dto.setCourseId(exam.getCourse().getId()); dto.setCourseName(exam.getCourse().getName()); if (exam.getCreatedBy() != null) { dto.setCreatedById(exam.getCreatedBy().getId()); dto.setCreatedByName(exam.getCreatedBy().getName() + " " + exam.getCreatedBy().getName()); } return dto; } private Exam convertToEntity(ExamDTO dto) { Exam exam = new Exam(); exam.setTitle(dto.getTitle()); exam.setDescription(dto.getDescription()); exam.setExamDate(dto.getExamDate()); exam.setDurationMinutes(dto.getDurationMinutes()); exam.setTotalMarks(dto.getTotalMarks()); exam.setPassingMarks(dto.getPassingMarks()); exam.setExamType(dto.getExamType()); return exam; } } package com.example.Tutionbackend.Courses.Services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import com.Tutionbackend.Courses.exception.ResourceNotFoundException; import com.example.Tutionbackend.Courses.DTO.MaterialDTO; import com.example.Tutionbackend.Courses.Model.Course; import com.example.Tutionbackend.Courses.Model.Material; import com.example.Tutionbackend.Courses.Repository.CourseRepository; import com.example.Tutionbackend.Courses.Repository.MaterialRepository; import com.example.Tutionbackend.Teacher.Model.Teacher; import com.example.Tutionbackend.Teacher.Repository.TeacherRepository; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @Service public class MaterialService { @Autowired private MaterialRepository materialRepository; @Autowired private CourseRepository courseRepository; @Autowired private TeacherRepository teacherRepository; @Value("${file.upload-dir:uploads/materials}") private String uploadDir; public List<MaterialDTO> getMaterialsByCourseId(Long courseId) { return materialRepository.findByCourseId(courseId).stream() .map(this::convertToDTO) .collect(Collectors.toList()); } public MaterialDTO getMaterialById(Long id) { Material material = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); return convertToDTO(material); } @Transactional public MaterialDTO uploadMaterial(MultipartFile file, MaterialDTO materialDTO) throws IOException { Course course = courseRepository.findById(materialDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + materialDTO.getCourseId())); Teacher teacher = teacherRepository.findById(materialDTO.getUploadedById()) .orElseThrow(() -> new ResourceNotFoundException("Teacher not found with id: " + materialDTO.getUploadedById())); // Create directory if it doesn't exist Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectories(uploadPath); } // Generate unique filename String originalFilename = file.getOriginalFilename(); String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); String uniqueFilename = UUID.randomUUID().toString() + fileExtension; // Save file to disk Path filePath = uploadPath.resolve(uniqueFilename); Files.copy(file.getInputStream(), filePath); // Create and save material entity Material material = new Material(); material.setTitle(materialDTO.getTitle()); material.setDescription(materialDTO.getDescription()); material.setFilePath(uniqueFilename); material.setFileType(file.getContentType()); material.setFileSize(file.getSize()); material.setCourse(course); material.setUploadedBy(teacher); material.setUploadDate(LocalDateTime.now()); Material savedMaterial = materialRepository.save(material); return convertToDTO(savedMaterial); } @Transactional public MaterialDTO updateMaterial(Long id,MaterialDTO materialDTO) { Material existingMaterial = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); // If course is being changed, verify it exists if (!existingMaterial.getCourse().getId().equals(materialDTO.getCourseId())) { Course newCourse = courseRepository.findById(materialDTO.getCourseId()) .orElseThrow(() -> new ResourceNotFoundException("Course not found with id: " + materialDTO.getCourseId())); existingMaterial.setCourse(newCourse); } existingMaterial.setTitle(materialDTO.getTitle()); existingMaterial.setDescription(materialDTO.getDescription()); Material updatedMaterial = materialRepository.save(existingMaterial); return convertToDTO(updatedMaterial); } @Transactional public void deleteMaterial(Long id) throws IOException { Material material = materialRepository.findById(id) .orElseThrow(() -> new ResourceNotFoundException("Class material not found with id: " + id)); // Delete the file from disk Path filePath = Paths.get(uploadDir).resolve(material.getFilePath()); if (Files.exists(filePath)) { Files.delete(filePath); } materialRepository.deleteById(id); } private MaterialDTO convertToDTO(Material material) { MaterialDTO dto = new MaterialDTO(); dto.setId(material.getId()); dto.setTitle(material.getTitle()); dto.setDescription(material.getDescription()); dto.setFilePath(material.getFilePath()); dto.setFileType(material.getFileType()); dto.setFileSize(material.getFileSize()); dto.setCourseId(material.getCourse().getId()); dto.setUploadDate(material.getUploadDate()); if (material.getUploadedBy() != null) { dto.setUploadedById(material.getUploadedBy().getId()); dto.setUploadedByName(material.getUploadedBy().getName() + " " + material.getUploadedBy().getName()); } return dto; } } package com.example.Tutionbackend.Courses.Model; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; import com.example.Tutionbackend.Teacher.Model.Teacher; @Entity @Table(name = "assignments") @Data @NoArgsConstructor @AllArgsConstructor public class Assignment { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String title; @Column(length = 1000) private String description; @Column(name = "due_date") private LocalDateTime dueDate; @Column(name = "total_marks") private Double totalMarks; @Column(name = "file_path") private String filePath; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id", nullable = false) private Course course; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "teacher_id") private Teacher createdBy; @Column(name = "created_at") private LocalDateTime createdAt; @Column(name = "updated_at") private LocalDateTime updatedAt; @PrePersist protected void onCreate() { createdAt = LocalDateTime.now(); updatedAt = createdAt; } @PreUpdate protected void onUpdate() { updatedAt = LocalDateTime.now(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public LocalDateTime getDueDate() { return dueDate; } public void setDueDate(LocalDateTime dueDate) { this.dueDate = dueDate; } public Double getTotalMarks() { return totalMarks; } public void setTotalMarks(Double totalMarks) { this.totalMarks = totalMarks; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public Teacher getCreatedBy() { return createdBy; } public void setCreatedBy(Teacher createdBy) { this.createdBy = createdBy; } public LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } public LocalDateTime getUpdatedAt() { return updatedAt; } public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } public Assignment(Long id, String title, String description, LocalDateTime dueDate, Double totalMarks, String filePath, Course course, Teacher createdBy, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.title = title; this.description = description; this.dueDate = dueDate; this.totalMarks = totalMarks; this.filePath = filePath; this.course = course; this.createdBy = createdBy; this.createdAt = createdAt; this.updatedAt = updatedAt; } public Assignment() { } } package com.example.Tutionbackend.Courses.Model; import java.time.LocalDateTime; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Entity @Table(name = "curriculum_items") @Data @NoArgsConstructor @AllArgsConstructor public class Curriculum { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String title; @Column(length = 1000) private String description; private Integer sequence; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id", nullable = false) private Course course; @Column(name = "created_at") private java.time.LocalDateTime createdAt; @Column(name = "updated_at") private java.time.LocalDateTime updatedAt; @PrePersist protected void onCreate() { createdAt = java.time.LocalDateTime.now(); updatedAt = createdAt; } @PreUpdate protected void onUpdate() { updatedAt = java.time.LocalDateTime.now(); } public Curriculum(Long id, String title, String description, Integer sequence, Course course, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.title = title; this.description = description; this.sequence = sequence; this.course = course; this.createdAt = createdAt; this.updatedAt = updatedAt; } public Curriculum() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Integer getSequence() { return sequence; } public void setSequence(Integer sequence) { this.sequence = sequence; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public java.time.LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(java.time.LocalDateTime createdAt) { this.createdAt = createdAt; } public java.time.LocalDateTime getUpdatedAt() { return updatedAt; } public void setUpdatedAt(java.time.LocalDateTime updatedAt) { this.updatedAt = updatedAt; } } package com.example.Tutionbackend.Courses.Model; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; import com.example.Tutionbackend.Teacher.Model.Teacher; @Entity @Table(name = "exams") @Data @NoArgsConstructor @AllArgsConstructor public class Exam { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String title; @Column(length = 1000) private String description; @Column(name = "exam_date") private LocalDateTime examDate; @Column(name = "duration_minutes") private Integer durationMinutes; @Column(name = "total_marks") private Double totalMarks; @Column(name = "passing_marks") private Double passingMarks; @Enumerated(EnumType.STRING) private ExamType examType; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id", nullable = false) private Course course; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "teacher_id") private Teacher createdBy; @Column(name = "created_at") private LocalDateTime createdAt; @Column(name = "updated_at") private LocalDateTime updatedAt; public enum ExamType { QUIZ, MID_TERM, FINAL, PRACTICAL, OTHER } @PrePersist protected void onCreate() { createdAt = LocalDateTime.now(); updatedAt = createdAt; } @PreUpdate protected void onUpdate() { updatedAt = LocalDateTime.now(); } public Exam(Long id, String title, String description, LocalDateTime examDate, Integer durationMinutes, Double totalMarks, Double passingMarks, ExamType examType, Course course, Teacher createdBy, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.title = title; this.description = description; this.examDate = examDate; this.durationMinutes = durationMinutes; this.totalMarks = totalMarks; this.passingMarks = passingMarks; this.examType = examType; this.course = course; this.createdBy = createdBy; this.createdAt = createdAt; this.updatedAt = updatedAt; } public Exam() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public LocalDateTime getExamDate() { return examDate; } public void setExamDate(LocalDateTime examDate) { this.examDate = examDate; } public Integer getDurationMinutes() { return durationMinutes; } public void setDurationMinutes(Integer durationMinutes) { this.durationMinutes = durationMinutes; } public Double getTotalMarks() { return totalMarks; } public void setTotalMarks(Double totalMarks) { this.totalMarks = totalMarks; } public Double getPassingMarks() { return passingMarks; } public void setPassingMarks(Double passingMarks) { this.passingMarks = passingMarks; } public ExamType getExamType() { return examType; } public void setExamType(ExamType examType) { this.examType = examType; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public Teacher getCreatedBy() { return createdBy; } public void setCreatedBy(Teacher createdBy) { this.createdBy = createdBy; } public LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } public LocalDateTime getUpdatedAt() { return updatedAt; } public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } } package com.example.Tutionbackend.Courses.Model; import java.time.LocalDateTime; import com.example.Tutionbackend.Teacher.Model.Teacher; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Entity @Table(name = "materials") @Data @NoArgsConstructor @AllArgsConstructor public class Material { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String title; @Column(length = 1000) private String description; @Column(name = "file_path") private String filePath; @Column(name = "file_type") private String fileType; @Column(name = "file_size") private Long fileSize; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id", nullable = false) private Course course; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "teacher_id") private Teacher uploadedBy; @Column(name = "upload_date") private java.time.LocalDateTime uploadDate; @Column(name = "created_at") private java.time.LocalDateTime createdAt; @Column(name = "updated_at") private java.time.LocalDateTime updatedAt; @PrePersist protected void onCreate() { createdAt = java.time.LocalDateTime.now(); updatedAt = createdAt; uploadDate = createdAt; } @PreUpdate protected void onUpdate() { updatedAt = java.time.LocalDateTime.now(); } public Material(Long id, String title, String description, String filePath, String fileType, Long fileSize, Course course, Teacher uploadedBy, LocalDateTime uploadDate, LocalDateTime createdAt, LocalDateTime updatedAt) { this.id = id; this.title = title; this.description = description; this.filePath = filePath; this.fileType = fileType; this.fileSize = fileSize; this.course = course; this.uploadedBy = uploadedBy; this.uploadDate = uploadDate; this.createdAt = createdAt; this.updatedAt = updatedAt; } public Material() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public String getFileType() { return fileType; } public void setFileType(String fileType) { this.fileType = fileType; } public Long getFileSize() { return fileSize; } public void setFileSize(Long fileSize) { this.fileSize = fileSize; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public Teacher getUploadedBy() { return uploadedBy; } public void setUploadedBy(Teacher uploadedBy) { this.uploadedBy = uploadedBy; } public java.time.LocalDateTime getUploadDate() { return uploadDate; } public void setUploadDate(java.time.LocalDateTime uploadDate) { this.uploadDate = uploadDate; } public java.time.LocalDateTime getCreatedAt() { return createdAt; } public void setCreatedAt(java.time.LocalDateTime createdAt) { this.createdAt = createdAt; } public java.time.LocalDateTime getUpdatedAt() { return updatedAt; } public void setUpdatedAt(java.time.LocalDateTime updatedAt) { this.updatedAt = updatedAt; } } give me all pages in nextjs i have already projects setup
I'll create a comprehensive Next.js frontend for your course management system that connects to your Spring Boot backend. Based on the backend code you've shared, I'll implement pages for courses, materials, assignments, exams, and curriculum.