-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from delicious-algorithme/feature/63-bookmark-…
…all-n+1-solve feature: 북마크, 가게 아이디 조회 API 구현 & N+1 문제 해결
- Loading branch information
Showing
8 changed files
with
167 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
src/main/java/matal/bookmark/domain/repository/BookmarkRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package matal.bookmark.domain.repository; | ||
|
||
import java.util.List; | ||
import matal.bookmark.domain.Bookmark; | ||
import matal.bookmark.dto.response.BookmarkStoreIdsResponseDto; | ||
import matal.member.domain.Member; | ||
import matal.store.domain.Store; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> { | ||
|
||
Page<Bookmark> findBookmarksByMemberId(Long id, Pageable pageable); | ||
@EntityGraph(attributePaths = {"store"}, type = EntityGraphType.FETCH) | ||
@Query("SELECT DISTINCT b FROM Bookmark b LEFT JOIN b.store WHERE b.member.id = :memberId") | ||
Page<Bookmark> findBookmarksByMemberId(@Param("memberId") Long id, Pageable pageable); | ||
|
||
@Query("SELECT new matal.bookmark.dto.response.BookmarkStoreIdsResponseDto(b.bookmarkId, b.store.storeId) " + | ||
"FROM Bookmark b WHERE b.member.id = :memberId") | ||
List<BookmarkStoreIdsResponseDto> findBookmarkStoreIdsByMemberId(@Param("memberId") Long memberId); | ||
|
||
|
||
Boolean existsBookmarkByStoreAndMember(Store store, Member member); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/matal/bookmark/dto/response/BookmarkStoreIdsResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package matal.bookmark.dto.response; | ||
|
||
public record BookmarkStoreIdsResponseDto(Long bookmarkId, | ||
Long storeId) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters