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