1 | package edu.ucsb.cs156.frontiers.controllers; | |
2 | ||
3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
4 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
6 | ||
7 | import edu.ucsb.cs156.frontiers.entities.Instructor; | |
8 | import edu.ucsb.cs156.frontiers.repositories.InstructorRepository; | |
9 | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | |
11 | import org.springframework.http.ResponseEntity; | |
12 | import org.springframework.security.access.prepost.PreAuthorize; | |
13 | import org.springframework.web.bind.annotation.GetMapping; | |
14 | import org.springframework.web.bind.annotation.PostMapping; | |
15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
16 | import org.springframework.web.bind.annotation.RequestMapping; | |
17 | import org.springframework.web.bind.annotation.RequestParam; | |
18 | import org.springframework.web.bind.annotation.RestController; | |
19 | ||
20 | import io.swagger.v3.oas.annotations.Operation; | |
21 | import io.swagger.v3.oas.annotations.tags.Tag; | |
22 | import io.swagger.v3.oas.annotations.Parameter; | |
23 | import lombok.extern.slf4j.Slf4j; | |
24 | ||
25 | @Tag(name = "Instructors") | |
26 | @RequestMapping("/api/instructors") | |
27 | @RestController | |
28 | @Slf4j | |
29 | ||
30 | public class InstructorsController extends ApiController{ | |
31 | ||
32 | @Autowired | |
33 | InstructorRepository instructorRepository; | |
34 | ||
35 | /** | |
36 | * This method creates a new instructor. Accessible only to users with the role "ROLE_ADMIN". | |
37 | * @param email email of the the instructor | |
38 | * @return the new instructor | |
39 | */ | |
40 | @Operation(summary= "Add a new Instructor") | |
41 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
42 | @PostMapping("/post") | |
43 | public Instructor postInstructor( | |
44 | @Parameter(name="email") @RequestParam String email | |
45 | ) | |
46 | { | |
47 | ||
48 | Instructor instructor = new Instructor(email); | |
49 | ||
50 | Instructor savedInstructor = instructorRepository.save(instructor); | |
51 | ||
52 |
1
1. postInstructor : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorsController::postInstructor → KILLED |
return savedInstructor; |
53 | } | |
54 | ||
55 | /** | |
56 | * THis method returns a list of all instructors. | |
57 | * @return a list of all instructors | |
58 | */ | |
59 | @Operation(summary= "List all Instructors") | |
60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
61 | @GetMapping("/all") | |
62 | public Iterable<Instructor> allInstructors() { | |
63 | Iterable<Instructor> instructors = instructorRepository.findAll(); | |
64 |
1
1. allInstructors : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/InstructorsController::allInstructors → KILLED |
return instructors; |
65 | } | |
66 | ||
67 | /** | |
68 | * This method deletes an instructor. Accessible only to users with the role "ROLE_ADMIN". | |
69 | * @param email email of the instructor | |
70 | * @return a message indicating the instructor was deleted | |
71 | * */ | |
72 | ||
73 | @Operation(summary= "Delete an Instructor") | |
74 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
75 | @DeleteMapping("") | |
76 | public Object deleteInstructor( | |
77 | @Parameter(name="email") @RequestParam String email) { | |
78 | Instructor instructor = instructorRepository.findById(email) | |
79 |
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)); |
80 |
1
1. deleteInstructor : removed call to edu/ucsb/cs156/frontiers/repositories/InstructorRepository::delete → KILLED |
instructorRepository.delete(instructor); |
81 |
1
1. deleteInstructor : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorsController::deleteInstructor → KILLED |
return genericMessage("Instructor with id %s deleted".formatted(email)); |
82 | } | |
83 | ||
84 | } | |
Mutations | ||
52 |
1.1 |
|
64 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |