| 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.HelpRequestRepository; | |
| 7 | ||
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | ||
| 13 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 14 | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.format.annotation.DateTimeFormat; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 19 | import org.springframework.web.bind.annotation.GetMapping; | |
| 20 | import org.springframework.web.bind.annotation.PostMapping; | |
| 21 | import org.springframework.web.bind.annotation.PutMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestBody; | |
| 23 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | import org.springframework.web.bind.annotation.RequestParam; | |
| 25 | import org.springframework.web.bind.annotation.RestController; | |
| 26 | ||
| 27 | import jakarta.validation.Valid; | |
| 28 | ||
| 29 | import java.time.LocalDateTime; | |
| 30 | ||
| 31 | /** | |
| 32 | * This is a REST controller for HelpRequests | |
| 33 | */ | |
| 34 | ||
| 35 | @Tag(name = "HelpRequests") | |
| 36 | @RequestMapping("/api/helprequests") | |
| 37 | @RestController | |
| 38 | @Slf4j | |
| 39 | public class HelpRequestsController extends ApiController{ | |
| 40 | | |
| 41 | @Autowired | |
| 42 | HelpRequestRepository helpRequestRepository; | |
| 43 | ||
| 44 | /** | |
| 45 | * List all HelpRequests | |
| 46 | * | |
| 47 | * @return an iterable of HelpRequests | |
| 48 | */ | |
| 49 | ||
| 50 | @Operation(summary= "List all help requests") | |
| 51 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 52 | @GetMapping("/all") | |
| 53 | public Iterable<HelpRequest> allUCSBDates() { | |
| 54 | Iterable<HelpRequest> dates = helpRequestRepository.findAll(); | |
| 55 |
1
1. allUCSBDates : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestsController::allUCSBDates → KILLED |
return dates; |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Create a new HelpRequest | |
| 60 | * | |
| 61 | * @param requesterEmail the email of the requester | |
| 62 | * @param teamId the team ID | |
| 63 | * @param tableOrBreakoutRoom the table or breakout room | |
| 64 | * @param requestTime the request time (ISO format) | |
| 65 | * @param explanation the explanation of the help request | |
| 66 | * @param solved whether the request is solved | |
| 67 | * @return the saved HelpRequest | |
| 68 | */ | |
| 69 | ||
| 70 | @Operation(summary = "Create a new help request") | |
| 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="requestTime", description="Request time (ISO format, e.g., YYYY-MM-DDTHH:MM:SS)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime, | |
| 78 | @Parameter(name="explanation") @RequestParam String explanation, | |
| 79 | @Parameter(name="solved") @RequestParam boolean solved) | |
| 80 | throws JsonProcessingException { | |
| 81 | ||
| 82 | log.info("requestTime={}", requestTime); | |
| 83 | ||
| 84 | HelpRequest helpRequest = HelpRequest.builder() | |
| 85 | .requesterEmail(requesterEmail) | |
| 86 | .teamId(teamId) | |
| 87 | .tableOrBreakoutRoom(tableOrBreakoutRoom) | |
| 88 | .requestTime(requestTime) | |
| 89 | .explanation(explanation) | |
| 90 | .solved(solved) | |
| 91 | .build(); | |
| 92 | ||
| 93 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
| 94 | ||
| 95 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::postHelpRequest → KILLED |
return savedHelpRequest; |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Get a single help request by id | |
| 100 | * | |
| 101 | * @param id the id of the help request | |
| 102 | * @return a HelpRequest | |
| 103 | */ | |
| 104 | @Operation(summary = "Get a single help request") | |
| 105 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 106 | @GetMapping("") | |
| 107 | public HelpRequest getById( | |
| 108 | @Parameter(name = "id") @RequestParam Long id) { | |
| 109 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 110 |
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)); |
| 111 | ||
| 112 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::getById → KILLED |
return helpRequest; |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Update a single help request | |
| 117 | * | |
| 118 | * @param id id of the help request to update | |
| 119 | * @param incoming the new help request | |
| 120 | * @return the updated help request object | |
| 121 | */ | |
| 122 | @Operation(summary = "Update a single help request") | |
| 123 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 124 | @PutMapping("") | |
| 125 | public HelpRequest updateHelpRequest( | |
| 126 | @Parameter(name = "id") @RequestParam Long id, | |
| 127 | @RequestBody @Valid HelpRequest incoming) { | |
| 128 | ||
| 129 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 130 |
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)); |
| 131 | ||
| 132 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
| 133 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
| 134 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
| 135 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
| 136 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
| 137 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
| 138 | ||
| 139 | helpRequestRepository.save(helpRequest); | |
| 140 | ||
| 141 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestsController::updateHelpRequest → KILLED |
return helpRequest; |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Delete a HelpRequest | |
| 146 | * | |
| 147 | * @param id the id of the help request to delete | |
| 148 | * @return a message indicating the help request was deleted | |
| 149 | */ | |
| 150 | @Operation(summary = "Delete a HelpRequest") | |
| 151 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 152 | @DeleteMapping("") | |
| 153 | public Object deleteHelpRequest( | |
| 154 | @Parameter(name = "id") @RequestParam Long id) { | |
| 155 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
| 156 |
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)); |
| 157 | ||
| 158 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
| 159 |
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)); |
| 160 | } | |
| 161 | } | |
| 162 | ||
| 163 | ||
Mutations | ||
| 55 |
1.1 |
|
| 95 |
1.1 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |
|
| 130 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |
|
| 134 |
1.1 |
|
| 135 |
1.1 |
|
| 136 |
1.1 |
|
| 137 |
1.1 |
|
| 141 |
1.1 |
|
| 156 |
1.1 |
|
| 158 |
1.1 |
|
| 159 |
1.1 |