Class CourseController

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

@RestController @RequestMapping("/api/v1/courses") public class CourseController extends Object
Controller for managing courses.
  • Constructor Details

    • CourseController

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

    • getCourses

      @GetMapping public List<Course> getCourses()
      Retrieves a list of all courses.
      Returns:
      A list of Course objects.
    • getCourseById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<Course> getCourseById(@PathVariable Long id)
      Retrieves a course by its ID.
      Parameters:
      id - The ID of the course to retrieve.
      Returns:
      A ResponseEntity containing the Course object if found, or a 404 Not Found status if not found.
    • addCourse

      @PostMapping public org.springframework.http.ResponseEntity<Course> addCourse(@RequestBody CourseCreateRequest req)
      Creates a new course.
      Parameters:
      req - The CourseCreateRequest object containing the data for the new course.
      Returns:
      A ResponseEntity containing the created Course object, or a 400 Bad Request status if the creation failed.
    • updateCourse

      @PutMapping("/{id}") public org.springframework.http.ResponseEntity<Course> updateCourse(@PathVariable Long id, @RequestBody CourseCreateRequest req)
      Updates an existing course.
      Parameters:
      id - The ID of the course to update.
      req - The CourseCreateRequest object containing the updated data for the course.
      Returns:
      A ResponseEntity containing the updated Course object if found and updated, or a 400 Bad Request status if the update failed.
    • deleteCourse

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteCourse(@PathVariable Long id)
      Deletes a course by its ID.
      Parameters:
      id - The ID of the course to delete.
      Returns:
      A ResponseEntity with a 204 No Content status if the deletion was successful, or a 404 Not Found status if the course was not found.