| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | ||
| 4 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 5 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 6 | import java.time.ZonedDateTime; | |
| 7 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 8 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 9 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
| 10 | ||
| 11 | import io.swagger.v3.oas.annotations.Operation; | |
| 12 | import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | import lombok.extern.slf4j.Slf4j; | |
| 15 | ||
| 16 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 17 | ||
| 18 | import org.springframework.beans.factory.annotation.Autowired; | |
| 19 | import org.springframework.format.annotation.DateTimeFormat; | |
| 20 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 21 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 22 | import org.springframework.web.bind.annotation.GetMapping; | |
| 23 | import org.springframework.web.bind.annotation.PostMapping; | |
| 24 | import org.springframework.web.bind.annotation.PutMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestBody; | |
| 26 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 27 | import org.springframework.web.bind.annotation.RequestParam; | |
| 28 | import org.springframework.web.bind.annotation.RestController; | |
| 29 | ||
| 30 | import jakarta.validation.Valid; | |
| 31 | ||
| 32 | import java.time.LocalDateTime; | |
| 33 | ||
| 34 | /** | |
| 35 |  * This is a REST controller for HelpRequests | |
| 36 |  */ | |
| 37 | ||
| 38 | @Tag(name = "HelpRequests") | |
| 39 | @RequestMapping("/api/helprequests") | |
| 40 | @RestController | |
| 41 | @Slf4j | |
| 42 | public class HelpRequestController extends ApiController{ | |
| 43 | ||
| 44 |     @Autowired | |
| 45 |     HelpRequestRepository helpRequestRepository; | |
| 46 | ||
| 47 | ||
| 48 |       /** | |
| 49 |      * List all HelpRequests | |
| 50 |      *  | |
| 51 |      * @return an iterable of HelpRequests | |
| 52 |      */ | |
| 53 |     @Operation(summary= "List all help requests") | |
| 54 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 55 |     @GetMapping("/all") | |
| 56 |     public Iterable<HelpRequest> allHelpRequests() { | |
| 57 |         Iterable<HelpRequest> helprequests = helpRequestRepository.findAll(); | |
| 58 | 
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED | 
        return helprequests; | 
| 59 |     } | |
| 60 | ||
| 61 | ||
| 62 |       /** | |
| 63 |      * Create a new HelpRequest | |
| 64 |      *  | |
| 65 |      * @param requesterEmail  the email of the person submitting helprequest | |
| 66 |      * @param teamId        the ID of the team | |
| 67 |      * @param tableOrBreakoutRoom the name of the table that needs help | |
| 68 |      * @param requestTime the time of the request | |
| 69 |      * @param explanation explanation of what need help with | |
| 70 |      * @param solved  tells us whether the helprequest is solved or not  | |
| 71 |      *  | |
| 72 |      * @return the saved helprequest  | |
| 73 |      */ | |
| 74 |     @Operation(summary= "Create a new helprequest") | |
| 75 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 76 |     @PostMapping("/post") | |
| 77 |     public HelpRequest postHelpRequest( | |
| 78 |             @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 79 |             @Parameter(name="teamId") @RequestParam String teamId, | |
| 80 |             @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 81 |             @Parameter(name="explanation") @RequestParam String explanation, | |
| 82 |             @Parameter(name="solved") @RequestParam Boolean solved, | |
| 83 |             @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) ZonedDateTime requestTime) | |
| 84 | ||
| 85 |             throws JsonProcessingException { | |
| 86 | ||
| 87 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 88 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 89 | ||
| 90 |         log.info("requestTime={}", requestTime); | |
| 91 | ||
| 92 | ||
| 93 |         HelpRequest helpRequest = new HelpRequest(); | |
| 94 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED | 
        helpRequest.setRequesterEmail(requesterEmail); | 
| 95 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED | 
        helpRequest.setTeamId(teamId); | 
| 96 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); | 
| 97 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED | 
        helpRequest.setRequestTime(requestTime); | 
| 98 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED | 
        helpRequest.setExplanation(explanation); | 
| 99 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED | 
        helpRequest.setSolved(solved); | 
| 100 | ||
| 101 | ||
| 102 | ||
| 103 |         HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 104 | ||
| 105 | 
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED | 
        return savedHelpRequest; | 
