| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 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 | /** | |
| 32 | * This is a REST controller for HelpRequests | |
| 33 | */ | |
| 34 | ||
| 35 | @Tag(name = "HelpRequests") | |
| 36 | @RequestMapping("/api/helprequests") | |
| 37 | @RestController | |
| 38 | @Slf4j | |
| 39 | public class HelpRequestsController extends ApiController { | |
| 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> helpRequests = helpRequestRepository.findAll(); | |
| 54 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allHelpRequests → KILLED |
return helpRequests; |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Get a single help request by id | |
| 59 | * | |
| 60 | * @param id the id of the help request | |
| 61 | * @return a HelpRequest | |
| 62 | */ | |
| 63 | @Operation(summary= "Get a single help request") | |
| 64 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 65 | @GetMapping("") | |
| 66 | public HelpRequest getById( | |
| 67 | @Parameter(name="id") @RequestParam Long id) { | |
| 68 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 69 |
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)); |
| 70 | | |
| 71 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED |
return helpRequest; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * Create a new help request | |
| 76 | * | |
| 77 | * @param requesterEmail the email of the requester | |
| 78 | * @param teamId the team id of the team the requester is in | |
| 79 | * @param tableOrBreakoutRoom where the help request is needed/located | |
| 80 | * @param requestTime when the help request was sent | |
| 81 | * @param explanation a description of the help needed | |
| 82 | * @param solved whether or not the help request has been resolved | |
| 83 | * @return the saved help request | |
| 84 | */ | |
| 85 | @Operation(summary= "Create a new help request") | |
| 86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 87 | @PostMapping("/post") | |
| 88 | public HelpRequest postHelpRequest( | |
| 89 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 90 | @Parameter(name="teamId") @RequestParam String teamId, | |
| 91 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 92 | @Parameter(name="explanation") @RequestParam String explanation, | |
| 93 | @Parameter(name="solved") @RequestParam Boolean solved, | |
| 94 | @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) | |
| 95 | throws JsonProcessingException { | |
| 96 | ||
| 97 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 98 | // See: https://www.baeldung.com/spring-date-parameters | |
| 99 | ||
| 100 | log.info("localDateTime={}", requestTime); | |
| 101 | ||
| 102 | HelpRequest helpRequest = new HelpRequest(); | |
| 103 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 104 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 105 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 106 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 107 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 108 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 109 | ||
| 110 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 111 | ||
| 112 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Delete a HelpRequest | |
| 117 | * | |
| 118 | * @param id the id of the help request to delete | |
| 119 | * @return a message indicating the help request was deleted | |
| 120 | */ | |
| 121 | @Operation(summary= "Delete a HelpRequest") | |
| 122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 123 | @DeleteMapping("") | |
| 124 | public Object deleteUCSBDate( | |
| 125 | @Parameter(name="id") @RequestParam Long id) { | |
| 126 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 127 |
1
1. lambda$deleteUCSBDate$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteUCSBDate$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 128 | ||
| 129 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 130 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::deleteUCSBDate → KILLED |
return genericMessage("HelpRequest with id %s deleted".formatted(id)); |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Update a single help request | |
| 135 | * | |
| 136 | * @param id id of the help request to update | |
| 137 | * @param incoming the new help request | |
| 138 | * @return the updated help request object | |
| 139 | */ | |
| 140 | @Operation(summary= "Update a single help request") | |
| 141 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 142 | @PutMapping("") | |
| 143 | public HelpRequest updateHelpRequest( | |
| 144 | @Parameter(name="id") @RequestParam Long id, | |
| 145 | @RequestBody @Valid HelpRequest incoming) { | |
| 146 | ||
| 147 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 148 |
1
1. lambda$updateHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$updateHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 149 | ||
| 150 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 151 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 152 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 153 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 154 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 155 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 156 | ||
| 157 | | |
| 158 | helpRequestRepository.save(helpRequest); | |
| 159 | ||
| 160 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED |
return helpRequest; |
| 161 | } | |
| 162 | } | |
Mutations | ||
| 54 |
1.1 |
|
| 69 |
1.1 |
|
| 71 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 112 |
1.1 |
|
| 127 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 148 |
1.1 |
|
| 150 |
1.1 |
|
| 151 |
1.1 |
|
| 152 |
1.1 |
|
| 153 |
1.1 |
|
| 154 |
1.1 |
|
| 155 |
1.1 |
|
| 160 |
1.1 |