1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
7 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
8 | ||
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.format.annotation.DateTimeFormat; | |
18 | import org.springframework.security.access.prepost.PreAuthorize; | |
19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
20 | import org.springframework.web.bind.annotation.GetMapping; | |
21 | import org.springframework.web.bind.annotation.PostMapping; | |
22 | import org.springframework.web.bind.annotation.PutMapping; | |
23 | import org.springframework.web.bind.annotation.RequestBody; | |
24 | import org.springframework.web.bind.annotation.RequestMapping; | |
25 | import org.springframework.web.bind.annotation.RequestParam; | |
26 | import org.springframework.web.bind.annotation.RestController; | |
27 | ||
28 | import jakarta.validation.Valid; | |
29 | ||
30 | import java.time.LocalDateTime; | |
31 | ||
32 | @Tag(name = "HelpRequest") // Does this have to be plural? | |
33 | @RequestMapping("/api/helprequest") | |
34 | @RestController | |
35 | @Slf4j | |
36 | ||
37 | public class HelpRequestController extends ApiController{ | |
38 | @Autowired | |
39 | HelpRequestRepository helpRequestRepository; | |
40 | ||
41 | @Operation(summary= "List all help requests") | |
42 | @PreAuthorize("hasRole('ROLE_USER')") | |
43 | @GetMapping("/all") | |
44 | public Iterable<HelpRequest> allHelpRequests() { | |
45 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
46 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
47 | } | |
48 | ||
49 | @Operation(summary= "GET (show) a single record in the table") | |
50 | @PreAuthorize("hasRole('ROLE_USER')") | |
51 | @GetMapping("") | |
52 | public HelpRequest getById( | |
53 | @Parameter(name="id") @RequestParam Long id) { | |
54 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
55 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
56 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
57 | } | |
58 | ||
59 | @Operation(summary= "Create a new request") | |
60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
61 | @PostMapping("/post") | |
62 | public HelpRequest postHelpRequest( | |
63 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
64 | @Parameter(name="teamId") @RequestParam String teamId, | |
65 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
66 | @Parameter(name="requestTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime, | |
67 | @Parameter(name="explanation") @RequestParam String explanation, | |
68 | @Parameter(name="solved") @RequestParam boolean solved) | |
69 | throws JsonProcessingException { | |
70 | ||
71 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
72 | // See: https://www.baeldung.com/spring-date-parameters | |
73 | ||
74 | log.info("requestTime={}", requestTime); | |
75 | ||
76 | // HelpRequest helpRequest = new HelpRequest(); | |
77 | // helpRequest.setRequesterEmail(requesterEmail); // This part is failing pitest | |
78 | // helpRequest.setTeamId(teamId); | |
79 | // helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); | |
80 | // helpRequest.setRequestTime(requestTime); | |
81 | // helpRequest.setExplanation(explanation); | |
82 | // helpRequest.setSolved(solved); | |
83 | ||
84 | // Using a builder works with pitest mutation coverage | |
85 | HelpRequest helpRequest = HelpRequest.builder() | |
86 | .requesterEmail(requesterEmail) | |
87 | .teamId(teamId) | |
88 | .tableOrBreakoutRoom(tableOrBreakoutRoom) | |
89 | .requestTime(requestTime) | |
90 | .explanation(explanation) | |
91 | .solved(solved) | |
92 | .build(); | |
93 | | |
94 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
95 | ||
96 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
97 | } | |
98 | ||
99 | @Operation(summary= "Delete a single record from the table") | |
100 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
101 | @DeleteMapping("") | |
102 | public Object deleteHelpRequest( | |
103 | @Parameter(name="id") @RequestParam Long id) { | |
104 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
105 |
1
1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
106 | ||
107 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
108 |
1
1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED |
return genericMessage("HelpRequest with id %s deleted".formatted(id)); |
109 | } | |
110 | | |
111 | @Operation(summary= "Update a single record in the table") | |
112 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
113 | @PutMapping("") | |
114 | public HelpRequest updateHelpRequest( | |
115 | @Parameter(name="id") @RequestParam Long id, | |
116 | @RequestBody @Valid HelpRequest incoming) { | |
117 | ||
118 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
119 |
1
1. lambda$updateHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
120 | ||
121 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
122 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
123 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
124 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
125 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
126 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
127 | ||
128 | helpRequestRepository.save(helpRequest); | |
129 | ||
130 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
131 | } | |
132 | ||
133 | ||
134 | } | |
Mutations | ||
46 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
96 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
130 |
1.1 |