| 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 | @Tag(name = "HelpRequest") | |
| 31 | @RequestMapping("/api/helprequest") | |
| 32 | @RestController | |
| 33 | @Slf4j | |
| 34 | public class HelpRequestController extends ApiController { | |
| 35 | ||
| 36 | @Autowired | |
| 37 | HelpRequestRepository helpRequestRepository; | |
| 38 | ||
| 39 | // GET (all entries) : lists all help requests | |
| 40 | @Operation(summary= "List all help requests") | |
| 41 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 42 | @GetMapping("/all") | |
| 43 | public Iterable<HelpRequest> allHelpRequests() { | |
| 44 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
| 45 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
| 46 | } | |
| 47 | ||
| 48 | // GET (by ID / single entry): Gets a single help request by id | |
| 49 | @Operation(summary= "Get a single help request") | |
| 50 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 51 | @GetMapping("") | |
| 52 | public HelpRequest getById( | |
| 53 | @Parameter(name="id") @RequestParam Long id) { | |
| 54 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 55 |
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)); |
| 56 | ||
| 57 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
| 58 | } | |
| 59 | ||
| 60 | // POST : creates a new help request entry for HelpRequest data table | |
| 61 | @Operation(summary= "Create a new help request") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/post") | |
| 64 | public HelpRequest postHelpRequest( | |
| 65 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
| 66 | @Parameter(name="teamId") @RequestParam String teamId, | |
| 67 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 68 | @Parameter(name="explanation") @RequestParam String explanation, | |
| 69 | @Parameter(name="solved") @RequestParam boolean solved, | |
| 70 | @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) | |
| 71 | throws JsonProcessingException { | |
| 72 | ||
| 73 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 74 | // See: https://www.baeldung.com/spring-date-parameters | |
| 75 | ||
| 76 | log.info("requestTime={}", requestTime); | |
| 77 | | |
| 78 | HelpRequest helpRequest = new HelpRequest(); | |
| 79 | ||
| 80 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 81 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 82 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 83 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 84 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 85 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 86 | ||
| 87 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 88 | ||
| 89 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 90 | } | |
| 91 | ||
| 92 | // PUT (edit) : edits a single data entry in the help request table | |
| 93 | @Operation(summary= "Update a single help request") | |
| 94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 95 | @PutMapping("") | |
| 96 | public HelpRequest updateHelpRequest( | |
| 97 | @Parameter(name="id") @RequestParam Long id, | |
| 98 | @RequestBody @Valid HelpRequest incoming) { | |
| 99 | ||
| 100 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 101 |
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)); |
| 102 | ||
| 103 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 104 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 105 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 106 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 107 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 108 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 109 | ||
| 110 | helpRequestRepository.save(helpRequest); | |
| 111 | ||
| 112 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
| 113 | } | |
| 114 | ||
| 115 | // DELETE : deletes a single entry in the data table via ID. | |
| 116 | @Operation(summary= "Delete a help request") | |
| 117 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 118 | @DeleteMapping("") | |
| 119 | public Object deleteHelpRequest( | |
| 120 | @Parameter(name="id") @RequestParam Long id) { | |
| 121 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 122 |
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)); |
| 123 | ||
| 124 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 125 |
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)); |
| 126 | } | |
| 127 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 55 |
1.1 |
|
| 57 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 85 |
1.1 |
|
| 89 |
1.1 |
|
| 101 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 112 |
1.1 |
|
| 122 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |