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