From f7ad06d26280286321777288b1b22e0341b64373 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Tue, 18 Apr 2023 11:31:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 237568 -> 831488 bytes data.trace.db | 1232 +++++++++++++++++ .../bookshop/service/AuthorService.java | 23 +- .../ip/labworks/labworks/JpaAuthorTests.java | 12 +- .../ru/ip/labworks/labworks/JpaBookTests.java | 2 +- .../ip/labworks/labworks/JpaGenreTests.java | 1 - 6 files changed, 1256 insertions(+), 14 deletions(-) diff --git a/data.mv.db b/data.mv.db index 3fb4b99a1796c2f870e709aacfa0032c4e2c4080..5d3937aa6ca94dfc4cc42b3e3ca6c6ddfdf39b6b 100644 GIT binary patch delta 12876 zcmeI3dyEy;9mmhPkKM~Y*cA{0g|fgR+Fq79GiP2~fx7__|9}{A(VD2t6Uo9ZkHyDo zvrDCI+9nE2>TOKh*rt!96zz&BOW1ydXKinA%dbb68 zyIta_Ce@9m(LMLK9Uf^q(%y9Q|D>OehES);4^zuK15j_2cR9PeRUeu=;TIUDQtl7# z9PIYo@@{8)u&-M$?;RKz>?S(=c171+%{Iz|J9Y)#R8=fHw6b4F%Yy?Re9?8hXmr*3 zE1M8PA4mT{4H&(Fi}fgabL%VlW{ieVacJXUuy2qb+TK5V_H0}J4R%+A3TLjns({*1i9eez8i|Zru0};rN-;KuiiJdgtb4!^x<5YBFX-jG2~?$Q3}^Ytw7d9z5|*% z_zERLl+OoB_0o~@d>Lp`E?L?*}WHOyjplH$qv?kQ0Wx5F0rMjL*BxPans2Hu7 zErq^rYDXVjzBC;z%M{~fIf)Qc2!WXd^l>d&hykF9XHvQt>n4_@OO3}%F#=Q4WrhpB zEre;wh(Y%Z4wOWjZ(S(KvufdxjuXr&kmq@_Jdj-f{3JbEqQ|6~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*_MM98=}#3-P$y$3Ry2wkO!*g-JEB~(!uMMaDWto|7#tnvLm!1wrQ1dzg>+RH7OP_^3*ewaC&=PDfP>)O zW@pPJQXRk9;GLTHlngTlSNa9-kc_PETqIvvs9!ypxJ3o;f7#sOIOkRQhXot8DtNc8 z@N5|0^FGVsLeu``>u1Aw^8#v(jj7&msYl8G|HJsF3Ns8eLvNsF%> AllAuthorsAndBooks(){ - Map> result = new HashMap<>(); - List tempList = findAllAuthors(); - for (Author author : tempList){ - result.put(author, author.getBooks()); - } - return result; + public Map> AllAuthorsAndBooks(){ + List temp = entityManager.createQuery("select a.lastname as author, b.name as book " + + "from Author a " + + "join a.books b " + + "group by a.id").getResultList(); + return temp.stream() + .collect( + Collectors.groupingBy( + o -> (String) o[0], + Collectors.mapping( o -> (String) o[1], Collectors.toList() ) + ) + ); } } diff --git a/src/test/java/ru/ip/labworks/labworks/JpaAuthorTests.java b/src/test/java/ru/ip/labworks/labworks/JpaAuthorTests.java index d852ffa..d50a055 100644 --- a/src/test/java/ru/ip/labworks/labworks/JpaAuthorTests.java +++ b/src/test/java/ru/ip/labworks/labworks/JpaAuthorTests.java @@ -8,13 +8,12 @@ import ru.ip.labworks.labworks.bookshop.model.Author; import ru.ip.labworks.labworks.bookshop.model.Book; import ru.ip.labworks.labworks.bookshop.service.AuthorService; import ru.ip.labworks.labworks.bookshop.service.BookService; - -import javax.imageio.ImageIO; import javax.persistence.EntityNotFoundException; -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @SpringBootTest public class JpaAuthorTests { @@ -107,6 +106,11 @@ public class JpaAuthorTests { Author author = authorService.addAuthor("Test", "Test", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\SK.jpg")); final Book book = bookService.addBook("Test2", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png")); authorService.addBookToAuthor(author.getId(), book); + Map> result = new HashMap<>(); + List temp = new ArrayList<>(); + temp.add(book.getName()); + result.put(author.getLastName(), temp); + Assertions.assertEquals(authorService.AllAuthorsAndBooks(), result); Assertions.assertNotNull(authorService.AllAuthorsAndBooks()); } } diff --git a/src/test/java/ru/ip/labworks/labworks/JpaBookTests.java b/src/test/java/ru/ip/labworks/labworks/JpaBookTests.java index b5d6633..739cc06 100644 --- a/src/test/java/ru/ip/labworks/labworks/JpaBookTests.java +++ b/src/test/java/ru/ip/labworks/labworks/JpaBookTests.java @@ -89,7 +89,7 @@ public class JpaBookTests { } @Test - void TestRemoveBookFromAuthor(){ + void TestRemoveGenreFromBook(){ bookService.deleteAllBooks(); genreService.deleteAllGenres(); Book book = bookService.addBook("Test", "03.04.2023", new File("D:\\Учёба\\Интернет программирование\\PIbd-22_Bondarenko_M.S._IP\\src\\main\\resources\\glow.png")); diff --git a/src/test/java/ru/ip/labworks/labworks/JpaGenreTests.java b/src/test/java/ru/ip/labworks/labworks/JpaGenreTests.java index 672e249..22966e7 100644 --- a/src/test/java/ru/ip/labworks/labworks/JpaGenreTests.java +++ b/src/test/java/ru/ip/labworks/labworks/JpaGenreTests.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import ru.ip.labworks.labworks.bookshop.model.Book; import ru.ip.labworks.labworks.bookshop.model.Genre; import ru.ip.labworks.labworks.bookshop.service.GenreService;