From b7efb56646fec5fc93b21ee6e85c850099c0d422 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 13 May 2023 20:54:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D1=80=D0=BE=D0=BC=D0=B5=20map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookshop/service/AuthorService.java | 4 +-- .../bookshop/service/BookService.java | 4 +-- .../spa-vue/src/components/Header.vue | 4 +-- .../frontend/spa-vue/src/pages/Authors.vue | 1 - .../frontend/spa-vue/src/pages/Index.vue | 34 ------------------- 5 files changed, 6 insertions(+), 41 deletions(-) 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{