Commit 490fd3b0 authored by Muhammad Suleman's avatar Muhammad Suleman

Added Upload Marks Feature

parent f5443341
......@@ -31,16 +31,12 @@ public class TeacherController {
@PostMapping("/upload/marks")
public void addAssessment(@RequestBody AddAssessmentDTO addAssessmentDTO){
uploadMarksService.setAssessment(addAssessmentDTO).getAssessmentId();
uploadMarksService.setAssessment(addAssessmentDTO);
}
@PostMapping("/upload/marks/section")
public void addSectionInAssessment(@RequestBody AddSectionDTO addSectionDTO) {
uploadMarksService.setSection(addSectionDTO);
@PostMapping("/upload/marks/assessments")
public void addMarks(@RequestBody UploadMarksDTO uploadMarksDTO){
uploadMarksService.setObtainedMarks(uploadMarksDTO);
}
@PostMapping("/upload/marks/section/assessment")
public void setStudentMarks(@RequestBody UploadMarksDTO uploadMarksDTO) {
uploadMarksService.setMarks(uploadMarksDTO);
}
}
......@@ -3,13 +3,11 @@ package com.school.project.dto.teacher;
import lombok.Getter;
import lombok.Setter;
import java.nio.file.LinkOption;
@Getter
@Setter
public class AddSectionDTO {
public class ObtainedMarksDTO {
private String studentRollNumber;
private Long obtainedMarks;
private Long assessmentId;
private Long totalMarks;
private Long totalWeightage;
}
package com.school.project.dto.teacher;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class SectionsDTO {
private Long sectionId;
private Long marks;
private Long weightage;
private List<ObtainedMarksDTO> obtainedMarksDTOS;
}
package com.school.project.dto.teacher;
import com.school.project.model.marks.Section;
import lombok.Getter;
import lombok.Setter;
......@@ -11,8 +12,7 @@ import java.util.Set;
@Setter
public class UploadMarksDTO {
private Long sectionId;
private List<String> studentRollNumbers;
private List<Long> obtainedMarks;
private Long assessmentId;
private List<SectionsDTO> sectionsList;
}
package com.school.project.mapper;
import com.school.project.model.marks.Assessment;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class AssessmentToListOfAssessment {
public List<Assessment> modelToList(Assessment assessment) {
List<Assessment> assessmentList = new ArrayList<>();
assessmentList.add(assessment);
return assessmentList;
}
}
......@@ -40,7 +40,10 @@ public class Course {
@JsonIgnore
private Set<Teacher> teacherList;
@OneToMany(mappedBy = "course",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JsonIgnore
private List<Assessment> assessment;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "courses_assessments",
joinColumns = {@JoinColumn(name = "course_id",insertable = false,updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "assessment_id",insertable = false,updatable = false)})
private List<Assessment> assessments;
}
......@@ -55,9 +55,11 @@ public class Student {
@JsonIgnore
private User studentAppUser;
@OneToMany(mappedBy = "student",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "student_obtained_marks",
joinColumns = {@JoinColumn(name = "student_id",insertable = false,updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "student_marks_id",insertable = false,updatable = false)})
@JsonIgnore
private List<StudentMarks> studentMarks;
private Set<StudentMarks> studentMarks;
}
......@@ -6,11 +6,9 @@ import com.school.project.model.Course;
import com.sun.istack.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
@Getter
@Setter
......@@ -29,15 +27,18 @@ public class Assessment {
private AssessmentType assessmentType;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "course_assessments",
@JoinTable(name = "courses_assessments",
joinColumns = {@JoinColumn(name = "assessment_id")},
inverseJoinColumns = {@JoinColumn(name = "course_id")})
@NotNull
@JsonIgnore
private Course course;
@OneToMany(mappedBy = "assessment",fetch = FetchType.LAZY)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "assessment_sections",
joinColumns = {@JoinColumn(name = "assessment_id",insertable = false,updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "section_id",insertable = false,updatable = false)})
@JsonIgnore
private List<Section> section;
}
......@@ -6,6 +6,7 @@ import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.List;
import java.util.Set;
@Getter
......@@ -31,12 +32,17 @@ public class Section {
@JoinTable(name = "assessment_sections",
joinColumns = {@JoinColumn(name = "section_id")},
inverseJoinColumns = {@JoinColumn(name = "assessment_id")})
@NotNull
@JsonIgnore
private Assessment assessment;
@OneToMany(mappedBy = "section",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "student_marks_section",
joinColumns = {@JoinColumn(name = "section_id",insertable = false,updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "student_marks_id",insertable = false,updatable = false)})
@JsonIgnore
private Set<StudentMarks> studentMarks;
private List<StudentMarks> studentMarks;
}
......@@ -21,13 +21,17 @@ public class StudentMarks {
@Column(name = "obtained_marks")
private Long obtainedMarks;
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name = "student_id")
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "student_obtained_marks",
joinColumns = {@JoinColumn(name = "student_marks_id")},
inverseJoinColumns = {@JoinColumn(name = "student_id")})
@NotNull
private Student student;
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name = "section_id")
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name = "student_marks_section",
joinColumns = {@JoinColumn(name = "student_marks_id")},
inverseJoinColumns = {@JoinColumn(name = "section_id")})
@NotNull
private Section section;
}
......@@ -4,4 +4,5 @@ import com.school.project.model.marks.Section;
import org.springframework.data.jpa.repository.JpaRepository;
public interface SectionRepository extends JpaRepository<Section,Long> {
}
package com.school.project.service.teacher;
import com.school.project.dto.teacher.AddAssessmentDTO;
import com.school.project.dto.teacher.AddSectionDTO;
import com.school.project.dto.teacher.ObtainedMarksDTO;
import com.school.project.dto.teacher.UploadMarksDTO;
import com.school.project.model.marks.Assessment;
import com.school.project.model.marks.Section;
import com.school.project.model.marks.StudentMarks;
import org.springframework.stereotype.Service;
@Service
public interface UploadMarksService {
Assessment setAssessment(AddAssessmentDTO assessmentDTO);
void setAssessment(AddAssessmentDTO assessmentDTO);
Section setSection(AddSectionDTO sectionDTO);
void setObtainedMarks(UploadMarksDTO uploadMarksDTO);
void setMarks(UploadMarksDTO marksDTO);
}
package com.school.project.service.teacher;
import com.school.project.dto.teacher.AddAssessmentDTO;
import com.school.project.dto.teacher.AddSectionDTO;
import com.school.project.dto.teacher.UploadMarksDTO;
import com.school.project.mapper.MarksToListOfMarks;
import com.school.project.mapper.SectionToListOfSectionMapper;
import com.school.project.mapper.AssessmentToListOfAssessment;
import com.school.project.model.Course;
import com.school.project.model.Student;
import com.school.project.model.marks.Assessment;
import com.school.project.model.marks.Section;
import com.school.project.model.marks.StudentMarks;
......@@ -15,7 +15,6 @@ import com.school.project.repository.marks.AssessmentTypeRepository;
import com.school.project.repository.marks.SectionRepository;
import com.school.project.repository.marks.StudentMarksRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
......@@ -25,6 +24,10 @@ public class UploadMarksServiceImpl implements UploadMarksService {
@Autowired
CourseRepository courseRepository;
@Autowired
StudentRepository studentRepository;
@Autowired
AssessmentTypeRepository assessmentTypeRepository;
......@@ -35,84 +38,58 @@ public class UploadMarksServiceImpl implements UploadMarksService {
SectionRepository sectionRepository;
@Autowired
StudentRepository studentRepository;
@Autowired
SectionToListOfSectionMapper sectionMapper;
StudentMarksRepository studentMarksRepository;
@Autowired
MarksToListOfMarks marksMapper;
AssessmentToListOfAssessment assessmentMapper;
@Autowired
StudentMarksRepository studentMarksRepository;
@Override
@Transactional
public Assessment setAssessment(AddAssessmentDTO assessmentDTO) {
public void setAssessment(AddAssessmentDTO assessmentDTO) {
Assessment assessment = new Assessment();
assessment.setAssessmentType(assessmentTypeRepository.findByAssessmentTypeName(
assessmentDTO.getAssessment()));
Course course = courseRepository.findByCourseCode(assessmentDTO.getCourseCode());
assessment.setAssessmentType(assessmentTypeRepository.findByAssessmentTypeName(assessmentDTO.getAssessment()));
assessment.setCourse(courseRepository.findByCourseCode(
assessmentDTO.getCourseCode()));
assessment.setCourse(course);
return assessmentRepository.save(assessment);
assessmentRepository.save(assessment);
}
@Override
@Transactional
@Modifying
public Section setSection(AddSectionDTO sectionDTO) {
Section section = new Section();
public void setObtainedMarks(UploadMarksDTO uploadMarksDTO) {
section.setAssessment(assessmentRepository.findByAssessmentId(sectionDTO.getAssessmentId()));
section.setTotalMarks(sectionDTO.getTotalMarks());
section.setTotalWeightage(sectionDTO.getTotalWeightage());
Assessment assessment = assessmentRepository.findByAssessmentId(uploadMarksDTO.getAssessmentId());
section = sectionRepository.save(section);
uploadMarksDTO.getSectionsList().forEach(sectionInList -> {
Assessment assessment = assessmentRepository.findByAssessmentId(sectionDTO.getAssessmentId());
assessment.setSection(sectionMapper.modelToList(section));
Section newSection = new Section();
return section;
}
newSection.setTotalMarks(sectionInList.getMarks());
newSection.setTotalWeightage(sectionInList.getWeightage());
newSection.setAssessment(assessment);
@Override
@Transactional
public void setMarks(UploadMarksDTO marksDTO) {
int marksSize = marksDTO.getObtainedMarks().size();
Section section = sectionRepository.findById(marksDTO.getSectionId()).get();
Section section = sectionRepository.save(newSection);
/* List<Student> studentsSet = new ArrayList<>();
List<Long> studentObtainedMarks = marksDTO.getObtainedMarks();
studentRollNumbers.forEach(studentRollNumber -> studentsSet.add(studentRepository.findByRollNumber(studentRollNumber)));
sectionInList.getObtainedMarksDTOS().forEach(obtainedMarksInList -> {
studentsSet.forEach(student -> {
StudentMarks studentMarks = new StudentMarks();
Student student = studentRepository.findByRollNumber(obtainedMarksInList.getStudentRollNumber());
studentMarks.setStudent(student);
studentMarks.setSection(section);
studentMarks =studentMarksRepository.save(studentMarks);
student.setStudentMarks(studentMarks);
});*/git
StudentMarks studentMarks = new StudentMarks();
for (int i = 0; i<marksDTO.getStudentRollNumbers().size() ;i++) {
StudentMarks studentMarks = new StudentMarks();
studentMarks.setObtainedMarks(obtainedMarksInList.getObtainedMarks());
studentMarks.setStudent(student);
studentMarks.setSection(section);
studentMarks.setSection(section);
studentMarks.setStudent(studentRepository.findByRollNumber(marksDTO.getStudentRollNumbers().get(i)));
studentMarksRepository.save(studentMarks);
if( i < marksDTO.getObtainedMarks().size() ) {
studentMarks.setObtainedMarks(marksDTO.getObtainedMarks().get(i));
} else {
studentMarks.setObtainedMarks(0l);
}
});
studentMarksRepository.save(studentMarks);
}
}
);
}
}
......@@ -2,7 +2,7 @@
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/school-portal
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.password=charlie123
spring.security.user.name= sulemantalpur6@gmail.com
......
Markdown is supported
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