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