| 1 | package edu.ucsb.cs156.happiercows.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.happiercows.entities.Course; | |
| 4 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.happiercows.models.CourseDTO; | |
| 6 | import edu.ucsb.cs156.happiercows.repositories.CourseRepository; | |
| 7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 13 | import org.springframework.web.bind.annotation.*; | |
| 14 | ||
| 15 | @Slf4j | |
| 16 | @Tag(name = "Course") | |
| 17 | @RequestMapping("/api/course") | |
| 18 | @RestController | |
| 19 | public class CourseController extends ApiController { | |
| 20 | @Autowired | |
| 21 | private CourseRepository courseRepository; | |
| 22 | ||
| 23 | /** | |
| 24 | * This method returns a list of all courses. | |
| 25 | * | |
| 26 | * @return a list of all courses | |
| 27 | */ | |
| 28 | @Operation(summary = "List all courses") | |
| 29 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 30 | @GetMapping("/all") | |
| 31 | public Iterable<Course> allOrganisations() { | |
| 32 | Iterable<Course> courses = courseRepository.findAll(); | |
| 33 |
1
1. allOrganisations : replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/CourseController::allOrganisations → KILLED |
return courses; |
| 34 | } | |
| 35 | ||
| 36 | @Operation(summary = "Get a course by id") | |
| 37 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 38 | @GetMapping("/{id}") | |
| 39 | public Course getCourseById( | |
| 40 | @Parameter(name = "id") @PathVariable Long id) { | |
| 41 | Course course = courseRepository.findById(id) | |
| 42 |
1
1. lambda$getCourseById$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::lambda$getCourseById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, id)); |
| 43 |
1
1. getCourseById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::getCourseById → KILLED |
return course; |
| 44 | } | |
| 45 | ||
| 46 | @Operation(summary = "Create a course") | |
| 47 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 48 | @PostMapping("") | |
| 49 | public Course postCourse( | |
| 50 | @Parameter(name = "course") @RequestBody CourseDTO courseDTO) { | |
| 51 | Course savedCourse = courseRepository.save(courseDTO.toCourse()); | |
| 52 |
1
1. postCourse : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/CourseController::postCourse → KILLED |
return savedCourse; |
| 53 | } | |
| 54 | } | |
Mutations | ||
| 33 |
1.1 |
|
| 42 |
1.1 |
|
| 43 |
1.1 |
|
| 52 |
1.1 |