Class CourseController
java.lang.Object
org.codewithmagret.rest.course.CourseController
Controller for managing courses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Course> Creates a new course.org.springframework.http.ResponseEntity<Void> deleteCourse(Long id) Deletes a course by its ID.org.springframework.http.ResponseEntity<Course> getCourseById(Long id) Retrieves a course by its ID.Retrieves a list of all courses.org.springframework.http.ResponseEntity<Course> updateCourse(Long id, CourseCreateRequest req) Updates an existing course.
-
Constructor Details
-
CourseController
public CourseController()Default constructor for CourseController.
-
-
Method Details
-
getCourses
-
getCourseById
-
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.
-