From db56ae0169c28fa61b2185a720bd8c9d2721d26c Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Mon, 5 Feb 2024 00:13:13 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20=EC=9C=A0=EC=A0=80=EC=95=84=EC=9D=B4?= =?UTF-8?q?=EB=94=94=EB=A5=BC=20=ED=8C=8C=EB=9D=BC=EB=A7=A4=ED=84=B0?= =?UTF-8?q?=EC=97=90=20=EB=84=A3=EC=96=B4=EC=84=9C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#37)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 유저아이디를 파라매터로 받음에 따라 쿼리문 몇 글자 추가 --- .../kuit/chatdiary/controller/diary/TagSearchController.java | 4 ++-- .../kuit/chatdiary/repository/diary/TagSearchRepository.java | 5 +++-- .../com/kuit/chatdiary/service/diary/TagSearchService.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/kuit/chatdiary/controller/diary/TagSearchController.java b/src/main/java/com/kuit/chatdiary/controller/diary/TagSearchController.java index 94eb5ce8..af3206f7 100644 --- a/src/main/java/com/kuit/chatdiary/controller/diary/TagSearchController.java +++ b/src/main/java/com/kuit/chatdiary/controller/diary/TagSearchController.java @@ -17,7 +17,7 @@ public TagSearchController(TagSearchService tagSearchService) { this.tagSearchService = tagSearchService; } @GetMapping("/list/tag") - public List findByTag(@RequestParam(name = "tagName") List tagNames) { - return tagSearchService.findByTag(tagNames); + public List findByTag(@RequestParam("userId") Long userId, @RequestParam(name = "tagName") List tagNames) { + return tagSearchService.findByTag(tagNames,userId); } } diff --git a/src/main/java/com/kuit/chatdiary/repository/diary/TagSearchRepository.java b/src/main/java/com/kuit/chatdiary/repository/diary/TagSearchRepository.java index 51b78465..5647ec36 100644 --- a/src/main/java/com/kuit/chatdiary/repository/diary/TagSearchRepository.java +++ b/src/main/java/com/kuit/chatdiary/repository/diary/TagSearchRepository.java @@ -18,16 +18,17 @@ public TagSearchRepository(EntityManager em) { /** 지식 한계로 쿼리문 세개를 나눠서.. */ - public List findByTag(List tagName) { + public List findByTag(List tagName, Long userId) { int tagCount = tagName.size(); List diaries = em.createQuery( "SELECT d FROM diary d " + "JOIN diarytag dt ON d.diaryId = dt.diary.diaryId " + "JOIN tag t ON dt.tag.tagId = t.tagId " + - "WHERE t.tagName IN :tagNames " + + "WHERE t.tagName IN :tagNames AND d.member.userId = :userId " + "GROUP BY d " + "HAVING COUNT(DISTINCT t) = :tagCount", Diary.class) .setParameter("tagNames", tagName) + .setParameter("userId", userId) .setParameter("tagCount", (long) tagCount) .getResultList(); diff --git a/src/main/java/com/kuit/chatdiary/service/diary/TagSearchService.java b/src/main/java/com/kuit/chatdiary/service/diary/TagSearchService.java index 5e468f7f..48517bb0 100644 --- a/src/main/java/com/kuit/chatdiary/service/diary/TagSearchService.java +++ b/src/main/java/com/kuit/chatdiary/service/diary/TagSearchService.java @@ -12,8 +12,8 @@ public class TagSearchService { public TagSearchService(TagSearchRepository tagSearchRepository) { this.tagSearchRepository = tagSearchRepository; } - public List findByTag(List tagNames){ - return tagSearchRepository.findByTag(tagNames); + public List findByTag(List tagNames,long userId){ + return tagSearchRepository.findByTag(tagNames,userId); } } \ No newline at end of file