Skip to content

Commit

Permalink
refactor(BoardHashtagRepository): SQL문에 개행추가, customRepository에서 JPQL…
Browse files Browse the repository at this point in the history
…로 작성한 내용을 어노테이션으로 수정
  • Loading branch information
mingmingmon committed Dec 22, 2024
1 parent 1527242 commit 0a53dd5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<BoardHashtag> getAllIncludingDeletedByBoardId(Long boardId) {
.collect(Collectors.toList());
}

public List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds, Pageable pageable) {
return repository.getBoardIdsByHashTagId(hashtagIds, pageable);
public List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds) {
return repository.getBoardIdsByHashTagId(hashtagIds, (long)hashtagIds.size());
}
}
Original file line number Diff line number Diff line change
@@ -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<BoardHashtagJpaEntity, Long>, BoardHashtagRepositoryCustom, QuerydslPredicateExecutor<BoardHashtagJpaEntity> {
public interface BoardHashtagRepository extends JpaRepository<BoardHashtagJpaEntity, Long>{

List<BoardHashtagJpaEntity> 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<BoardHashtagJpaEntity> 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<Long> getBoardIdsByHashTagId(@Param("hashtagIds") List<Long> hashtagIds, @Param("size") Long size);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface RetrieveBoardHashtagPort {

List<BoardHashtag> getAllIncludingDeletedByBoardId(Long boardId);

List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds, Pageable pageable);
List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PagedResponseDto<BoardOverviewResponseDto> retrieveBoardsByHashtag(List<S
hashtagIds.add(externalRetrieveHashtagUseCase.getByName(hashtag).getId());
}

List<Long> boardIds = externalRetrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds, pageable);
List<Long> boardIds = externalRetrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds);

List<Board> boards = boardIds.stream()
.map(externalRetrieveBoardUseCase::getById)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface ExternalRetrieveBoardHashtagUseCase {

List<BoardHashtag> getAllIncludingDeletedByBoardId(Long boardId);

List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds, Pageable pageable);
List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<BoardHashtag> getAllIncludingDeletedByBoardId(Long boardId) {
}

@Override
public List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds, Pageable pageable) {
return retrieveBoardHashtagPort.getBoardIdsByHashTagId(hashtagIds, pageable);
public List<Long> getBoardIdsByHashTagId(List<Long> hashtagIds) {
return retrieveBoardHashtagPort.getBoardIdsByHashTagId(hashtagIds);
}
}

0 comments on commit 0a53dd5

Please sign in to comment.