| 106 |     } | |
| 107 | ||
| 108 |      /** | |
| 109 |      * Get a single HelpRequest by id | |
| 110 |      *  | |
| 111 |      * @param id the id of the HelpRequest | |
| 112 |      * @return a HelpRequest | |
| 113 |      */ | |
| 114 |     @Operation(summary= "Get a single HelpRequest") | |
| 115 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 116 |     @GetMapping("") | |
| 117 |     public HelpRequest getById( | |
| 118 |             @Parameter(name="id") @RequestParam Long id) { | |
| 119 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 120 | 
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)); | 
| 121 | ||
| 122 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED | 
        return helpRequest; | 
| 123 |     } | |
| 124 | ||
| 125 | ||
| 126 |      /** | |
| 127 |      * Update a single helprequest | |
| 128 |      *  | |
| 129 |      * @param id       id of the helprequest to update | |
| 130 |      * @param incoming the new helprequest | |
| 131 |      * @return the updated helprequest object | |
| 132 |      */ | |
| 133 |     @Operation(summary= "Update a single helprequest") | |
| 134 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 135 |     @PutMapping("") | |
| 136 |     public HelpRequest updateHelpRequest( | |
| 137 |             @Parameter(name="id") @RequestParam Long id, | |
| 138 |             @RequestBody @Valid HelpRequest incoming) { | |
| 139 | ||
| 140 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 141 | 
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)); | 
| 142 | ||
| 143 | ||
| 144 | ||
| 145 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED | 
        helpRequest.setRequesterEmail(incoming.getRequesterEmail()); | 
| 146 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED | 
        helpRequest.setTeamId(incoming.getTeamId()); | 
| 147 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); | 
| 148 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED | 
        helpRequest.setRequestTime(incoming.getRequestTime()); | 
| 149 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED | 
        helpRequest.setExplanation(incoming.getExplanation()); | 
| 150 | 
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED | 
        helpRequest.setSolved(incoming.getSolved()); | 
| 151 | ||
| 152 |         helpRequestRepository.save(helpRequest); | |
| 153 | ||
| 154 | 
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED | 
        return helpRequest; | 
| 155 |     } | |
| 156 | ||
| 157 | ||
| 158 |       /** | |
| 159 |      * Delete a HelpRequest | |
| 160 |      *  | |
| 161 |      * @param id the id of the helprequest to delete | |
| 162 |      * @return a message indicating the date was deleted | |
| 163 |      */ | |
| 164 |     @Operation(summary= "Delete a HelpRequest") | |
| 165 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 166 |     @DeleteMapping("") | |
| 167 |     public Object deleteHelpRequest( | |
| 168 |             @Parameter(name="id") @RequestParam Long id) { | |
| 169 |         HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 170 | 
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)); | 
| 171 | ||
| 172 | 
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED | 
        helpRequestRepository.delete(helpRequest); | 
| 173 |          | |
| 174 | 
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)); | 
| 175 |     } | |
| 176 | ||
| 177 | ||
| 178 | ||
| 179 | ||
| 180 | ||
| 181 | ||
| 182 | } | |
Mutations | ||
| 58 | 
 
 1.1  | 
|
| 94 | 
 
 1.1  | 
|
| 95 | 
 
 1.1  | 
|
| 96 | 
 
 1.1  | 
|
| 97 | 
 
 1.1  | 
|
| 98 | 
 
 1.1  | 
|
| 99 | 
 
 1.1  | 
|
| 105 | 
 
 1.1  | 
|
| 120 | 
 
 1.1  | 
|
| 122 | 
 
 1.1  | 
|
| 141 | 
 
 1.1  | 
|
| 145 | 
 
 1.1  | 
|
| 146 | 
 
 1.1  | 
|
| 147 | 
 
 1.1  | 
|
| 148 | 
 
 1.1  | 
|
| 149 | 
 
 1.1  | 
|
| 150 | 
 
 1.1  | 
|
| 154 | 
 
 1.1  | 
|
| 170 | 
 
 1.1  | 
|
| 172 | 
 
 1.1  | 
|
| 174 | 
 
 1.1  |