| 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 = "HelpRequests") | |
| 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> helpRequests = helpRequestRepository.findAll(); | |
| 44 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return helpRequests; |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Get a single help request by id | |
| 49 | * | |
| 50 | * @param id the id of the help request | |
| 51 | * @return a HelpRequest | |
| 52 | */ | |
| 53 | @Operation(summary = "Get a single help request") | |
| 54 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 55 | @GetMapping("") | |
| 56 | public HelpRequest getById( | |
| 57 | @Parameter(name = "id", description = "id of the help request") @RequestParam Long id) { | |
| 58 | HelpRequest helpRequest = | |
| 59 | helpRequestRepository | |
| 60 | .findById(id) | |
| 61 |
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)); |
| 62 | ||
| 63 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Create a new help request | |
| 68 | * | |
| 69 | * @param requesterEmail the email of the person requesting help | |
| 70 | * @param teamId the id of the requester's team | |
| 71 | * @param tableOrBreakoutRoom the table or breakout room where the requester can be found | |
| 72 | * @param requestTime the time the help was requested | |
| 73 | * @param explanation a description of what the requester needs help with | |
| 74 | * @param solved whether the request has been solved | |
| 75 | * @return the saved help request | |
| 76 | */ | |
| 77 | @Operation(summary = "Create a new help request") | |
| 78 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 79 | @PostMapping("/post") | |
| 80 | public HelpRequest postHelpRequest( | |
| 81 | @Parameter(name = "requesterEmail", description = "email of the person requesting help") | |
| 82 | @RequestParam | |
| 83 | String requesterEmail, | |
| 84 | @Parameter(name = "teamId", description = "team id, e.g. f26-13") @RequestParam String teamId, | |
| 85 | @Parameter( | |
| 86 | name = "tableOrBreakoutRoom", | |
| 87 | description = "table number or breakout room where the requester can be found") | |
| 88 | @RequestParam | |
| 89 | String tableOrBreakoutRoom, | |
| 90 | @Parameter( | |
| 91 | name = "requestTime", | |
| 92 | description = | |
| 93 | "time of the request (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 94 | @RequestParam("requestTime") | |
| 95 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 96 | LocalDateTime requestTime, | |
| 97 | @Parameter(name = "explanation", description = "what the requester needs help with") | |
| 98 | @RequestParam | |
| 99 | String explanation, | |
| 100 | @Parameter(name = "solved", description = "whether the request has been solved") @RequestParam | |
| 101 | boolean solved) | |
| 102 | throws JsonProcessingException { | |
| 103 | ||
| 104 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 105 | // See: https://www.baeldung.com/spring-date-parameters | |
| 106 | ||
| 107 | log.info("requestTime={}", requestTime); | |
| 108 | ||
| 109 | HelpRequest helpRequest = new HelpRequest(); | |
| 110 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 111 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 112 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 113 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 114 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 115 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 116 | ||
| 117 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 118 | ||
| 119 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Delete a HelpRequest | |
| 124 | * | |
| 125 | * @param id the id of the help request to delete | |
| 126 | * @return a message indicating the help request was deleted | |
| 127 | */ | |
| 128 | @Operation(summary = "Delete a HelpRequest") | |
| 129 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 130 | @DeleteMapping("") | |
| 131 | public Object deleteHelpRequest( | |
| 132 | @Parameter(name = "id", description = "id of the help request to delete") @RequestParam | |
| 133 | Long id) { | |
| 134 | HelpRequest helpRequest = | |
| 135 | helpRequestRepository | |
| 136 | .findById(id) | |
| 137 |
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)); |
| 138 | ||
| 139 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 140 |
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)); |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * Update a single help request | |
| 145 | * | |
| 146 | * @param id id of the help request to update | |
| 147 | * @param incoming the new values for the help request | |
| 148 | * @return the updated help request object | |
| 149 | */ | |
| 150 | @Operation(summary = "Update a single help request") | |
| 151 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 152 | @PutMapping("") | |
| 153 | public HelpRequest updateHelpRequest( | |
| 154 | @Parameter(name = "id", description = "id of the help request to update") @RequestParam | |
| 155 | Long id, | |
| 156 | @RequestBody @Valid HelpRequest incoming) { | |
| 157 | ||
| 158 | HelpRequest helpRequest = | |
| 159 | helpRequestRepository | |
| 160 | .findById(id) | |
| 161 |
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)); |
| 162 | ||
| 163 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 164 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 165 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 166 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 167 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 168 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 169 | ||
| 170 | helpRequestRepository.save(helpRequest); | |
| 171 | ||
| 172 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
| 173 | } | |
| 174 | } | |
Mutations | ||
| 44 |
1.1 |
|
| 61 |
1.1 |
|
| 63 |
1.1 |
|
| 110 |
1.1 |
|
| 111 |
1.1 |
|
| 112 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 115 |
1.1 |
|
| 119 |
1.1 |
|
| 137 |
1.1 |
|
| 139 |
1.1 |
|
| 140 |
1.1 |
|
| 161 |
1.1 |
|
| 163 |
1.1 |
|
| 164 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 168 |
1.1 |
|
| 172 |
1.1 |