1 | package edu.ucsb.cs156.rec.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.rec.entities.RequestType; | |
4 | import edu.ucsb.cs156.rec.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.rec.errors.EntityAlreadyExistsException; | |
6 | import edu.ucsb.cs156.rec.repositories.RequestTypeRepository; | |
7 | import edu.ucsb.cs156.rec.services.RequestTypeService; | |
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.security.access.prepost.PreAuthorize; | |
15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
16 | import org.springframework.web.bind.annotation.GetMapping; | |
17 | import org.springframework.web.bind.annotation.PostMapping; | |
18 | import org.springframework.web.bind.annotation.PutMapping; | |
19 | import org.springframework.web.bind.annotation.RequestBody; | |
20 | import org.springframework.web.bind.annotation.RequestMapping; | |
21 | import org.springframework.web.bind.annotation.RequestParam; | |
22 | import org.springframework.web.bind.annotation.RestController; | |
23 | ||
24 | import jakarta.validation.Valid; | |
25 | ||
26 | /** | |
27 | * This is a REST controller for Request Types | |
28 | */ | |
29 | ||
30 | @Tag(name = "RequestTypes") | |
31 | @RequestMapping("/api/requesttypes") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class RequestTypesController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | RequestTypeRepository requestTypeRepository; | |
38 | ||
39 | @Autowired | |
40 | RequestTypeService requestTypeService; | |
41 | ||
42 | /** | |
43 | * This method returns a list of all request types. | |
44 | * @return a list of all request types | |
45 | */ | |
46 | @Operation(summary = "List all request types") | |
47 | @PreAuthorize("hasRole('ROLE_USER')") | |
48 | @GetMapping("/all") | |
49 | public Iterable<RequestType> allRequestTypes() { | |
50 | Iterable<RequestType> requestTypes = requestTypeRepository.findAll(); | |
51 |
1
1. allRequestTypes : replaced return value with Collections.emptyList for edu/ucsb/cs156/rec/controllers/RequestTypesController::allRequestTypes → KILLED |
return requestTypes; |
52 | } | |
53 | ||
54 | /** | |
55 | * This method returns a single request type. | |
56 | * @param id id of the request type to get | |
57 | * @return a single request type | |
58 | */ | |
59 | @Operation(summary = "Get a single request type") | |
60 | @PreAuthorize("hasRole('ROLE_USER')") | |
61 | @GetMapping("") | |
62 | public RequestType getById( | |
63 | @Parameter(name = "id") @RequestParam Long id) { | |
64 | RequestType requestType = requestTypeRepository.findById(id) | |
65 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RequestType.class, id)); |
66 | ||
67 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::getById → KILLED |
return requestType; |
68 | } | |
69 | ||
70 | /** | |
71 | * This method creates a new request type. Accessible only to users with the role "ROLE_ADMIN" or "ROLE_INSTRUCTOR". | |
72 | * @param requestType description of the request type | |
73 | * @return the save request type (with it's id field set by the database) | |
74 | */ | |
75 | @Operation(summary = "Create a new request type") | |
76 | @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTRUCTOR')") | |
77 | @PostMapping("/post") | |
78 | public RequestType postRequestType( | |
79 | @Parameter(name = "requestType") @RequestParam String requestType) { | |
80 | | |
81 | RequestType savingRequestType = new RequestType(); | |
82 |
1
1. postRequestType : removed call to edu/ucsb/cs156/rec/entities/RequestType::setRequestType → KILLED |
savingRequestType.setRequestType(requestType); |
83 | ||
84 |
1
1. postRequestType : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::postRequestType → KILLED |
return requestTypeService.trySave(savingRequestType) |
85 |
1
1. lambda$postRequestType$1 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$postRequestType$1 → KILLED |
.orElseThrow(() -> new EntityAlreadyExistsException(RequestType.class, requestType)); |
86 | } | |
87 | ||
88 | /** | |
89 | * Deletes a request type. Accessible only to users with the role "ROLE_ADMIN". | |
90 | * @param id id of the request type to delete | |
91 | * @return a message indicating that the request type was deleted | |
92 | */ | |
93 | @Operation(summary = "Delete a Request Type") | |
94 | @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTRUCTOR')") | |
95 | @DeleteMapping("") | |
96 | public Object deleteRequestType( | |
97 | @Parameter(name = "id") @RequestParam Long id) { | |
98 | RequestType requestType = requestTypeRepository.findById(id) | |
99 |
1
1. lambda$deleteRequestType$2 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$deleteRequestType$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RequestType.class, id)); |
100 | ||
101 |
1
1. deleteRequestType : removed call to edu/ucsb/cs156/rec/repositories/RequestTypeRepository::delete → KILLED |
requestTypeRepository.delete(requestType); |
102 |
1
1. deleteRequestType : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::deleteRequestType → KILLED |
return genericMessage("RequestType with id %s deleted".formatted(id)); |
103 | } | |
104 | ||
105 | /** | |
106 | * Update a single request type. Accessible only to users with the role "ROLE_ADMIN". | |
107 | * @param id id of the request type to update | |
108 | * @param incoming the new request type contents | |
109 | * @return the updated request type object | |
110 | */ | |
111 | @Operation(summary = "Update a single request type") | |
112 | @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTRUCTOR')") | |
113 | @PutMapping("") | |
114 | public RequestType updateRequestType( | |
115 | @Parameter(name = "id") @RequestParam Long id, | |
116 | @RequestBody @Valid RequestType incoming) { | |
117 | ||
118 | RequestType requestType = requestTypeRepository.findById(id) | |
119 |
1
1. lambda$updateRequestType$3 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$updateRequestType$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RequestType.class, id)); |
120 | ||
121 |
1
1. updateRequestType : removed call to edu/ucsb/cs156/rec/entities/RequestType::setRequestType → KILLED |
requestType.setRequestType(incoming.getRequestType()); |
122 | | |
123 |
1
1. updateRequestType : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::updateRequestType → KILLED |
return requestTypeService.trySave(requestType) |
124 |
1
1. lambda$updateRequestType$4 : replaced return value with null for edu/ucsb/cs156/rec/controllers/RequestTypesController::lambda$updateRequestType$4 → KILLED |
.orElseThrow(() -> new EntityAlreadyExistsException(RequestType.class, incoming.getRequestType())); |
125 | } | |
126 | } | |
Mutations | ||
51 |
1.1 |
|
65 |
1.1 |
|
67 |
1.1 |
|
82 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |