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