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