Skip to content

Commit e1014bd

Browse files
authored
refactor: 다이어리 아이디 기준 내림차순 정렬 및 테스트 로그인 임시 주석 처리
# 변경점 👍 close: #29 다이어리 아이디 기준 내림차순 정렬 및 테스트 로그인 임시 주석 처리를 진행했습니다. 추가로 정렬이 잘되는지 확인하기 위해 테스트를 보완했습니다. # 비고 ✏ 정렬 기준을 추가하려니 JPA 네이밍 메서드를 사용하면 메서드명이 너무 길어져서 JPQL을 사용했습니다!
1 parent 2033937 commit e1014bd

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/main/java/apptive/team5/diary/repository/DiaryRepository.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
import java.util.Set;
1515

1616
public interface DiaryRepository extends JpaRepository<DiaryEntity, Long> {
17+
18+
@Query("select d from DiaryEntity d where d.user = :user order by d.id desc")
1719
Page<DiaryEntity> findByUser(UserEntity user, Pageable pageable);
1820

1921
List<DiaryEntity> findByUserId(Long userId);
2022

23+
@Query("select d from DiaryEntity d where d.user.id = :userId and d.scope in :scopes order by d.id desc")
2124
Page<DiaryEntity> findByUserIdAndScopeIn(Long userId, List<DiaryScope> scopes, Pageable pageable);
2225

26+
@Query("select d from DiaryEntity d where d.user.id = :userId and d.createDateTime between :start and :end order by d.id desc")
2327
List<DiaryEntity> findByUserIdAndCreateDateTimeBetween(Long userId, LocalDateTime start, LocalDateTime end);
2428

2529
@Query("select count(d) from DiaryEntity d where d.user.id = :userId")
@@ -29,9 +33,6 @@ public interface DiaryRepository extends JpaRepository<DiaryEntity, Long> {
2933
@Modifying(clearAutomatically = true)
3034
void deleteByUserId(Long userId);
3135

32-
@Query("select d from DiaryEntity d where d.user.id in :userIds")
33-
Page<DiaryEntity> findByUserIdsPage(Set<Long> userIds, Pageable pageable);
34-
35-
@Query("select d from DiaryEntity d join fetch d.user where d.user.id in :userIds and d.scope in :scopes")
36+
@Query("select d from DiaryEntity d join fetch d.user where d.user.id in :userIds and d.scope in :scopes order by d.id desc")
3637
Page<DiaryEntity> findByUserIdsAndScopseWithUserPage(Set<Long> userIds, List<DiaryScope> scopes, Pageable pageable);
3738
}

src/main/java/apptive/team5/diary/service/DiaryLowService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ public void deleteByUserId(Long userId) {
7070
diaryRepository.deleteByUserId(userId);
7171
}
7272

73-
public Page<DiaryEntity> findByUserIds(Set<Long> userIds, Pageable pageable) {
74-
return diaryRepository.findByUserIdsPage(userIds, pageable);
75-
}
7673

7774
public Page<DiaryEntity> findByUserIdsAndScopseWithUserPage(Set<Long> userIds, List<DiaryScope> scopes, Pageable pageable) {
7875
return diaryRepository.findByUserIdsAndScopseWithUserPage(userIds, scopes, pageable);

src/main/java/apptive/team5/oauth2/controller/OAuth2Controller.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public ResponseEntity<TokenResponse> googleLogin(@RequestBody GoogleLoginRequest
3535
return ResponseEntity.ok(tokenResponse);
3636
}
3737

38-
@GetMapping("/test")
39-
public ResponseEntity<TokenResponse> testLogin() {
40-
41-
TokenResponse tokenResponse = testLoginService.testLogin();
42-
43-
return ResponseEntity.ok(tokenResponse);
44-
}
38+
// @GetMapping("/test")
39+
// public ResponseEntity<TokenResponse> testLogin() {
40+
//
41+
// TokenResponse tokenResponse = testLoginService.testLogin();
42+
//
43+
// return ResponseEntity.ok(tokenResponse);
44+
// }
4545
}

src/test/java/apptive/team5/diary/controller/DiaryControllerTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void setUp() {
8181
@DisplayName("내 다이어리 목록 조회")
8282
void getMyMusicDiary() throws Exception {
8383
// given
84-
DiaryEntity diary = diaryRepository.save(TestUtil.makeDiaryEntity(testUser));
84+
DiaryEntity firstDiary = diaryRepository.save(TestUtil.makeDiaryEntity(testUser));
85+
DiaryEntity secondDiary = diaryRepository.save(TestUtil.makeDiaryEntity(testUser));
8586

8687
TestSecurityContextHolderInjection.inject(testUser.getId(), testUser.getRoleType());
8788

@@ -106,13 +107,15 @@ void getMyMusicDiary() throws Exception {
106107
MyDiaryResponseDto diaryResponse = content.getFirst();
107108

108109
assertSoftly(softly-> {
109-
softly.assertThat(content).hasSize(1);
110-
softly.assertThat(diaryResponse.musicTitle()).isEqualTo(diary.getMusicTitle());
111-
softly.assertThat(diaryResponse.artist()).isEqualTo(diary.getArtist());
112-
softly.assertThat(diaryResponse.duration()).isEqualTo(diary.getDuration());
113-
softly.assertThat(diaryResponse.totalDuration()).isEqualTo(diary.getTotalDuration());
114-
softly.assertThat(diaryResponse.start()).isEqualTo(diary.getStart());
115-
softly.assertThat(diaryResponse.end()).isEqualTo(diary.getEnd());
110+
softly.assertThat(content).hasSize(2);
111+
softly.assertThat(diaryResponse.diaryId()).isEqualTo(secondDiary.getId());
112+
softly.assertThat(diaryResponse.musicTitle()).isEqualTo(secondDiary.getMusicTitle());
113+
softly.assertThat(diaryResponse.artist()).isEqualTo(secondDiary.getArtist());
114+
softly.assertThat(diaryResponse.duration()).isEqualTo(secondDiary.getDuration());
115+
softly.assertThat(diaryResponse.totalDuration()).isEqualTo(secondDiary.getTotalDuration());
116+
softly.assertThat(diaryResponse.start()).isEqualTo(secondDiary.getStart());
117+
softly.assertThat(diaryResponse.end()).isEqualTo(secondDiary.getEnd());
118+
softly.assertThat(content.getFirst().diaryId() > content.getLast().diaryId()).isTrue();
116119
});
117120
}
118121

@@ -151,6 +154,7 @@ void getUserDiariesByViewer() throws Exception {
151154
assertSoftly(softly -> {
152155
softly.assertThat(content).hasSize(2);
153156
softly.assertThat(responseMap.containsKey(privateDiary.getId())).isFalse();
157+
softly.assertThat(content.getFirst().diaryId() > content.getLast().diaryId()).isTrue();
154158

155159
// PUBLIC
156160
UserDiaryResponseDto publicResponse = responseMap.get(publicDiary.getId());
@@ -195,6 +199,7 @@ void getMyDiariesByPeriod() throws Exception {
195199
List<MyDiaryResponseDto> content = objectMapper.readValue(response, new TypeReference<>() {});
196200

197201
assertSoftly(softly -> {
202+
softly.assertThat(content.getFirst().diaryId() > content.getLast().diaryId()).isTrue();
198203
softly.assertThat(content).hasSize(2);
199204
});
200205
}
@@ -209,9 +214,11 @@ void getMyDiariesFeeds() throws Exception {
209214
Subscribe subscribe = new Subscribe(testUser, subscribedToUser);
210215
subscribeRepository.save(subscribe);
211216

217+
DiaryEntity otherFeedDiary = diaryRepository.save(TestUtil.makeDiaryEntity(subscribedToUser));
218+
// 좋아요 누를 다이어를 두 번째로 저장
219+
DiaryEntity likedFeedDiary = diaryRepository.save(TestUtil.makeDiaryEntity(subscribedToUser));
212220
// 좋아요 누르기
213-
DiaryEntity feedDiary = diaryRepository.save(TestUtil.makeDiaryEntity(subscribedToUser));
214-
DiaryLikeEntity diaryLikeEntity = diaryLikeLowService.saveDiaryLike(new DiaryLikeEntity(testUser, feedDiary));
221+
DiaryLikeEntity diaryLikeEntity = diaryLikeLowService.saveDiaryLike(new DiaryLikeEntity(testUser, likedFeedDiary));
215222

216223
// 구독하지 않은 회원
217224
UserEntity otherUser = userRepository.save(TestUtil.makeDifferentUserEntity(subscribedToUser));
@@ -237,11 +244,12 @@ void getMyDiariesFeeds() throws Exception {
237244
FeedDiaryResponseDto feedDiaryResponseDto = content.getFirst();
238245

239246
assertSoftly(softly -> {
240-
softly.assertThat(content).hasSize(1);
241-
softly.assertThat(feedDiaryResponseDto.diaryId()).isEqualTo(feedDiary.getId());
247+
softly.assertThat(content).hasSize(2);
248+
softly.assertThat(feedDiaryResponseDto.diaryId()).isEqualTo(likedFeedDiary.getId());
242249
softly.assertThat(feedDiaryResponseDto.isLiked()).isTrue();
243250
softly.assertThat(feedDiaryResponseDto.likeCount()).isEqualTo(1L);
244251
softly.assertThat(feedDiaryResponseDto.userId()).isEqualTo(subscribedToUser.getId());
252+
softly.assertThat(content.getFirst().diaryId() > content.getLast().diaryId()).isTrue();
245253
});
246254
}
247255

0 commit comments

Comments
 (0)