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