-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
342 additions
and
59 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
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
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
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
7 changes: 5 additions & 2 deletions
7
...ain/java/com/example/dreamvalutbackend/domain/playlist/repository/PlaylistRepository.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,18 +1,21 @@ | ||
package com.example.dreamvalutbackend.domain.playlist.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.example.dreamvalutbackend.domain.playlist.domain.Playlist; | ||
|
||
public interface PlaylistRepository extends JpaRepository<Playlist, Long> { | ||
public interface PlaylistRepository extends JpaRepository<Playlist, Long>, PlaylistRepositoryCustom { | ||
|
||
Page<Playlist> findByIsCuratedTrue(Pageable pageable); | ||
|
||
Page<Playlist> findByIsCuratedFalseAndIsPublicTrue(Pageable pageable); | ||
|
||
Page<Playlist> findAllByUser_UserId(Long userId, Pageable pageable); | ||
|
||
|
||
Page<Playlist> findAllByIdInAndIsCurated(List<Long> ids, Boolean isCurated, Pageable pageable); | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
...va/com/example/dreamvalutbackend/domain/playlist/repository/PlaylistRepositoryCustom.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,11 @@ | ||
package com.example.dreamvalutbackend.domain.playlist.repository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import com.example.dreamvalutbackend.domain.playlist.domain.Playlist; | ||
|
||
|
||
public interface PlaylistRepositoryCustom { | ||
Page<Playlist> findUnionOfCreatedAndFollowedPlaylists(Long userId, Pageable pageable); | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...java/com/example/dreamvalutbackend/domain/playlist/repository/PlaylistRepositoryImpl.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,66 @@ | ||
package com.example.dreamvalutbackend.domain.playlist.repository; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import com.example.dreamvalutbackend.domain.playlist.domain.Playlist; | ||
import com.example.dreamvalutbackend.domain.playlist.domain.QMyPlaylist; | ||
import com.example.dreamvalutbackend.domain.playlist.domain.QPlaylist; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
public class PlaylistRepositoryImpl implements PlaylistRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Autowired | ||
public PlaylistRepositoryImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
@Override | ||
public Page<Playlist> findUnionOfCreatedAndFollowedPlaylists(Long userId, Pageable pageable) { | ||
QPlaylist playlist = QPlaylist.playlist; | ||
QMyPlaylist myPlaylist = QMyPlaylist.myPlaylist; | ||
|
||
List<Long> createdPlaylistIds = queryFactory | ||
.select(playlist.id) | ||
.from(playlist) | ||
.where(playlist.user.userId.eq(userId)) | ||
.fetch(); | ||
|
||
List<Long> followedPlaylistIds = queryFactory | ||
.select(myPlaylist.playlist.id) | ||
.from(myPlaylist) | ||
.where(myPlaylist.user.userId.eq(userId)) | ||
.fetch(); | ||
|
||
Set<Long> unionIds = new HashSet<>(createdPlaylistIds); | ||
unionIds.addAll(followedPlaylistIds); | ||
|
||
List<Playlist> result = queryFactory | ||
.selectFrom(playlist) | ||
.where(playlist.id.in(unionIds)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
long total = queryFactory | ||
.selectFrom(playlist) | ||
.where(playlist.id.in(unionIds)) | ||
.fetchCount(); | ||
|
||
return new PageImpl<>(result, pageable, total); | ||
|
||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.