| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import jakarta.validation.Valid; | |
| 10 | import java.time.LocalDateTime; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.format.annotation.DateTimeFormat; | |
| 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 | /** This is a REST controller for HelpRequests. */ | |
| 25 | @Tag(name = "HelpRequests") | |
| 26 | @RequestMapping("/api/helprequests") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class HelpRequestController extends ApiController { | |
| 30 | ||
| 31 | @Autowired HelpRequestRepository helpRequestRepository; | |
| 32 | ||
| 33 | /** List all help requests. */ | |
| 34 | @Operation(summary = "List all help requests") | |
| 35 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 36 | @GetMapping("/all") | |
| 37 | public Iterable<HelpRequest> allHelpRequests() { | |
| 38 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
| 39 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Get a single HelpRequest by ID. | |
| 44 | * | |
| 45 | * @param id the ID of the HelpRequest | |
| 46 | * @return the HelpRequest with the given ID | |
| 47 | */ | |
| 48 | @Operation(summary = "Get a single help request by ID") | |
| 49 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 50 | @GetMapping("") | |
| 51 | public HelpRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 52 | HelpRequest helpRequest = | |
| 53 | helpRequestRepository | |
| 54 | .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 | ||
| 57 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
| 58 | } | |
| 59 | ||
| 60 | /** Create a new help request. */ | |
| 61 | @Operation(summary = "Create a new help request") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/post") | |
| 64 | public HelpRequest postHelpRequest( | |
| 65 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 66 | @Parameter(name = "teamId") @RequestParam String teamId, | |
| 67 | @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 68 | @Parameter(name = "requestTime") | |
| 69 | @RequestParam | |
| 70 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 71 | LocalDateTime requestTime, | |
| 72 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 73 | @Parameter(name = "solved") @RequestParam boolean solved) { | |
| 74 | ||
| 75 | HelpRequest request = new HelpRequest(); | |
| 76 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(requesterEmail); |
| 77 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
request.setTeamId(teamId); |
| 78 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
request.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 79 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
request.setRequestTime(requestTime); |
| 80 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
request.setExplanation(explanation); |
| 81 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
request.setSolved(solved); |
| 82 | ||
| 83 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return helpRequestRepository.save(request); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Update a single HelpRequest. | |
| 88 | * | |
| 89 | * @param id the ID of the HelpRequest to update | |
| 90 | * @param incoming the updated HelpRequest data | |
| 91 | * @return the updated HelpRequest | |
| 92 | */ | |
| 93 | @Operation(summary = "Update a single help request") | |
| 94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 95 | @PutMapping("") | |
| 96 | public HelpRequest updateHelpRequest( | |
| 97 | @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid HelpRequest incoming) { | |
| 98 | ||
| 99 | HelpRequest helpRequest = | |
| 100 | helpRequestRepository | |
| 101 | .findById(id) | |
| 102 |
1
1. lambda$updateHelpRequest$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 103 | ||
| 104 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 105 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 106 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 107 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 108 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 109 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.isSolved()); |
| 110 | ||
| 111 | helpRequestRepository.save(helpRequest); | |
| 112 | ||
| 113 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Delete a HelpRequest. | |
| 118 | * | |
| 119 | * @param id the ID of the HelpRequest to delete | |
| 120 | * @return a message indicating the HelpRequest was deleted | |
| 121 | */ | |
| 122 | @Operation(summary = "Delete a HelpRequest") | |
| 123 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 124 | @DeleteMapping("") | |
| 125 | public Object deleteHelpRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 126 | HelpRequest helpRequest = | |
| 127 | helpRequestRepository | |
| 128 | .findById(id) | |
| 129 |
1
1. lambda$deleteHelpRequest$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 130 | ||
| 131 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 132 | ||
| 133 |
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)); |
| 134 | } | |
| 135 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 55 |
1.1 |
|
| 57 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 83 |
1.1 |
|
| 102 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 129 |
1.1 |
|
| 131 |
1.1 |
|
| 133 |
1.1 |