| 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 | 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.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | import javax.validation.Valid; | |
| 26 | ||
| 27 | import java.time.LocalDateTime; | |
| 28 | ||
| 29 | @Api(description = "Book") | |
| 30 | @RequestMapping("/api/books") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | public class BookController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | BookRepository BookRepository; | |
| 37 | ||
| 38 | @ApiOperation(value = "List all ucsb dates") | |
| 39 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 40 | @GetMapping("/all") | |
| 41 | public Iterable<Book> allBooks() { | |
| 42 | Iterable<Book> dates = BookRepository.findAll(); | |
| 43 |
1
1. allBooks : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::allBooks → KILLED |
return dates; |
| 44 | } | |
| 45 | ||
| 46 | @ApiOperation(value = "Get a single date") | |
| 47 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 48 | @GetMapping("") | |
| 49 | public Book getById( | |
| 50 | @ApiParam("id") @RequestParam Long id) { | |
| 51 | Book Book = BookRepository.findById(id) | |
| 52 |
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)); |
| 53 | ||
| 54 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::getById → KILLED |
return Book; |
| 55 | } | |
| 56 | ||
| 57 | @ApiOperation(value = "Create a new date") | |
| 58 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 59 | @PostMapping("/post") | |
| 60 | public Book postBook( | |
| 61 | @ApiParam("title") @RequestParam String title, | |
| 62 | @ApiParam("author") @RequestParam String author, | |
| 63 | @ApiParam("genre") @RequestParam String genre) | |
| 64 | throws JsonProcessingException { | |
| 65 | ||
| 66 | ||
| 67 | ||
| 68 | Book Book = new Book(); | |
| 69 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setTitle → KILLED |
Book.setTitle(title); |
| 70 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setAuthor → KILLED |
Book.setAuthor(author); |
| 71 |
1
1. postBook : removed call to edu/ucsb/cs156/example/entities/Book::setGenre → KILLED |
Book.setGenre(genre); |
| 72 | ||
| 73 | Book savedBook = BookRepository.save(Book); | |
| 74 | ||
| 75 |
1
1. postBook : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::postBook → KILLED |
return savedBook; |
| 76 | } | |
| 77 | ||
| 78 | @ApiOperation(value = "Delete a Book") | |
| 79 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 80 | @DeleteMapping("") | |
| 81 | public Object deleteBook( | |
| 82 | @ApiParam("id") @RequestParam Long id) { | |
| 83 | Book Book = BookRepository.findById(id) | |
| 84 |
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)); |
| 85 | ||
| 86 |
1
1. deleteBook : removed call to edu/ucsb/cs156/example/repositories/BookRepository::delete → KILLED |
BookRepository.delete(Book); |
| 87 |
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)); |
| 88 | } | |
| 89 | ||
| 90 | @ApiOperation(value = "Update a single date") | |
| 91 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 92 | @PutMapping("") | |
| 93 | public Book updateBook( | |
| 94 | @ApiParam("id") @RequestParam Long id, | |
| 95 | @RequestBody @Valid Book incoming) { | |
| 96 | ||
| 97 | Book Book = BookRepository.findById(id) | |
| 98 |
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)); |
| 99 | ||
| 100 |
1
1. updateBook : removed call to edu/ucsb/cs156/example/entities/Book::setTitle → KILLED |
Book.setTitle(incoming.getTitle()); |
| 101 |
1
1. updateBook : removed call to edu/ucsb/cs156/example/entities/Book::setAuthor → KILLED |
Book.setAuthor(incoming.getAuthor()); |
| 102 |
1
1. updateBook : removed call to edu/ucsb/cs156/example/entities/Book::setGenre → KILLED |
Book.setGenre(incoming.getGenre()); |
| 103 | ||
| 104 | BookRepository.save(Book); | |
| 105 | ||
| 106 |
1
1. updateBook : replaced return value with null for edu/ucsb/cs156/example/controllers/BookController::updateBook → KILLED |
return Book; |
| 107 | } | |
| 108 | } | |
Mutations | ||
| 43 |
1.1 |
|
| 52 |
1.1 |
|
| 54 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 75 |
1.1 |
|
| 84 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 98 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 106 |
1.1 |