Skip to content

Commit

Permalink
Feat : 유저아이디를 파라매터에 넣어서 로직 변경 (#37)
Browse files Browse the repository at this point in the history
유저아이디를 파라매터로 받음에 따라 쿼리문 몇 글자 추가
  • Loading branch information
Mouon authored Feb 4, 2024
1 parent fb04fde commit db56ae0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public TagSearchController(TagSearchService tagSearchService) {
this.tagSearchService = tagSearchService;
}
@GetMapping("/list/tag")
public List<TagSearchResponseDTO> findByTag(@RequestParam(name = "tagName") List<String> tagNames) {
return tagSearchService.findByTag(tagNames);
public List<TagSearchResponseDTO> findByTag(@RequestParam("userId") Long userId, @RequestParam(name = "tagName") List<String> tagNames) {
return tagSearchService.findByTag(tagNames,userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public TagSearchRepository(EntityManager em) {


/** 지식 한계로 쿼리문 세개를 나눠서.. */
public List<TagSearchResponseDTO> findByTag(List<String> tagName) {
public List<TagSearchResponseDTO> findByTag(List<String> tagName, Long userId) {
int tagCount = tagName.size();
List<Diary> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class TagSearchService {
public TagSearchService(TagSearchRepository tagSearchRepository) {
this.tagSearchRepository = tagSearchRepository;
}
public List<TagSearchResponseDTO> findByTag(List<String> tagNames){
return tagSearchRepository.findByTag(tagNames);
public List<TagSearchResponseDTO> findByTag(List<String> tagNames,long userId){
return tagSearchRepository.findByTag(tagNames,userId);
}

}

0 comments on commit db56ae0

Please sign in to comment.