package com.studentcrudoperation.Controller; import java.util.List; import com.studentcrudoperation.Model.Course; import com.studentcrudoperation.Service.CourseService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.beans.factory.annotation.Autowired; @RestController public class CourseController { @Autowired CourseService courseService; @GetMapping("/courses") public List<Course> getAllStudents() { return this.courseService.getAllCourses(); } @GetMapping("/courses/{id}") public Course getCourseByID(@PathVariable("id") int cid) { return this.courseService.getCourseByID(cid); } @PostMapping("/courses") public Course addCourse(@RequestBody Course course) { Course co = this.courseService.addCourse(course); return co; } @PutMapping("/courses/{courseId}") public Course updateCourse(@RequestBody Course course, @PathVariable("courseId")int courseId) { this.courseService.updateCourse(course, courseId); return course; } @DeleteMapping("/courses/{courseId}") public void deleteCourse(@PathVariable("courseId") int courseId) { this.courseService.deleteCourseById(courseId); } }