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