| 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 UCSBDates | |
| 32 |  */ | |
| 33 | ||
| 34 |  @Tag(name = "HelpRequest") | |
| 35 |  @RequestMapping("/api/helprequest") | |
| 36 |  @RestController | |
| 37 |  @Slf4j | |
| 38 | ||
| 39 |  public class HelpRequestController 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> requests = helpRequestRepository.findAll(); | |
| 54 | 
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED | 
        return requests; | 
| 55 |     } | |
| 56 | ||
| 57 |     /** | |
| 58 |      * Get a single request by id | |
| 59 |      *  | |
| 60 |      * @param id the id of the date | |
| 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/HelpRequestController::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/HelpRequestController::getById → KILLED | 
        return helpRequest; | 
| 72 |     } | |
| 73 | ||
| 74 |     /** | |
| 75 |      * Create a new help request | |
| 76 |      *  | |
| 77 |      * @param requesterEmail       the email in typical email format | |
| 78 |      * @param teamID               the number of the team | |
| 79 |      * @param tableOrBreakoutRoom  the table/room the help requster is at | |
| 80 |      * @param explanation          the explanation of the problem | |
| 81 |      * @param solved               the solved status of the request | |
| 82 |      * @param localDateTime        the date of the request | |
| 83 |      * @return the saved helprequest | |
| 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="localDateTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("localDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime localDateTime) | |
| 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={}", localDateTime); | |
| 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::setTeamID → KILLED | 
        helpRequest.setTeamID(teamID); | 
| 105 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); | 
| 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 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setLocalDateTime → KILLED | 
        helpRequest.setLocalDateTime(localDateTime); | 
| 109 | ||
| 110 |         HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 111 | ||
| 112 | 
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED | 
        return savedHelpRequest; | 
| 113 |     } | |
| 114 | ||
| 115 |     /** | |
| 116 |      * Delete a HelpRequest | |
| 117 |      *  | |
| 118 |      * @param id the id of the helprequest to delete | |
| 119 |      * @return a message indicating the helprequest was deleted | |
| 120 |      */ | |
| 121 |     @Operation(summary= "Delete a HelpRequest") | |
| 122 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 123 |     @DeleteMapping("") | |
| 124 |     public Object deleteHelpRequest( | |
| 125 |             @Parameter(name="id") @RequestParam Long id) { | |
| 126 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 127 | 
1
1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED | 
                .orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); | 
| 128 | ||
| 129 | 
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED | 
        helpRequestRepository.delete(helpRequest); | 
| 130 | 
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)); | 
| 131 |     } | |
| 132 | ||
| 133 |     /** | |
| 134 |      * Update a single request | |
| 135 |      *  | |
| 136 |      * @param id       id of the helprequest to update | |
| 137 |      * @param incoming the new helprequest | |
| 138 |      * @return the updated helprequest object | |
| 139 |      */ | |
| 140 |     @Operation(summary= "Update a single helprequest") | |
| 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/HelpRequestController::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::setTeamID → KILLED | 
        helpRequest.setTeamID(incoming.getTeamID()); | 
| 155 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setLocalDateTime → KILLED | 
        helpRequest.setLocalDateTime(incoming.getLocalDateTime()); | 
| 156 | ||
| 157 |         helpRequestRepository.save(helpRequest); | |
| 158 | ||
| 159 | 
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED | 
        return helpRequest; | 
| 160 |     } | |
| 161 | } | |
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  | 
|
| 159 | 
 
 1.1  |