CourseController.java
package edu.ucsb.cs156.happiercows.controllers;
import edu.ucsb.cs156.happiercows.entities.Course;
import edu.ucsb.cs156.happiercows.repositories.CourseRepository;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@Slf4j
@Tag(name = "Course")
@RequestMapping("/api/course")
@RestController
public class CourseController extends ApiController {
@Autowired
private CourseRepository courseRepository;
/**
* This method returns a list of all courses.
*
* @return a list of all courses
*/
@Operation(summary = "List all courses")
@PreAuthorize("hasRole('ROLE_USER')")
@GetMapping("/all")
public Iterable<Course> allOrganisations() {
Iterable<Course> courses = courseRepository.findAll();
return courses;
}
}