From ae3c1960aa06aba8dfec00b3cde2fdea8292783b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:52:23 +0900 Subject: [PATCH 01/11] =?UTF-8?q?refactor(repository):=20template=20tag=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EB=B0=9C=EC=83=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20N=20+=201=20=EA=B0=9C=EC=84=A0=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20JPQL=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/TemplateTagJpaRepository.java | 8 +++++++ .../tag/repository/TemplateTagRepository.java | 2 ++ .../TemplateTagJpaRepositoryTest.java | 21 +++++++++++++++++++ .../repository/FakeTemplateTagRepository.java | 7 +++++++ 4 files changed, 38 insertions(+) diff --git a/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java b/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java index 322574cef..943294e21 100644 --- a/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java +++ b/backend/src/main/java/codezap/tag/repository/TemplateTagJpaRepository.java @@ -13,6 +13,14 @@ public interface TemplateTagJpaRepository extends TemplateTagRepository, JpaRepo List findAllByTemplate(Template template); + @Query(""" + SELECT tt, t + FROM TemplateTag tt + JOIN FETCH tt.tag t + WHERE tt.id.templateId = :templateId + """) + List findAllByTemplateId(Long templateId); + @Query(""" SELECT DISTINCT tt.id.tagId FROM TemplateTag tt diff --git a/backend/src/main/java/codezap/tag/repository/TemplateTagRepository.java b/backend/src/main/java/codezap/tag/repository/TemplateTagRepository.java index e1f47840f..d6212839d 100644 --- a/backend/src/main/java/codezap/tag/repository/TemplateTagRepository.java +++ b/backend/src/main/java/codezap/tag/repository/TemplateTagRepository.java @@ -9,6 +9,8 @@ public interface TemplateTagRepository { List findAllByTemplate(Template template); + List findAllByTemplateId(Long templateId); + List findDistinctByTemplateIn(List templateIds); TemplateTag save(TemplateTag templateTag); diff --git a/backend/src/test/java/codezap/tag/repository/TemplateTagJpaRepositoryTest.java b/backend/src/test/java/codezap/tag/repository/TemplateTagJpaRepositoryTest.java index 97edf2bc5..729a9de84 100644 --- a/backend/src/test/java/codezap/tag/repository/TemplateTagJpaRepositoryTest.java +++ b/backend/src/test/java/codezap/tag/repository/TemplateTagJpaRepositoryTest.java @@ -71,6 +71,27 @@ void findAllByTemplateTest() { .doesNotContain(new TemplateTag(template, tag3)); } + @Test + @DisplayName("Template Id 을 이용한 TemplateTag 목록 조회 성공") + void findAllByTemplateIdTest() { + //given + Template template = templateRepository.save(createNthTemplate(member, category, 1)); + + Tag tag1 = tagRepository.save(new Tag("tag1")); + Tag tag2 = tagRepository.save(new Tag("tag2")); + Tag tag3 = tagRepository.save(new Tag("tag3")); + + TemplateTag templateTag1 = templateTagRepository.save(new TemplateTag(template, tag1)); + TemplateTag templateTag2 = templateTagRepository.save(new TemplateTag(template, tag2)); + + //when + List templateTags = templateTagRepository.findAllByTemplateId(template.getId()); + + //then + assertThat(templateTags).containsExactly(templateTag1, templateTag2) + .doesNotContain(new TemplateTag(template, tag3)); + } + @Nested @DisplayName("템플릿 id 목록이 사용하는 모든 태그 목록을 조회") class FindDistinctByTemplateIn { diff --git a/backend/src/test/java/codezap/template/repository/FakeTemplateTagRepository.java b/backend/src/test/java/codezap/template/repository/FakeTemplateTagRepository.java index d6dba3394..35b72f808 100644 --- a/backend/src/test/java/codezap/template/repository/FakeTemplateTagRepository.java +++ b/backend/src/test/java/codezap/template/repository/FakeTemplateTagRepository.java @@ -23,6 +23,13 @@ public List findAllByTemplate(Template template) { .toList(); } + @Override + public List findAllByTemplateId(Long templateId) { + return templateTags.stream() + .filter(templateTag -> Objects.equals(templateTag.getTemplate(), templateId)) + .toList(); + } + @Override public TemplateTag save(TemplateTag entity) { var saved = new TemplateTag( From c158416aaa64fee5d97bd0a3100add58d8f79b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98jminkkk=E2=80=99?= <102847513+jminkkk@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:53:30 +0900 Subject: [PATCH 02/11] =?UTF-8?q?refactor(service):=20N=20+=201=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=EB=90=9C=20tag=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=97=AC=20=EB=B3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/codezap/tag/service/TagService.java | 6 +++ .../facade/TemplateApplicationService.java | 2 +- .../codezap/tag/service/TagServiceTest.java | 53 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/codezap/tag/service/TagService.java b/backend/src/main/java/codezap/tag/service/TagService.java index cc7408527..fbbcb72d5 100644 --- a/backend/src/main/java/codezap/tag/service/TagService.java +++ b/backend/src/main/java/codezap/tag/service/TagService.java @@ -52,6 +52,12 @@ public List findAllByTemplate(Template template) { .toList(); } + public List findAllByTemplateId(Long templateId) { + return templateTagRepository.findAllByTemplateId(templateId).stream() + .map(TemplateTag::getTag) + .toList(); + } + public FindAllTagsResponse findAllByMemberId(Long memberId) { List