| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.Hotel; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.HotelRepository; | |
| 6 | import io.swagger.annotations.Api; | |
| 7 | import io.swagger.annotations.ApiOperation; | |
| 8 | import io.swagger.annotations.ApiParam; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | ||
| 11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 12 | ||
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.PutMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestBody; | |
| 20 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | import javax.validation.Valid; | |
| 25 | ||
| 26 | @Api(description = "Hotels") | |
| 27 | @RequestMapping("/api/hotels") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class HotelsController extends ApiController { | |
| 31 | ||
| 32 | @Autowired | |
| 33 | HotelRepository hotelRepository; | |
| 34 | ||
| 35 | @ApiOperation(value = "List all hotels") | |
| 36 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 37 | @GetMapping("/all") | |
| 38 | public Iterable<Hotel> allHotels() { | |
| 39 |
1
1. allHotels : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::allHotels → KILLED |
return hotelRepository.findAll(); |
| 40 | } | |
| 41 | ||
| 42 | @ApiOperation(value = "Get a single hotel") | |
| 43 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 44 | @GetMapping("") | |
| 45 | public Hotel getById( | |
| 46 | @ApiParam("id") @RequestParam Long id | |
| 47 | ) { | |
| 48 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::getById → KILLED |
return hotelRepository.findById(id) |
| 49 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Hotel.class, id)); |
| 50 | } | |
| 51 | ||
| 52 | @ApiOperation(value = "Create a new hotel") | |
| 53 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 54 | @PostMapping("/post") | |
| 55 | public Hotel postHotel( | |
| 56 | @ApiParam("name") @RequestParam String name, | |
| 57 | @ApiParam("address") @RequestParam String address, | |
| 58 | @ApiParam("description") @RequestParam String description) | |
| 59 | throws JsonProcessingException { | |
| 60 | ||
| 61 | var hotel = Hotel.builder() | |
| 62 | .name(name) | |
| 63 | .address(address) | |
| 64 | .description(description) | |
| 65 | .build(); | |
| 66 |
1
1. postHotel : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::postHotel → KILLED |
return hotelRepository.save(hotel); |
| 67 | } | |
| 68 | ||
| 69 | @ApiOperation(value = "Delete a Hotel") | |
| 70 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 71 | @DeleteMapping("") | |
| 72 | public Object deleteHotel( | |
| 73 | @ApiParam("id") @RequestParam Long id) { | |
| 74 | Hotel hotel = hotelRepository.findById(id) | |
| 75 |
1
1. lambda$deleteHotel$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::lambda$deleteHotel$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Hotel.class, id)); |
| 76 | ||
| 77 |
1
1. deleteHotel : removed call to edu/ucsb/cs156/example/repositories/HotelRepository::delete → KILLED |
hotelRepository.delete(hotel); |
| 78 |
1
1. deleteHotel : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::deleteHotel → KILLED |
return genericMessage("Hotel with id %s deleted".formatted(id)); |
| 79 | } | |
| 80 | ||
| 81 | @ApiOperation(value = "Update a single hotel") | |
| 82 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 83 | @PutMapping("") | |
| 84 | public Hotel updateHotel( | |
| 85 | @ApiParam("id") @RequestParam Long id, | |
| 86 | @RequestBody @Valid Hotel incoming) { | |
| 87 | ||
| 88 | Hotel hotel = hotelRepository.findById(id) | |
| 89 |
1
1. lambda$updateHotel$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::lambda$updateHotel$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Hotel.class, id)); |
| 90 | ||
| 91 |
1
1. updateHotel : removed call to edu/ucsb/cs156/example/entities/Hotel::setName → KILLED |
hotel.setName(incoming.getName()); |
| 92 |
1
1. updateHotel : removed call to edu/ucsb/cs156/example/entities/Hotel::setAddress → KILLED |
hotel.setAddress(incoming.getAddress()); |
| 93 |
1
1. updateHotel : removed call to edu/ucsb/cs156/example/entities/Hotel::setDescription → KILLED |
hotel.setDescription(incoming.getDescription()); |
| 94 | ||
| 95 | hotelRepository.save(hotel); | |
| 96 | ||
| 97 |
1
1. updateHotel : replaced return value with null for edu/ucsb/cs156/example/controllers/HotelsController::updateHotel → KILLED |
return hotel; |
| 98 | } | |
| 99 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 66 |
1.1 |
|
| 75 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 89 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 97 |
1.1 |