1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.Book; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.BookRepository; | |
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 = "Books") | |
26 | @RequestMapping("/api/books") | |
27 | @RestController | |
28 | public class BookController extends ApiController { | |
29 | ||
30 | @Autowired | |
31 | BookRepository bookRepository; | |
32 | ||
33 | @ApiOperation(value = "List all books") | |
34 | @PreAuthorize("hasRole('ROLE_USER')") | |
35 | @GetMapping("/all") | |
36 | public Iterable<Book> allBooks() { | |
37 | Iterable<Book> books = bookRepository.findAll(); | |
38 |
1
1. allBooks : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::allBooks → KILLED |
return books; |
39 | } | |
40 | ||
41 | @ApiOperation(value = "Get a single book") | |
42 | @PreAuthorize("hasRole('ROLE_USER')") | |
43 | @GetMapping("") | |
44 | public Book getById( | |
45 | @ApiParam("id") @RequestParam Long id) { | |
46 | Book book = bookRepository.findById(id) | |
47 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Book.class, id)); |
48 | ||
49 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::getById → KILLED |
return book; |
50 | } | |
51 | ||
52 | @ApiOperation(value = "Create a new book") | |
53 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
54 | @PostMapping("/post") | |
55 | public Book postBook( | |
56 | @ApiParam("title") @RequestParam String title, | |
57 | @ApiParam("author") @RequestParam String author, | |
58 | @ApiParam("year") @RequestParam String year) | |
59 | throws JsonProcessingException { | |
60 | ||
61 | Book book = new Book(); | |
62 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setTitle → KILLED |
book.setTitle(title); |
63 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setAuthor → KILLED |
book.setAuthor(author); |
64 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setYear → KILLED |
book.setYear(year); |
65 | ||
66 | Book savedBook = bookRepository.save(book); | |
67 | ||
68 |
1
1. postBook : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::postBook → KILLED |
return savedBook; |
69 | } | |
70 | ||
71 | @ApiOperation(value = "Delete a Book") | |
72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
73 | @DeleteMapping("") | |
74 | public Object deleteBook( | |
75 | @ApiParam("id") @RequestParam Long id) { | |
76 | Book book = bookRepository.findById(id) | |
77 |
1
1. lambda$deleteBook$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::lambda$deleteBook$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Book.class, id)); |
78 | ||
79 |
1
1. deleteBook : removed call to edu/ucsb/cs156/example/repositories/BookRepository::delete → KILLED |
bookRepository.delete(book); |
80 |
1
1. deleteBook : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::deleteBook → KILLED |
return genericMessage("Book with id %s deleted".formatted(id)); |
81 | } | |
82 | ||
83 | @ApiOperation(value = "Update a single book") | |
84 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
85 | @PutMapping("") | |
86 | public Book updateBook( | |
87 | @ApiParam("id") @RequestParam Long id, | |
88 | @RequestBody @Valid Book incoming) { | |
89 | ||
90 | Book book = bookRepository.findById(id) | |
91 |
1
1. lambda$updateBook$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::lambda$updateBook$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Book.class, id)); |
92 | ||
93 |
1
1. updateBook : removed call to edu/ucsb/cs156/example/entities/Book::updateFrom → KILLED |
book.updateFrom(incoming); |
94 | | |
95 | bookRepository.save(book); | |
96 | ||
97 |
1
1. updateBook : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::updateBook → KILLED |
return book; |
98 | } | |
99 | } | |
Mutations | ||
38 |
1.1 |
|
47 |
1.1 |
|
49 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
68 |
1.1 |
|
77 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
91 |
1.1 |
|
93 |
1.1 |
|
97 |
1.1 |