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