| 1 | package edu.ucsb.cs156.diningcachingproxy.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.diningcachingproxy.entity.HostManager; | |
| 4 | import edu.ucsb.cs156.diningcachingproxy.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.diningcachingproxy.repository.HostManagerRepository; | |
| 6 | import edu.ucsb.cs156.diningcachingproxy.utilities.CanonicalFormConverter; | |
| 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 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 13 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 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 | @Tag(name = "HostManagers") | |
| 21 | @RequestMapping("/api/admin/hostmanagers") | |
| 22 | @RestController | |
| 23 | @Slf4j | |
| 24 | public class HostManagersController extends ApiController { | |
| 25 | ||
| 26 | @Autowired HostManagerRepository hostManagerRepository; | |
| 27 | ||
| 28 | @Operation(summary = "Create a new HostManager") | |
| 29 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 30 | @PostMapping("/post") | |
| 31 | public HostManager postHostManager(@Parameter(name = "email") @RequestParam String email) { | |
| 32 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(email).strip(); | |
| 33 | HostManager hostManager = new HostManager(convertedEmail); | |
| 34 |
1
1. postHostManager : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/controller/HostManagersController::postHostManager → KILLED |
return hostManagerRepository.save(hostManager); |
| 35 | } | |
| 36 | ||
| 37 | @Operation(summary = "List all HostManagers") | |
| 38 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 39 | @GetMapping("/all") | |
| 40 | public Iterable<HostManager> allHostManagers() { | |
| 41 |
1
1. allHostManagers : replaced return value with Collections.emptyList for edu/ucsb/cs156/diningcachingproxy/controller/HostManagersController::allHostManagers → KILLED |
return hostManagerRepository.findAll(); |
| 42 | } | |
| 43 | ||
| 44 | @Operation(summary = "Delete a HostManager") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @DeleteMapping("/delete") | |
| 47 | public Object deleteHostManager(@Parameter(name = "email") @RequestParam String email) { | |
| 48 | HostManager hostManager = | |
| 49 | hostManagerRepository | |
| 50 | .findByEmail(email) | |
| 51 |
1
1. lambda$deleteHostManager$0 : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/controller/HostManagersController::lambda$deleteHostManager$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HostManager.class, email)); |
| 52 |
1
1. deleteHostManager : removed call to edu/ucsb/cs156/diningcachingproxy/repository/HostManagerRepository::delete → KILLED |
hostManagerRepository.delete(hostManager); |
| 53 |
1
1. deleteHostManager : replaced return value with null for edu/ucsb/cs156/diningcachingproxy/controller/HostManagersController::deleteHostManager → KILLED |
return genericMessage("HostManager with id %s deleted".formatted(email)); |
| 54 | } | |
| 55 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 41 |
1.1 |
|
| 51 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |