diff --git a/src/main/java/ru/ip/labworks/labworks/bookshop/service/AuthorService.java b/src/main/java/ru/ip/labworks/labworks/bookshop/service/AuthorService.java index fcffae2..9e0b4bb 100644 --- a/src/main/java/ru/ip/labworks/labworks/bookshop/service/AuthorService.java +++ b/src/main/java/ru/ip/labworks/labworks/bookshop/service/AuthorService.java @@ -107,7 +107,7 @@ public class AuthorService { @Transactional public void addBookToAuthor(Long id, Long bookId){ Optional author = authorRepository.findById(id); - if (author.isPresent()){ + if (author.isPresent() && !author.get().getBooks().contains(bookRepository.findById(bookId).get())){ author.get().addBook(bookRepository.findById(bookId).get()); } authorRepository.save(author.get()); @@ -116,7 +116,7 @@ public class AuthorService { @Transactional public void removeBookFromAuthor(Long id, Long bookId){ Optional author = authorRepository.findById(id); - if(author.isPresent()){ + if(author.isPresent() && author.get().getBooks().contains(bookRepository.findById(bookId).get())){ author.get().removeBook(bookRepository.findById(bookId).get()); } authorRepository.save(author.get()); diff --git a/src/main/java/ru/ip/labworks/labworks/bookshop/service/BookService.java b/src/main/java/ru/ip/labworks/labworks/bookshop/service/BookService.java index 9a0d5e9..d95b607 100644 --- a/src/main/java/ru/ip/labworks/labworks/bookshop/service/BookService.java +++ b/src/main/java/ru/ip/labworks/labworks/bookshop/service/BookService.java @@ -112,7 +112,7 @@ public class BookService { @Transactional public void addGenreToBook(Long id, Long genreId){ Optional book = bookRepository.findById(id); - if (book.isPresent()){ + if (book.isPresent() && !book.get().getGenres().contains(genreRepository.findById(genreId).get())){ book.get().addGenre(genreRepository.findById(genreId).get()); } bookRepository.save(book.get()); @@ -121,7 +121,7 @@ public class BookService { @Transactional public void removeGenreFromBook(Long id, Long genreId){ Optional book = bookRepository.findById(id); - if(book.isPresent()){ + if(book.isPresent() && book.get().getGenres().contains(genreRepository.findById(genreId).get())){ book.get().removeGenre(genreRepository.findById(genreId).get()); } bookRepository.save(book.get()); diff --git a/src/main/resources/frontend/spa-vue/src/components/Header.vue b/src/main/resources/frontend/spa-vue/src/components/Header.vue index 2a289e5..841fd56 100644 --- a/src/main/resources/frontend/spa-vue/src/components/Header.vue +++ b/src/main/resources/frontend/spa-vue/src/components/Header.vue @@ -11,8 +11,8 @@ diff --git a/src/main/resources/frontend/spa-vue/src/pages/Authors.vue b/src/main/resources/frontend/spa-vue/src/pages/Authors.vue index bf2a223..502d54e 100644 --- a/src/main/resources/frontend/spa-vue/src/pages/Authors.vue +++ b/src/main/resources/frontend/spa-vue/src/pages/Authors.vue @@ -4,7 +4,6 @@ import axios from "axios"; import Header from '../components/Header.vue'; import Footer from '../components/Footer.vue'; import Author from '../models/Author'; -import Book from '../models/Book'; export default{ components:{ Header, diff --git a/src/main/resources/frontend/spa-vue/src/pages/Index.vue b/src/main/resources/frontend/spa-vue/src/pages/Index.vue index 081887e..7eae3d5 100644 --- a/src/main/resources/frontend/spa-vue/src/pages/Index.vue +++ b/src/main/resources/frontend/spa-vue/src/pages/Index.vue @@ -33,40 +33,6 @@ export default{