1 | package edu.ucsb.cs156.frontiers.controllers; | |
2 | ||
3 | ||
4 | import org.springframework.beans.factory.annotation.Autowired; | |
5 | import org.springframework.beans.factory.annotation.Value; | |
6 | import org.springframework.data.domain.Sort; | |
7 | import org.springframework.security.access.prepost.PreAuthorize; | |
8 | import org.springframework.web.bind.annotation.DeleteMapping; | |
9 | import org.springframework.web.bind.annotation.GetMapping; | |
10 | import org.springframework.web.bind.annotation.PostMapping; | |
11 | import org.springframework.web.bind.annotation.RequestMapping; | |
12 | import org.springframework.web.bind.annotation.RequestParam; | |
13 | import org.springframework.web.bind.annotation.RestController; | |
14 | ||
15 | import com.fasterxml.jackson.core.JsonProcessingException; | |
16 | ||
17 | import edu.ucsb.cs156.frontiers.entities.Instructor; | |
18 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
19 | import edu.ucsb.cs156.frontiers.repositories.InstructorRepository; | |
20 | import io.swagger.v3.oas.annotations.Operation; | |
21 | import io.swagger.v3.oas.annotations.Parameter; | |
22 | import io.swagger.v3.oas.annotations.tags.Tag; | |
23 | import lombok.extern.slf4j.Slf4j; | |
24 | ||
25 | @Tag(name = "Instructors") | |
26 | @RequestMapping("/api/admin/instructors") | |
27 | @RestController | |
28 | @Slf4j | |
29 | public class InstructorController extends ApiController{ | |
30 | @Autowired | |
31 | InstructorRepository instructorRepository; | |
32 | ||
33 | @Operation(summary= "List all instructors") | |
34 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
35 | @GetMapping("/all") | |
36 | public Iterable<Instructor> allInstructors() { | |
37 |
1
1. allInstructors : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/InstructorController::allInstructors → KILLED |
return instructorRepository.findAll(Sort.by("email").ascending()); |
38 | } | |
39 | ||
40 | @Operation(summary= "Create a new instructor") | |
41 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
42 | @PostMapping("/post") | |
43 | public Instructor postInstructor( | |
44 | @Parameter(name="email") @RequestParam String email) | |
45 | throws JsonProcessingException { | |
46 | ||
47 | Instructor instructor = new Instructor(); | |
48 |
1
1. postInstructor : removed call to edu/ucsb/cs156/frontiers/entities/Instructor::setEmail → KILLED |
instructor.setEmail(email); |
49 | ||
50 | Instructor savedInstructor = instructorRepository.save(instructor); | |
51 | ||
52 |
1
1. postInstructor : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorController::postInstructor → KILLED |
return savedInstructor; |
53 | } | |
54 | ||
55 | @Operation(summary= "Delete an Instructor") | |
56 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
57 | @DeleteMapping("") | |
58 | public Object deleteInstructor(@Parameter(name="email") @RequestParam String email) { | |
59 | | |
60 | Instructor instructor = instructorRepository.findById(email) | |
61 |
1
1. lambda$deleteInstructor$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorController::lambda$deleteInstructor$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Instructor.class, email)); |
62 | ||
63 |
1
1. deleteInstructor : removed call to edu/ucsb/cs156/frontiers/repositories/InstructorRepository::delete → KILLED |
instructorRepository.delete(instructor); |
64 |
1
1. deleteInstructor : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/InstructorController::deleteInstructor → KILLED |
return genericMessage("Instructor with valid email is deleted".formatted(email)); |
65 | } | |
66 | } | |
Mutations | ||
37 |
1.1 |
|
48 |
1.1 |
|
52 |
1.1 |
|
61 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |