| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 7 | import io.swagger.v3.oas.annotations.Operation; | |
| 8 | import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 10 | import jakarta.validation.Valid; | |
| 11 | import java.time.LocalDateTime; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | /** This is a REST controller for HelpRequests */ | |
| 26 | @Tag(name = "HelpRequest") | |
| 27 | @RequestMapping("/api/helprequests") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class HelpRequestController extends ApiController { | |
| 31 | ||
| 32 | @Autowired HelpRequestRepository helpRequestRepository; | |
| 33 | ||
| 34 | /** | |
| 35 | * List all Help Requests | |
| 36 | * | |
| 37 | * @return an iterable of HelpRequest | |
| 38 | */ | |
| 39 | @Operation(summary = "List all help requests") | |
| 40 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 41 | @GetMapping("/all") | |
| 42 | public Iterable<HelpRequest> allHelpRequests() { | |
| 43 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
| 44 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * @param id the id of the help request | |
| 49 | * @return a HelpRequest | |
| 50 | */ | |
| 51 | @Operation(summary = "Get a single help request") | |
| 52 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 53 | @GetMapping("") | |
| 54 | public HelpRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 55 | HelpRequest helpRequest = | |
| 56 | helpRequestRepository | |
| 57 | .findById(id) | |
| 58 |
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)); |
| 59 | ||
| 60 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * @param requesterEmail The email of the requester | |
| 65 | * @param teamId The teamId of the requester | |
| 66 | * @param tableOrBreakoutRoom The table or breakout room of the requester | |
| 67 | * @param explanation An explanation detailing the contents of the request | |
| 68 | * @param solved Value indicating whether the request has been solved | |
| 69 | * @param requestTime The date and time the request was made | |
| 70 | * @return The saved helprequest | |
| 71 | */ | |
| 72 | @Operation(summary = "Create a new help request") | |
| 73 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 74 | @PostMapping("/post") | |
| 75 | public HelpRequest postHelpRequest( | |
| 76 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 77 | @Parameter(name = "teamId") @RequestParam String teamId, | |
| 78 | @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 79 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 80 | @Parameter(name = "solved") @RequestParam boolean solved, | |
| 81 | @Parameter( | |
| 82 | name = "requestTime", | |
| 83 | description = | |
| 84 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 85 | @RequestParam("requestTime") | |
| 86 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 87 | LocalDateTime requestTime) | |
| 88 | throws JsonProcessingException { | |
| 89 | ||
| 90 | log.info("localDateTime={}", requestTime); | |
| 91 | ||
| 92 | HelpRequest helpRequest = new HelpRequest(); | |
| 93 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 94 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 95 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 96 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 97 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 98 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 99 | ||
| 100 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 101 | ||
| 102 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Update a single help request | |
| 107 | * | |
| 108 | * @param id id of the date to update | |
| 109 | * @param incoming the new date | |
| 110 | * @return the updated help request object | |
| 111 | */ | |
| 112 | @Operation(summary = "Update a single Help Request") | |
| 113 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 114 | @PutMapping("") | |
| 115 | public HelpRequest updateHelpRequest( | |
| 116 | @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid HelpRequest incoming) { | |
| 117 | ||
| 118 | HelpRequest helpRequest = | |
| 119 | helpRequestRepository | |
| 120 | .findById(id) | |
| 121 |
1
1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 122 | ||
| 123 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 124 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 125 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 126 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 127 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 128 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 129 | ||
| 130 | helpRequestRepository.save(helpRequest); | |
| 131 | ||
| 132 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Delete a help request | |
| 137 | * | |
| 138 | * @param id the id of the help request to delete | |
| 139 | * @return a message indicating the help request was deleted | |
| 140 | */ | |
| 141 | @Operation(summary = "Delete a Help Request") | |
| 142 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 143 | @DeleteMapping("") | |
| 144 | public Object deleteHelpRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 145 | HelpRequest helpRequest = | |
| 146 | helpRequestRepository | |
| 147 | .findById(id) | |
| 148 |
1
1. lambda$deleteHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 149 | ||
| 150 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 151 |
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)); |
| 152 | } | |
| 153 | } | |
Mutations | ||
| 44 |
1.1 |
|
| 58 |
1.1 |
|
| 60 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 102 |
1.1 |
|
| 121 |
1.1 |
|
| 123 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 132 |
1.1 |
|
| 148 |
1.1 |
|
| 150 |
1.1 |
|
| 151 |
1.1 |