| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 5 | import edu.ucsb.cs156.example.entities.UCSBDiningCommons; | |
| 6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 8 | ||
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | ||
| 14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 15 | ||
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.format.annotation.DateTimeFormat; | |
| 18 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | import org.springframework.web.bind.annotation.PutMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestBody; | |
| 24 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestParam; | |
| 26 | import org.springframework.web.bind.annotation.RestController; | |
| 27 | ||
| 28 | import jakarta.validation.Valid; | |
| 29 | ||
| 30 | import java.time.LocalDateTime; | |
| 31 | ||
| 32 | /** | |
| 33 |  * This is a REST controller for HelpRequest | |
| 34 |  */ | |
| 35 | ||
| 36 |  @Tag(name = "HelpRequest") | |
| 37 | @RequestMapping("/api/helprequest") | |
| 38 | @RestController | |
| 39 | @Slf4j | |
| 40 | public class HelpRequestController extends ApiController { | |
| 41 | ||
| 42 |     @Autowired | |
| 43 |     HelpRequestRepository helprequestRepository; | |
| 44 | ||
| 45 |      /** | |
| 46 |      * List all HelpRequests | |
| 47 |      *  | |
| 48 |      * @return an iterable of HelpRequests | |
| 49 |      */ | |
| 50 |     @Operation(summary= "List all helprequests") | |
| 51 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 52 |     @GetMapping("/all") | |
| 53 |     public Iterable<HelpRequest> allHelpRequests() { | |
| 54 |         Iterable<HelpRequest> helprequests = helprequestRepository.findAll(); | |
| 55 | 
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED | 
        return helprequests; | 
| 56 |     } | |
| 57 | ||
| 58 | ||
| 59 |     /** | |
| 60 |      * Create a new helprequest | |
| 61 |      *  | |
| 62 |      * @param requesterEmail  the requester's email | |
| 63 |      * @param teamId          the ID of the team of the requester | |
| 64 |      * @param tableOrBreakoutRoom the table or breakout room of the requester | |
| 65 |      * @param requestTime the timestamp on the help request, with time zome information | |
| 66 |      * @param explanation the explanation for the problem | |
| 67 |      * @param solved the boolean paramter indicating if the problem is sloved | |
| 68 |      * @return the saved helprequest | |
| 69 |      */ | |
| 70 |     @Operation(summary= "Create a new helprequest") | |
| 71 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 72 |     @PostMapping("/post") | |
| 73 |     public HelpRequest postHelpRequest( | |
| 74 |             @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 75 |             @Parameter(name="teamId") @RequestParam String teamId, | |
| 76 |             @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 77 |             @Parameter(name="explanation") @RequestParam String explanation, | |
| 78 |             @Parameter(name="solved") @RequestParam boolean solved, | |
| 79 |             @Parameter(name="requestTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SSZ; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime) | |
| 80 |             throws JsonProcessingException { | |
| 81 | ||
| 82 |         // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 83 |         // See: https://www.baeldung.com/spring-date-parameters | |
| 84 | ||
| 85 |         log.info("requestTime={}", requestTime); | |
| 86 | ||
| 87 |         HelpRequest helprequest = new HelpRequest(); | |
| 88 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED | 
        helprequest.setRequesterEmail(requesterEmail); | 
| 89 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED | 
        helprequest.setTeamId(teamId); | 
| 90 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED | 
        helprequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); | 
| 91 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED | 
        helprequest.setRequestTime(requestTime); | 
| 92 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED | 
        helprequest.setExplanation(explanation); | 
| 93 | 
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED | 
        helprequest.setSolved(solved); | 
| 94 | ||
| 95 |         HelpRequest savedHelpRequest = helprequestRepository.save(helprequest); | |
| 96 | ||
| 97 | 
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED | 
        return savedHelpRequest; | 
| 98 |     } | |
| 99 | ||
| 100 |     /** | |
| 101 |      * Get a single helprequest by id | |
| 102 |      *  | |
| 103 |      * @param id the id of the helprequest | |
| 104 |      * @return a HelpRequest | |
| 105 |      */ | |
| 106 |     @Operation(summary= "Get a single helprequest") | |
| 107 |     @PreAuthorize("hasRole('ROLE_USER')") | |
| 108 |     @GetMapping("") | |
| 109 |     public HelpRequest getById( | |
| 110 |             @Parameter(name="id") @RequestParam Long id) { | |
| 111 |         HelpRequest helprequest = helprequestRepository.findById(id) | |
| 112 | 
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)); | 
| 113 | ||
| 114 | 
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED | 
        return helprequest; | 
| 115 |     } | |
| 116 |      | |
| 117 |          /** | |
| 118 |      * Update a single helprequest | |
| 119 |      *  | |
| 120 |      * @param id       id of the date to update | |
| 121 |      * @param incoming the new hleprequest | |
| 122 |      * @return the updated date object | |
| 123 |      */ | |
| 124 |     @Operation(summary= "Update a single helprequest") | |
| 125 |     @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 126 |     @PutMapping("") | |
| 127 |     public HelpRequest updateHelpRequest( | |
| 128 |             @Parameter(name="id") @RequestParam Long id, | |
| 129 |             @RequestBody @Valid HelpRequest incoming) { | |
| 130 | ||
| 131 |         HelpRequest helprequest = helprequestRepository.findById(id) | |
| 132 | 
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)); | 
| 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/HelpRequestController::updateHelpRequest → KILLED | 
        return helprequest; | 
| 144 |     } | |
| 145 | ||
| 146 |     /** | |
| 147 |      * Delete a HelpRequest | |
| 148 |      *  | |
| 149 |      * @param id the id of the helprequest to delete | |
| 150 |      * @return a message indicating the helprequest 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 | 
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED | 
        helprequestRepository.delete(helprequest); | 
| 161 | 
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)); | 
| 162 |     } | |
| 163 | } | |
Mutations | ||
| 55 | 
 
 1.1  | 
|
| 88 | 
 
 1.1  | 
|
| 89 | 
 
 1.1  | 
|
| 90 | 
 
 1.1  | 
|
| 91 | 
 
 1.1  | 
|
| 92 | 
 
 1.1  | 
|
| 93 | 
 
 1.1  | 
|
| 97 | 
 
 1.1  | 
|
| 112 | 
 
 1.1  | 
|
| 114 | 
 
 1.1  | 
|
| 132 | 
 
 1.1  | 
|
| 134 | 
 
 1.1  | 
|
| 135 | 
 
 1.1  | 
|
| 136 | 
 
 1.1  | 
|
| 137 | 
 
 1.1  | 
|
| 138 | 
 
 1.1  | 
|
| 139 | 
 
 1.1  | 
|
| 143 | 
 
 1.1  | 
|
| 158 | 
 
 1.1  | 
|
| 160 | 
 
 1.1  | 
|
| 161 | 
 
 1.1  |