Skip to content

Commit b30807d

Browse files
committed
update and delete Library updates
1 parent c26ed9e commit b30807d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main/java/com/learn/SpringBootRESTService/LibraryController.java

+25
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import org.springframework.http.HttpStatus;
88
import org.springframework.http.HttpStatusCode;
99
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.DeleteMapping;
1011
import org.springframework.web.bind.annotation.GetMapping;
1112
import org.springframework.web.bind.annotation.PathVariable;
1213
import org.springframework.web.bind.annotation.PostMapping;
14+
import org.springframework.web.bind.annotation.PutMapping;
1315
import org.springframework.web.bind.annotation.RequestBody;
1416
import org.springframework.web.bind.annotation.RequestParam;
17+
import org.springframework.web.bind.annotation.ResponseBody;
1518
import org.springframework.web.bind.annotation.RestController;
1619
import org.springframework.web.server.ResponseStatusException;
1720

@@ -72,4 +75,26 @@ public List<Library> getBookByAuthorName(@RequestParam(value = "authorname")Stri
7275
return repository.findAllByAuthor(authorname);
7376
}
7477

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+
75100
}

0 commit comments

Comments
 (0)