diff --git a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagPersistenceAdapter.java b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagPersistenceAdapter.java index 39d4836b0..3c4391243 100644 --- a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagPersistenceAdapter.java +++ b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagPersistenceAdapter.java @@ -38,7 +38,7 @@ public List getAllIncludingDeletedByBoardId(Long boardId) { .collect(Collectors.toList()); } - public List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable) { - return repository.getBoardIdsByHashTagId(hashtagIds, pageable); + public List getBoardIdsByHashTagId(List hashtagIds) { + return repository.getBoardIdsByHashTagId(hashtagIds, (long)hashtagIds.size()); } } diff --git a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepository.java b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepository.java index 41b9d9889..84ee1ca14 100644 --- a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepository.java +++ b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepository.java @@ -1,16 +1,29 @@ package page.clab.api.domain.community.board.adapter.out.persistence; import java.util.List; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository -public interface BoardHashtagRepository extends JpaRepository, BoardHashtagRepositoryCustom, QuerydslPredicateExecutor { +public interface BoardHashtagRepository extends JpaRepository{ List findAllByBoardId(Long boardId); - @Query(value = "SELECT b.* FROM board_hashtag b WHERE b.board_id = :boardId", nativeQuery = true) + @Query(value = "SELECT b.* " + + "FROM board_hashtag b " + + "WHERE b.board_id = :boardId", + nativeQuery = true) List findAllIncludingDeletedByBoardId(Long boardId); + + @Query("SELECT DISTINCT b.boardId " + + "FROM BoardHashtagJpaEntity b " + + "WHERE b.hashtagId IN :hashtagIds " + + "AND b.isDeleted = false " + + "GROUP BY b.boardId " + + "HAVING COUNT(b.hashtagId) = :size") + List getBoardIdsByHashTagId(@Param("hashtagIds") List hashtagIds, @Param("size") Long size); } diff --git a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryCustom.java b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryCustom.java deleted file mode 100644 index 97644c1c6..000000000 --- a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryCustom.java +++ /dev/null @@ -1,9 +0,0 @@ -package page.clab.api.domain.community.board.adapter.out.persistence; - -import java.util.List; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface BoardHashtagRepositoryCustom { - List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable); -} diff --git a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryImpl.java b/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryImpl.java deleted file mode 100644 index e2a23c601..000000000 --- a/src/main/java/page/clab/api/domain/community/board/adapter/out/persistence/BoardHashtagRepositoryImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package page.clab.api.domain.community.board.adapter.out.persistence; - -import com.querydsl.jpa.JPQLQuery; -import com.querydsl.jpa.impl.JPAQueryFactory; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Repository; - -@Repository -@RequiredArgsConstructor -public class BoardHashtagRepositoryImpl implements BoardHashtagRepositoryCustom { - - private final JPAQueryFactory queryFactory; - - @Override - public List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable) { - QBoardHashtagJpaEntity boardHashtag = QBoardHashtagJpaEntity.boardHashtagJpaEntity; - - JPQLQuery query = queryFactory.selectDistinct(boardHashtag.boardId) - .from(boardHashtag) - .where(boardHashtag.hashtagId.in(hashtagIds) - .and(boardHashtag.isDeleted.eq(false))) - .groupBy(boardHashtag.boardId) - .having(boardHashtag.hashtagId.count().eq((long) hashtagIds.size())); - - return query.fetch(); - } -} diff --git a/src/main/java/page/clab/api/domain/community/board/application/port/out/RetrieveBoardHashtagPort.java b/src/main/java/page/clab/api/domain/community/board/application/port/out/RetrieveBoardHashtagPort.java index b34250bb8..93a12dc34 100644 --- a/src/main/java/page/clab/api/domain/community/board/application/port/out/RetrieveBoardHashtagPort.java +++ b/src/main/java/page/clab/api/domain/community/board/application/port/out/RetrieveBoardHashtagPort.java @@ -10,5 +10,5 @@ public interface RetrieveBoardHashtagPort { List getAllIncludingDeletedByBoardId(Long boardId); - List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable); + List getBoardIdsByHashTagId(List hashtagIds); } diff --git a/src/main/java/page/clab/api/domain/community/board/application/service/BoardsByHashtagRetrievalService.java b/src/main/java/page/clab/api/domain/community/board/application/service/BoardsByHashtagRetrievalService.java index 2053635c5..052e0b793 100644 --- a/src/main/java/page/clab/api/domain/community/board/application/service/BoardsByHashtagRetrievalService.java +++ b/src/main/java/page/clab/api/domain/community/board/application/service/BoardsByHashtagRetrievalService.java @@ -39,7 +39,7 @@ public PagedResponseDto retrieveBoardsByHashtag(List boardIds = externalRetrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds, pageable); + List boardIds = externalRetrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds); List boards = boardIds.stream() .map(externalRetrieveBoardUseCase::getById) diff --git a/src/main/java/page/clab/api/external/community/board/application/port/ExternalRetrieveBoardHashtagUseCase.java b/src/main/java/page/clab/api/external/community/board/application/port/ExternalRetrieveBoardHashtagUseCase.java index 3fbe05d3c..1764ada44 100644 --- a/src/main/java/page/clab/api/external/community/board/application/port/ExternalRetrieveBoardHashtagUseCase.java +++ b/src/main/java/page/clab/api/external/community/board/application/port/ExternalRetrieveBoardHashtagUseCase.java @@ -15,5 +15,5 @@ public interface ExternalRetrieveBoardHashtagUseCase { List getAllIncludingDeletedByBoardId(Long boardId); - List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable); + List getBoardIdsByHashTagId(List hashtagIds); } diff --git a/src/main/java/page/clab/api/external/community/board/application/service/ExternalBoardHashtagRetrieveService.java b/src/main/java/page/clab/api/external/community/board/application/service/ExternalBoardHashtagRetrieveService.java index e5346fb84..805c53580 100644 --- a/src/main/java/page/clab/api/external/community/board/application/service/ExternalBoardHashtagRetrieveService.java +++ b/src/main/java/page/clab/api/external/community/board/application/service/ExternalBoardHashtagRetrieveService.java @@ -49,7 +49,7 @@ public List getAllIncludingDeletedByBoardId(Long boardId) { } @Override - public List getBoardIdsByHashTagId(List hashtagIds, Pageable pageable) { - return retrieveBoardHashtagPort.getBoardIdsByHashTagId(hashtagIds, pageable); + public List getBoardIdsByHashTagId(List hashtagIds) { + return retrieveBoardHashtagPort.getBoardIdsByHashTagId(hashtagIds); } }