Skip to content

Commit

Permalink
#39 - Fix: 상품과 관련된 글을 조회할 때 해당 키워드와 관련된 다른 작가의 글까지 조회되는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Nov 10, 2022
1 parent 30980c6 commit 67d55ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public MyBookDetailDto findByIdForDetail(long id) {
MyBook myBook = findById(id);

PostKeyword postKeyword = myBook.getProduct().getPostKeyword();
List<PostHashTag> postHashTags = postHashTagService.findByPostKeyword(postKeyword);
Member author = myBook.getProduct().getAuthor();

// 해당 작가, 키워드와 관련된 글만 조회
List<PostHashTag> postHashTags = postHashTagService.findByPostKeywordAndMember(postKeyword, author);

List<Post> posts = postHashTags.stream()
.map(postHashTag -> postHashTag.getPost())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.mutbooks.app.postHashTag.repository;

import com.example.mutbooks.app.member.entity.Member;
import com.example.mutbooks.app.postHashTag.entity.PostHashTag;
import com.example.mutbooks.app.postKeyword.entity.PostKeyword;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -12,5 +13,5 @@ public interface PostHashTagRepository extends JpaRepository<PostHashTag, Long>

List<PostHashTag> findByPostId(Long postId);

List<PostHashTag> findByPostKeyword(PostKeyword postKeyword);
List<PostHashTag> findByPostKeywordAndMember(PostKeyword postKeyword, Member member);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.example.mutbooks.app.postHashTag.service;

import com.example.mutbooks.app.member.entity.Member;
import com.example.mutbooks.app.post.entity.Post;
import com.example.mutbooks.app.postHashTag.entity.PostHashTag;
import com.example.mutbooks.app.postHashTag.repository.PostHashTagRepository;
import com.example.mutbooks.app.postKeyword.entity.PostKeyword;
import com.example.mutbooks.app.postKeyword.service.PostKeywordService;
import com.example.mutbooks.app.post.entity.Post;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -78,7 +79,7 @@ public List<PostHashTag> findByPostId(long postId) {
return postHashTagRepository.findByPostId(postId);
}

public List<PostHashTag> findByPostKeyword(PostKeyword postKeyword) {
return postHashTagRepository.findByPostKeyword(postKeyword);
public List<PostHashTag> findByPostKeywordAndMember(PostKeyword postKeyword, Member member) {
return postHashTagRepository.findByPostKeywordAndMember(postKeyword, member);
}
}

0 comments on commit 67d55ee

Please sign in to comment.