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