Class CourseService
java.lang.Object
org.codewithmagret.rest.course.CourseService
Service class for handling business logic related to Course entities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a new course to the repository.booleandeleteCourse(Long id) Deletes a course by its ID.getCourseById(Long id) Retrieves a course by its ID.Retrieves all courses from the repository.updateCourse(Long id, CourseCreateRequest req) Updates an existing course in the repository.
-
Constructor Details
-
CourseService
public CourseService()Default constructor for CourseService.
-
-
Method Details
-
getCourses
-
getCourseById
-
addCourse
Adds a new course to the repository.- Parameters:
req- the CourseCreateRequest object containing the data for the new course- Returns:
- the saved Course object, or null if the category or instructor was not found
-
updateCourse
Updates an existing course in the repository.- Parameters:
id- the ID of the course to updatereq- the CourseCreateRequest object containing the updated data for the course- Returns:
- the updated Course object if found and updated, or null if the course, category, or instructor was not found
-
deleteCourse
Deletes a course by its ID.- Parameters:
id- the ID of the course to delete- Returns:
- true if the course was deleted, false if the course was not found
-