From 83673a42b81b5c034b03f0b08a7416da48d9e2c2 Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Mon, 3 Apr 2023 14:43:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/LabWork/app/student/service/MangaService.java | 5 ++++- src/test/java/com/LabWork/app/ReMangaTest.java | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/LabWork/app/student/service/MangaService.java b/src/main/java/com/LabWork/app/student/service/MangaService.java index d39e634..96cccbd 100644 --- a/src/main/java/com/LabWork/app/student/service/MangaService.java +++ b/src/main/java/com/LabWork/app/student/service/MangaService.java @@ -63,7 +63,10 @@ public class MangaService { public List getReader(Long id) { //em.createNativeQuery("delete from Mangas_Readers where MANGA_FK = " + manga.getId() + " AND READER_FK = "+ readerId).executeUpdate(); //SELECT b FROM Book b WHERE ?1 MEMBER OF b.genres - final List listReader = em.createQuery("select r from Reader r where " + id + " MEMBER OF r.mangas", Reader.class).getResultList(); + final Manga currentManga = em.find(Manga.class, id); + final List listReader = em.createQuery("select r from Reader r where :currentManga MEMBER OF r.mangas", Reader.class) + .setParameter("currentManga", currentManga) + .getResultList(); return listReader; } diff --git a/src/test/java/com/LabWork/app/ReMangaTest.java b/src/test/java/com/LabWork/app/ReMangaTest.java index 82990cd..1d4b715 100644 --- a/src/test/java/com/LabWork/app/ReMangaTest.java +++ b/src/test/java/com/LabWork/app/ReMangaTest.java @@ -13,6 +13,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + @SpringBootTest public class ReMangaTest { @Autowired @@ -44,9 +46,10 @@ public class ReMangaTest { Reader r4 = readerService.findReader(r1.getId()); log.info(r4.getMangas().toString()); - //List listReader = mangaService.getReader(m1.getId()); - //log.info(listReader); - Assertions.assertEquals(2, mangaService.getReader(m1.getId()).size()); + List listReader = mangaService.getReader(m1.getId()); + log.info(listReader.toString()); + Assertions.assertEquals(true, mangaService.getReader(m1.getId()).contains(r4)); + Assertions.assertEquals(true, mangaService.getReader(m1.getId()).contains(r2)); readerService.deleteAllReaders(); mangaService.deleteAllMangas(); creatorService.deleteAllCreators();