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