2222public class EmotionRecordRepositoryImpl implements EmotionRecordRepositoryCustom {
2323
2424 private final JPAQueryFactory jpaQueryFactory ;
25- private final QEmotionRecord emotionRecord = QEmotionRecord .emotionRecord ;
26- private final QUser user = QUser .user ;
27- private final QSpotifyMusic spotifyMusic = QSpotifyMusic .spotifyMusic ;
28-
2925
3026 @ Override
3127 public List <EmotionRecordDto > findByUser (User user ) {
@@ -49,11 +45,11 @@ public List<EmotionRecordDto> findByUser(User user) {
4945 // loginId를 기준으로 JOIN FETCH (user, spotifyMusic) 후 페이징 처리
5046 @ Override
5147 public Page <EmotionRecord > findByLoginId (String loginId , Pageable pageable ) {
52- List <EmotionRecord > content = jpaQueryFactory
53- .selectFrom (emotionRecord )
54- .join (emotionRecord .user , user ).fetchJoin ()
55- .join (emotionRecord .spotifyMusic , spotifyMusic ).fetchJoin ()
56- .where (user .loginId .eq (loginId ))
48+ List <EmotionRecord > emotionRecords = jpaQueryFactory
49+ .selectFrom (QEmotionRecord . emotionRecord )
50+ .join (QEmotionRecord . emotionRecord .user , QUser . user ).fetchJoin ()
51+ .join (QEmotionRecord . emotionRecord .spotifyMusic , QSpotifyMusic . spotifyMusic ).fetchJoin ()
52+ .where (QUser . user .loginId .eq (loginId ))
5753 .offset (pageable .getOffset ())
5854 .limit (pageable .getPageSize ())
5955 .fetch ();
@@ -63,57 +59,57 @@ public Page<EmotionRecord> findByLoginId(String loginId, Pageable pageable) {
6359 // QueryDSL을 사용할 경우에 위와 달리 데이터 수 계산 쿼리를 별도로 실행해 줘야함 (Querydsl 5 이상 권장 방식)
6460 long total = Optional .ofNullable (
6561 jpaQueryFactory
66- .select (emotionRecord .count ())
67- .from (emotionRecord )
68- .join (emotionRecord .user , user )
69- .where (user .loginId .eq (loginId ))
62+ .select (QEmotionRecord . emotionRecord .count ())
63+ .from (QEmotionRecord . emotionRecord )
64+ .join (QEmotionRecord . emotionRecord .user , QUser . user )
65+ .where (QUser . user .loginId .eq (loginId ))
7066 .fetchOne ()
7167 ).orElse (0L );
7268
73- return new PageImpl <>(content , pageable , total );
69+ return new PageImpl <>(emotionRecords , pageable , total );
7470 }
7571
7672 // 로그인 된 userId를 제외한 EmotionRecord 조회 (LEFT JOIN으로 spotifyMusic 포함) 후 페이징처리
7773 @ Override
7874 public Page <EmotionRecord > findByWithoutUserId (Long userId , Pageable pageable ) {
79- List <EmotionRecord > content = jpaQueryFactory
80- .selectFrom (emotionRecord )
81- .join (emotionRecord .user , user ).fetchJoin ()
82- .leftJoin (emotionRecord .spotifyMusic , spotifyMusic ).fetchJoin ()
83- .where (user .userId .ne (userId ))
75+ List <EmotionRecord > emotionRecords = jpaQueryFactory
76+ .selectFrom (QEmotionRecord . emotionRecord )
77+ .join (QEmotionRecord . emotionRecord .user , QUser . user ).fetchJoin ()
78+ .leftJoin (QEmotionRecord . emotionRecord .spotifyMusic , QSpotifyMusic . spotifyMusic ).fetchJoin ()
79+ .where (QUser . user .userId .ne (userId ))
8480 .offset (pageable .getOffset ())
8581 .limit (pageable .getPageSize ())
8682 .fetch ();
8783
8884 // 위의 findByLoginId 메서드 설명 참고
8985 long total = Optional .ofNullable (
9086 jpaQueryFactory
91- .select (emotionRecord .count ())
92- .from (emotionRecord )
93- .join (emotionRecord .user , user )
94- .where (user .userId .ne (userId ))
87+ .select (QEmotionRecord . emotionRecord .count ())
88+ .from (QEmotionRecord . emotionRecord )
89+ .join (QEmotionRecord . emotionRecord .user , QUser . user )
90+ .where (QUser . user .userId .ne (userId ))
9591 .fetchOne ()
9692 ).orElse (0L );
9793
98- return new PageImpl <>(content , pageable , total );
94+ return new PageImpl <>(emotionRecords , pageable , total );
9995 }
10096
10197 // recordId에 해당하는 EmotionRecord 조회
10298 @ Override
10399 public Optional <EmotionRecord > findByRecordId (Long recordId ) {
104- EmotionRecord record = jpaQueryFactory
105- .selectFrom (emotionRecord )
106- .where (emotionRecord .recordId .eq (recordId ))
100+ EmotionRecord emotionRecord = jpaQueryFactory
101+ .selectFrom (QEmotionRecord . emotionRecord )
102+ .where (QEmotionRecord . emotionRecord .recordId .eq (recordId ))
107103 .fetchOne ();
108- return Optional .ofNullable (record );
104+ return Optional .ofNullable (emotionRecord );
109105 }
110106
111107 // recordId에 해당하는 EmotionRecord 삭제
112108 @ Override
113109 public int deleteByRecordId (Long recordId ) {
114110 return (int )jpaQueryFactory
115- .delete (emotionRecord )
116- .where (emotionRecord .recordId .eq (recordId ))
111+ .delete (QEmotionRecord . emotionRecord )
112+ .where (QEmotionRecord . emotionRecord .recordId .eq (recordId ))
117113 .execute ();
118114 }
119115}
0 commit comments