Class CourseService

java.lang.Object
org.codewithmagret.rest.course.CourseService

@Service public class CourseService extends Object
Service class for handling business logic related to Course entities.
  • Constructor Details

    • CourseService

      public CourseService()
      Default constructor for CourseService.
  • Method Details

    • getCourses

      public List<Course> getCourses()
      Retrieves all courses from the repository.
      Returns:
      a list of all courses
    • getCourseById

      public Course getCourseById(Long id)
      Retrieves a course by its ID.
      Parameters:
      id - the ID of the course to retrieve
      Returns:
      the Course object if found, or null if not found
    • addCourse

      public Course addCourse(CourseCreateRequest req)
      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

      public Course updateCourse(Long id, CourseCreateRequest req)
      Updates an existing course in the repository.
      Parameters:
      id - the ID of the course to update
      req - 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

      public boolean deleteCourse(Long id)
      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