Skip to content

Commit

Permalink
add possibility to delete a book
Browse files Browse the repository at this point in the history
  • Loading branch information
USER3411 committed Jun 12, 2021
1 parent a4bd30c commit 23ae34c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/dj/personal/website/book/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public Collection<Book> findAll() {
public Book save(@RequestBody Book book) {
return bookService.save(book);
}

@DeleteMapping(path = "/{isbn}")
@RolesAllowed(Role.ADMIN)
public void delete(@PathVariable Long isbn){
bookService.deleteByIsbn(isbn);
}
}
1 change: 1 addition & 0 deletions src/main/java/dj/personal/website/book/BookRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

interface BookRepository extends JpaRepository<Book, Long> {
void deleteByIsbn(Long isbn);
}
4 changes: 4 additions & 0 deletions src/main/java/dj/personal/website/book/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public Collection<Book> getBooks() {
public Book save(Book book) {
return bookRepository.save(book);
}

public void deleteByIsbn(Long isbn) {
bookRepository.deleteByIsbn(isbn);
}
}

0 comments on commit 23ae34c

Please sign in to comment.