| 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.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
| 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 HelpRequests | |
| 34 | */ | |
| 35 | ||
| 36 | @Tag(name = "helprequest") | |
| 37 | @RequestMapping("/api/helprequests") | |
| 38 | @RestController | |
| 39 | @Slf4j | |
| 40 | public class HelpRequestsController extends ApiController { | |
| 41 | ||
| 42 | @Autowired | |
| 43 | HelpRequestRepository helpRequestRepository; | |
| 44 | ||
| 45 | /** | |
| 46 | * List all Help Requests | |
| 47 | * | |
| 48 | * @return an iterable of Help Requests | |
| 49 | */ | |
| 50 | @Operation(summary = "List all help requests") | |
| 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/HelpRequestsController::allHelpRequests → KILLED |
return helpRequests; |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Create a new help request | |
| 60 | * | |
| 61 | * @param requesterEmail requester email | |
| 62 | * @param teamId team id | |
| 63 | * @param tableOrBreakoutRoom table or breakout room | |
| 64 | * @param requestTime time of request | |
| 65 | * @param explanation request explanation | |
| 66 | * @param solved status of the help request | |
| 67 | * @return the saved help request | |
| 68 | */ | |
| 69 | @Operation(summary = "Create a new help request") | |
| 70 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 71 | @PostMapping("/post") | |
| 72 | public HelpRequest postHelpRequest( | |
| 73 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 74 | @Parameter(name = "teamId") @RequestParam String teamId, | |
| 75 | @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 76 | @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, | |
| 77 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 78 | @Parameter(name = "solved") @RequestParam boolean solved) | |
| 79 | throws JsonProcessingException { | |
| 80 | ||
| 81 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 82 | // See: https://www.baeldung.com/spring-date-parameters | |
| 83 | ||
| 84 | log.info("requestTime={}", requestTime); | |
| 85 | ||
| 86 | HelpRequest helpRequest = new HelpRequest(); | |
| 87 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 88 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 89 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 90 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 91 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 92 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 93 | ||
| 94 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 95 | ||
| 96 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Get a single help request by id | |
| 101 | * | |
| 102 | * @param id the id of the help request | |
| 103 | * @return a help request | |
| 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/HelpRequestsController::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/HelpRequestsController::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 | |
| 122 | */ | |
| 123 | ||
| 124 | @Operation(summary= "Update a single help request") | |
| 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/HelpRequestsController::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 | helpRequestRepository.save(helpRequest); | |
| 141 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED |
return helpRequest; |
| 142 | ||
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * Delete a help request | |
| 147 | * | |
| 148 | * @param id the id of the help request to delete | |
| 149 | * @return a message indicating the help request was deleted | |
| 150 | */ | |
| 151 | @Operation(summary= "Delete a help request") | |
| 152 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 153 | @DeleteMapping("") | |
| 154 | public Object deleteHelpRequest( | |
| 155 | @Parameter(name="id") @RequestParam Long id) { | |
| 156 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 157 |
1
1. lambda$deleteHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
| 158 | ||
| 159 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 160 |
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)); |
| 161 | } | |
| 162 | | |
| 163 | } | |
Mutations | ||
| 55 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 96 |
1.1 |
|
| 111 |
1.1 |
|
| 113 |
1.1 |
|
| 132 |
1.1 |
|
| 134 |
1.1 |
|
| 135 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |
|
| 139 |
1.1 |
|
| 141 |
1.1 |
|
| 157 |
1.1 |
|
| 159 |
1.1 |
|
| 160 |
1.1 |