| 1 | package edu.ucsb.cs.scaffold.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs.scaffold.entity.Instructor; | |
| 4 | import edu.ucsb.cs.scaffold.repository.InstructorRepository; | |
| 5 | import edu.ucsb.cs.scaffold.utilities.CanonicalFormConverter; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | import lombok.extern.slf4j.Slf4j; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.http.ResponseEntity; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 13 | import org.springframework.web.bind.annotation.GetMapping; | |
| 14 | import org.springframework.web.bind.annotation.PostMapping; | |
| 15 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 16 | import org.springframework.web.bind.annotation.RequestParam; | |
| 17 | import org.springframework.web.bind.annotation.RestController; | |
| 18 | ||
| 19 | @Tag(name = "Instructors") | |
| 20 | @RequestMapping("/api/admin/instructors") | |
| 21 | @RestController | |
| 22 | @Slf4j | |
| 23 | public class InstructorsController extends ApiController { | |
| 24 | ||
| 25 | @Autowired InstructorRepository instructorRepository; | |
| 26 | ||
| 27 | @Operation(summary = "Create a new Instructor") | |
| 28 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 29 | @PostMapping("/post") | |
| 30 | public Instructor postInstructor(@RequestParam String email) { | |
| 31 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(email).strip(); | |
| 32 | Instructor instructor = Instructor.builder().email(convertedEmail).build(); | |
| 33 | instructorRepository.save(instructor); | |
| 34 |
1
1. postInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::postInstructor → KILLED |
return instructor; |
| 35 | } | |
| 36 | ||
| 37 | @Operation(summary = "List all Instructors") | |
| 38 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 39 | @GetMapping("/get") | |
| 40 | public Iterable<Instructor> allInstructors() { | |
| 41 |
1
1. allInstructors : replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/InstructorsController::allInstructors → KILLED |
return instructorRepository.findAll(); |
| 42 | } | |
| 43 | ||
| 44 | @Operation(summary = "Delete an Instructor by email") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @DeleteMapping("/delete") | |
| 47 | public ResponseEntity<String> deleteInstructor(@RequestParam String email) { | |
| 48 | Instructor instructor = instructorRepository.findById(email).orElse(null); | |
| 49 |
1
1. deleteInstructor : negated conditional → KILLED |
if (instructor == null) { |
| 50 |
1
1. deleteInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED |
return ResponseEntity.status(404) |
| 51 | .body(String.format("Instructor with email %s not found.", email)); | |
| 52 | } | |
| 53 |
1
1. deleteInstructor : removed call to edu/ucsb/cs/scaffold/repository/InstructorRepository::delete → KILLED |
instructorRepository.delete(instructor); |
| 54 |
1
1. deleteInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED |
return ResponseEntity.status(200) |
| 55 | .body(String.format("Instructor with email %s deleted.", email)); | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 41 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |