Class StudentService
java.lang.Object
org.codewithmagret.rest.student.StudentService
Service class for handling business logic related to Student entities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddStudent(Student student) Adds a new student to the repository.booleandeleteStudent(Long id) Deletes a student by its ID.enrollStudentInCourse(Long studentId, Long courseId) Enrolls a student in a course.getStudentById(Long id) Retrieves a student by its ID.Retrieves all students from the repository.unenrollStudentFromCourse(Long studentId, Long courseId) Unenrolls a student from a course.updateStudent(Long id, Student studentToUpdate) Updates an existing student in the repository.
-
Constructor Details
-
StudentService
public StudentService()Default constructor for StudentService.
-
-
Method Details
-
getStudents
-
getStudentById
-
addStudent
-
updateStudent
-
deleteStudent
Deletes a student by its ID.- Parameters:
id- the ID of the student to delete- Returns:
- true if the student was deleted, false if the student was not found
-
enrollStudentInCourse
Enrolls a student in a course.- Parameters:
studentId- the ID of the student to enrollcourseId- the ID of the course to enroll the student in- Returns:
- the updated Student object if both the student and course were found and enrollment was successful, or null if either was not found
-
unenrollStudentFromCourse
Unenrolls a student from a course.- Parameters:
studentId- the ID of the student to unenrollcourseId- the ID of the course to unenroll the student from- Returns:
- the updated Student object if both the student and course were found and unenrollment was successful, or null if either was not found
-