| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Instructor; | |
| 4 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.frontiers.repositories.InstructorRepository; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.web.bind.annotation.*; | |
| 13 | ||
| 14 | @Tag(name = "Instructors") | |
| 15 | @RequestMapping("/api/instructors") | |
| 16 | @RestController | |
| 17 | @Slf4j | |
| 18 | public class InstructorsController extends ApiController { | |
| 19 | ||
| 20 | @Autowired | |
| 21 | private InstructorRepository instructorRepository; | |
| 22 | ||
| 23 | // POST | |
| 24 | @Operation(summary = "Create a new instructor") | |
| 25 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 26 | @PostMapping("/post") | |
| 27 | public Instructor postInstructor( | |
| 28 | @Parameter(name = "email") @RequestParam String email) { | |
| 29 | ||
| 30 | Instructor instructor = Instructor.builder().email(email).build(); | |
| 31 |
1
1. postInstructor : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorsController::postInstructor → KILLED |
return instructorRepository.save(instructor); |
| 32 | } | |
| 33 | ||
| 34 | // GET | |
| 35 | @Operation(summary = "Get all instructors") | |
| 36 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 37 | @GetMapping("/all") | |
| 38 | public Iterable<Instructor> allInstructors() { | |
| 39 |
1
1. allInstructors : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/InstructorsController::allInstructors → KILLED |
return instructorRepository.findAll(); |
| 40 | } | |
| 41 | ||
| 42 | // DELETE | |
| 43 | @Operation(summary = "Delete instructor by email") | |
| 44 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 45 | @DeleteMapping("") | |
| 46 | public String deleteInstructor( | |
| 47 | @Parameter(name = "email") @RequestParam String email) { | |
| 48 | ||
| 49 | Instructor instructor = instructorRepository.findById(email) | |
| 50 |
1
1. lambda$deleteInstructor$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorsController::lambda$deleteInstructor$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Instructor.class, email)); |
| 51 |
1
1. deleteInstructor : removed call to edu/ucsb/cs156/frontiers/repositories/InstructorRepository::delete → KILLED |
instructorRepository.delete(instructor); |
| 52 |
1
1. deleteInstructor : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/InstructorsController::deleteInstructor → KILLED |
return String.format("Instructor with email %s deleted", email); |
| 53 | } | |
| 54 | } | |
Mutations | ||
| 31 |
1.1 |
|
| 39 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 52 |
1.1 |