|
7 | 7 | import org.springframework.http.HttpStatus;
|
8 | 8 | import org.springframework.http.HttpStatusCode;
|
9 | 9 | import org.springframework.http.ResponseEntity;
|
| 10 | +import org.springframework.web.bind.annotation.DeleteMapping; |
10 | 11 | import org.springframework.web.bind.annotation.GetMapping;
|
11 | 12 | import org.springframework.web.bind.annotation.PathVariable;
|
12 | 13 | import org.springframework.web.bind.annotation.PostMapping;
|
| 14 | +import org.springframework.web.bind.annotation.PutMapping; |
13 | 15 | import org.springframework.web.bind.annotation.RequestBody;
|
14 | 16 | import org.springframework.web.bind.annotation.RequestParam;
|
| 17 | +import org.springframework.web.bind.annotation.ResponseBody; |
15 | 18 | import org.springframework.web.bind.annotation.RestController;
|
16 | 19 | import org.springframework.web.server.ResponseStatusException;
|
17 | 20 |
|
@@ -72,4 +75,26 @@ public List<Library> getBookByAuthorName(@RequestParam(value = "authorname")Stri
|
72 | 75 | return repository.findAllByAuthor(authorname);
|
73 | 76 | }
|
74 | 77 |
|
| 78 | + @PutMapping("/updateBook/{id}") |
| 79 | + public ResponseEntity<Library> updateBook(@PathVariable (value ="id")String id, @RequestBody Library library) { |
| 80 | + Library existingBook = repository.findById(id).get(); |
| 81 | + existingBook.setAisle(library.getAisle()); |
| 82 | + existingBook.setBook_name(library.getBook_name()); |
| 83 | + existingBook.setAuthor(library.getAuthor()); |
| 84 | + repository.save(existingBook); |
| 85 | + |
| 86 | + return new ResponseEntity<Library>(existingBook,HttpStatus.OK); |
| 87 | + } |
| 88 | + |
| 89 | + @DeleteMapping("/deleteBook") |
| 90 | + public ResponseEntity deleteBookByID(@RequestBody Library library){ |
| 91 | + Library libToDelete = repository.findById(library.getId()).get(); |
| 92 | + repository.delete(libToDelete); |
| 93 | + |
| 94 | + return new ResponseEntity<>("Book is deleted",HttpStatus.CREATED); |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
75 | 100 | }
|
0 commit comments