| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
| 5 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import java.time.LocalDateTime; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.GetMapping; | |
| 15 | import org.springframework.web.bind.annotation.PostMapping; | |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestParam; | |
| 18 | import org.springframework.web.bind.annotation.RestController; | |
| 19 | ||
| 20 | /** This is a REST controller for HelpRequest */ | |
| 21 | @Tag(name = "HelpRequest") | |
| 22 | @RequestMapping("/api/helprequest") | |
| 23 | @RestController | |
| 24 | @Slf4j | |
| 25 | public class HelpRequestController { | |
| 26 | ||
| 27 | @Autowired HelpRequestRepository helpRequestRepository; | |
| 28 | ||
| 29 | /** | |
| 30 | * List all Help Requests | |
| 31 | * | |
| 32 | * @return an iterable of HelpRequest | |
| 33 | */ | |
| 34 | @Operation(summary = "List all help requests") | |
| 35 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 36 | @GetMapping("/all") | |
| 37 | public Iterable<HelpRequest> allHelpRequests() { | |
| 38 | Iterable<HelpRequest> helpRequests = helpRequestRepository.findAll(); | |
| 39 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return helpRequests; |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * Create a new help request | |
| 44 | * | |
| 45 | * @param requesterEmail the requester's email | |
| 46 | * @param teamId the team id of the requester | |
| 47 | * @param tableOrBreakoutRoom table or breakout room of the requester | |
| 48 | * @param requestTime the request time of the help request | |
| 49 | * @param explanation an example explanation of the help request | |
| 50 | * @param solved whether the help request has been solved or not | |
| 51 | * @return the saved HelpRequest | |
| 52 | */ | |
| 53 | @Operation(summary = "Create a new help request") | |
| 54 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 55 | @PostMapping("/post") | |
| 56 | public HelpRequest postHelpRequest( | |
| 57 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 58 | @Parameter(name = "teamId") @RequestParam String teamId, | |
| 59 | @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
| 60 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 61 | @Parameter(name = "solved") @RequestParam Boolean solved, | |
| 62 | @Parameter( | |
| 63 | name = "requestTime", | |
| 64 | description = | |
| 65 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 66 | @RequestParam("requestTime") | |
| 67 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 68 | LocalDateTime requestTime) | |
| 69 | throws JsonProcessingException { | |
| 70 | ||
| 71 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 72 | // See: https://www.baeldung.com/spring-date-parameters | |
| 73 | ||
| 74 | log.info("requestTime={}", requestTime); | |
| 75 | ||
| 76 | HelpRequest helpRequest = new HelpRequest(); | |
| 77 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 78 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 79 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 80 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 81 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 82 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 83 | ||
| 84 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 85 | ||
| 86 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 86 |
1.1 |