| 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 |  * This is a REST controller for HelpRequests | |
| 32 |  */ | |
| 33 | ||
| 34 | @Tag(name = "HelpRequests") | |
| 35 | @RequestMapping("/api/helprequests") | |
| 36 | @RestController | |
| 37 | @Slf4j | |
| 38 | ||
| 39 | public class HelpRequestsController extends ApiController { | |
| 40 | ||
| 41 |     @Autowired | |
| 42 |     HelpRequestRepository helpRequestRepository; | |
| 43 | ||
| 44 |     @Operation(summary= "List all help requests") | |
| 45 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 46 |     @GetMapping("/all") | |
| 47 |     public Iterable<HelpRequest> allHelpRequests() { | |
| 48 |         Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
| 49 | 
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allHelpRequests → KILLED | 
        return requests; | 
| 50 |     } | |
| 51 | ||
| 52 |     @Operation(summary= "Get a help request") | |
| 53 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 54 |     @GetMapping("") | |
| 55 |     public HelpRequest getById( | |
| 56 |             @Parameter(name="id") @RequestParam Long id) { | |
| 57 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 58 | 
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)); | 
| 59 | ||
| 60 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED | 
        return helpRequest; | 
| 61 |     } | |
| 62 | ||
| 63 |     @Operation(summary= "Create a new help request") | |
| 64 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 65 |     @PostMapping("/post") | |
| 66 |     public HelpRequest postHelpRequest( | |
| 67 |             @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 68 |             @Parameter(name="teamId") @RequestParam String teamId, | |
| 69 |             @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 70 |             @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, | |
| 71 |             @Parameter(name="explanation") @RequestParam String explanation, | |
| 72 |             @Parameter(name="solved") @RequestParam boolean solved | |
| 73 |             ) | |
| 74 |             throws JsonProcessingException { | |
| 75 | ||
| 76 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 77 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 78 | ||
| 79 |         log.info("requestTime={}", requestTime); | |
| 80 | ||
| 81 |         HelpRequest helpRequest = new HelpRequest(); | |
| 82 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED | 
        helpRequest.setRequesterEmail(requesterEmail); | 
| 83 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED | 
        helpRequest.setTeamId(teamId); | 
| 84 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); | 
| 85 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED | 
        helpRequest.setRequestTime(requestTime); | 
| 86 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED | 
        helpRequest.setExplanation(explanation); | 
| 87 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED | 
        helpRequest.setSolved(solved); | 
| 88 | ||
| 89 |         HelpRequest savedhelpRequest = helpRequestRepository.save(helpRequest); | |
| 90 | ||
| 91 | 
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED | 
        return savedhelpRequest; | 
| 92 |     } | |
| 93 | ||
| 94 | ||
| 95 |     /** | |
| 96 |      * Delete a HelpRequest | |
| 97 |      *  | |
| 98 |      * @param id the id of the request to delete | |
| 99 |      * @return a message indicating the request was deleted | |
| 100 |      */ | |
| 101 |     @Operation(summary= "Delete a HelpRequest") | |
| 102 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 103 |     @DeleteMapping("") | |
| 104 |     public Object deleteHelpRequest( | |
| 105 |             @Parameter(name="id") @RequestParam Long id) { | |
| 106 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 107 | 
1
1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$1 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); | 
| 108 | ||
| 109 | 
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED | 
        helpRequestRepository.delete(helpRequest); | 
| 110 | 
1
1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::deleteHelpRequest → KILLED | 
        return genericMessage("HelpRequest with id %s deleted".formatted(id)); | 
| 111 |     } | |
| 112 | ||
| 113 |     /** | |
| 114 |      * Update a single request | |
| 115 |      *  | |
| 116 |      * @param id       id of the request to update | |
| 117 |      * @param incoming the new request | |
| 118 |      * @return the updated request object | |
| 119 |      */ | |
| 120 |     @Operation(summary= "Update a single request") | |
| 121 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 122 |     @PutMapping("") | |
| 123 |     public HelpRequest updateHelpRequest( | |
| 124 |             @Parameter(name="id") @RequestParam Long id, | |
| 125 |             @RequestBody @Valid HelpRequest incoming) { | |
| 126 | ||
| 127 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 128 | 
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)); | 
| 129 | ||
| 130 |         // helpRequest.setQuarterYYYYQ(incoming.getQuarterYYYYQ()); | |
| 131 |         // helpRequest.setName(incoming.getName()); | |
| 132 |         // helpRequest.setLocalDateTime(incoming.getLocalDateTime()); | |
| 133 | ||
| 134 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED | 
        helpRequest.setRequesterEmail(incoming.getRequesterEmail()); | 
| 135 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED | 
        helpRequest.setTeamId(incoming.getTeamId()); | 
| 136 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); | 
| 137 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED | 
        helpRequest.setRequestTime(incoming.getRequestTime()); | 
| 138 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED | 
        helpRequest.setExplanation(incoming.getExplanation()); | 
| 139 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED | 
        helpRequest.setSolved(incoming.getSolved()); | 
| 140 | ||
| 141 |         helpRequestRepository.save(helpRequest); | |
| 142 | ||
| 143 | 
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED | 
        return helpRequest; | 
| 144 |     } | |
| 145 | ||
| 146 | ||
| 147 | } | |
Mutations | ||
| 49 | 
 
 1.1  | 
|
| 58 | 
 
 1.1  | 
|
| 60 | 
 
 1.1  | 
|
| 82 | 
 
 1.1  | 
|
| 83 | 
 
 1.1  | 
|
| 84 | 
 
 1.1  | 
|
| 85 | 
 
 1.1  | 
|
| 86 | 
 
 1.1  | 
|
| 87 | 
 
 1.1  | 
|
| 91 | 
 
 1.1  | 
|
| 107 | 
 
 1.1  | 
|
| 109 | 
 
 1.1  | 
|
| 110 | 
 
 1.1  | 
|
| 128 | 
 
 1.1  | 
|
| 134 | 
 
 1.1  | 
|
| 135 | 
 
 1.1  | 
|
| 136 | 
 
 1.1  | 
|
| 137 | 
 
 1.1  | 
|
| 138 | 
 
 1.1  | 
|
| 139 | 
 
 1.1  | 
|
| 143 | 
 
 1.1  |