| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import java.time.LocalDateTime; | |
| 4 | ||
| 5 | import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | import org.springframework.format.annotation.DateTimeFormat; | |
| 7 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 8 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 9 | import org.springframework.web.bind.annotation.GetMapping; | |
| 10 | import org.springframework.web.bind.annotation.PostMapping; | |
| 11 | import org.springframework.web.bind.annotation.PutMapping; | |
| 12 | import org.springframework.web.bind.annotation.RequestBody; | |
| 13 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | import org.springframework.web.bind.annotation.RequestParam; | |
| 15 | import org.springframework.web.bind.annotation.RestController; | |
| 16 | ||
| 17 | import edu.ucsb.cs156.example.entities.HelpRequests; | |
| 18 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 19 | import edu.ucsb.cs156.example.repositories.HelpRequestsRepository; | |
| 20 | import io.swagger.v3.oas.annotations.Operation; | |
| 21 | import io.swagger.v3.oas.annotations.Parameter; | |
| 22 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 23 | import jakarta.validation.Valid; | |
| 24 | import lombok.extern.slf4j.Slf4j; | |
| 25 | ||
| 26 | /** | |
| 27 | * This is a REST controller for managing Help Requests | |
| 28 | */ | |
| 29 | @RestController | |
| 30 | @Slf4j | |
| 31 | @RequestMapping("/api/HelpRequests") | |
| 32 | @Tag(name = "HelpRequests") | |
| 33 | public class HelpRequestsController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | private HelpRequestsRepository helpRequestsRepository; | |
| 37 | ||
| 38 | /** | |
| 39 | * List all help requests | |
| 40 | * | |
| 41 | * @return an iterable of help requests | |
| 42 | */ | |
| 43 | @Operation(summary= "List all help requests") | |
| 44 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 45 | @GetMapping("/all") | |
| 46 | public Iterable<HelpRequests> allHelpRequests() { | |
| 47 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allHelpRequests → KILLED |
return helpRequestsRepository.findAll(); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Create a new help request | |
| 52 | * | |
| 53 | * @param requesterEmail the email of the requester | |
| 54 | * @param teamId the ID of the team | |
| 55 | * @param tableOrBreakoutRoom the table or breakout room location | |
| 56 | * @param explanation explanation of the help request | |
| 57 | * @param solved status of the help request, whether it's solved or not | |
| 58 | * @param requestTime the time the request was made | |
| 59 | * @return the newly created help request | |
| 60 | */ | |
| 61 | @Operation(summary= "Create a new help request") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/post") | |
| 64 | public HelpRequests 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="ISO date format, e.g., YYYY-mm-ddTHH:MM:SS") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime) { | |
| 71 | ||
| 72 | log.info("Creating new help request: {}, at {}", requesterEmail, requestTime); | |
| 73 | ||
| 74 | HelpRequests helpRequest = new HelpRequests(); | |
| 75 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
| 76 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
| 77 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
| 78 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
| 79 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setSolved → KILLED |
helpRequest.setSolved(solved); |
| 80 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
| 81 | ||
| 82 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED |
return helpRequestsRepository.save(helpRequest); |
| 83 | } | |
| 84 | // GET (by ID / single entry): Gets a single help request by id | |
| 85 | @Operation(summary= "Get a single help request") | |
| 86 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 87 | @GetMapping("") | |
| 88 | public HelpRequests getById( | |
| 89 | @Parameter(name="id") @RequestParam Long id) { | |
| 90 | HelpRequests helpRequest = helpRequestsRepository.findById(id) | |
| 91 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequests.class, id)); |
| 92 | ||
| 93 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED |
return helpRequest; |
| 94 | } | |
| 95 | @Operation(summary= "Update a single help request") | |
| 96 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 97 | @PutMapping("") | |
| 98 | public HelpRequests updateHelpRequest( | |
| 99 | @Parameter(name="id") @RequestParam Long id, | |
| 100 | @RequestBody @Valid HelpRequests incoming) { | |
| 101 | ||
| 102 | HelpRequests helpRequest = helpRequestsRepository.findById(id) | |
| 103 |
1
1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$updateHelpRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequests.class, id)); |
| 104 | ||
| 105 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 106 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 107 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 108 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 109 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 110 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequests::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 111 | ||
| 112 | helpRequestsRepository.save(helpRequest); | |
| 113 | ||
| 114 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED |
return helpRequest; |
| 115 | } | |
| 116 | ||
| 117 | // DELETE : deletes a single entry in the data table via ID. | |
| 118 | @Operation(summary= "Delete a help request") | |
| 119 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 120 | @DeleteMapping("") | |
| 121 | public Object deleteHelpRequest( | |
| 122 | @Parameter(name="id") @RequestParam Long id) { | |
| 123 | HelpRequests helpRequest = helpRequestsRepository.findById(id) | |
| 124 |
1
1. lambda$deleteHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::lambda$deleteHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequests.class, id)); |
| 125 | ||
| 126 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestsRepository::delete → KILLED |
helpRequestsRepository.delete(helpRequest); |
| 127 |
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)); |
| 128 | } | |
| 129 | } | |
Mutations | ||
| 47 |
1.1 |
|
| 75 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 82 |
1.1 |
|
| 91 |
1.1 |
|
| 93 |
1.1 |
|
| 103 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 108 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 114 |
1.1 |
|
| 124 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |