Skip to content

Commit

Permalink
[BUG] 좋아요 목록 조회 시 발생하는 버그 수정 (#169)
Browse files Browse the repository at this point in the history
* bug: 좋아요 목록 조회 오류 해결

* bug: 좋아요 목록 조회 오류 테스트 완료

* bug : 좋아요 목록 조회 버그 수정

* chore: 불필요한 h2 주석처리

* bug: 버그해결
  • Loading branch information
kimdozzi authored Apr 22, 2024
1 parent 51ebf78 commit 31863e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ dependencies {
// testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'

// H2
implementation 'com.h2database:h2'
runtimeOnly 'com.h2database:h2:2.2.222'
testRuntimeOnly 'com.h2database:h2'
//implementation 'com.h2database:h2'
//runtimeOnly 'com.h2database:h2:2.2.222'
testRuntimeOnly 'com.h2database:h2:2.2.222'

// Github API for Java
implementation 'org.kohsuke:github-api:1.318'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.genius.gitget.global.file.service.FilesService;
import com.genius.gitget.global.util.exception.BusinessException;
import com.genius.gitget.global.util.exception.ErrorCode;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -41,8 +43,8 @@ public Page<UserLikesResponse> getLikesList(User user, Pageable pageable) {
likes = userObject.getLikesList();
}
}
List<UserLikesResponse> userLikesResponses = new ArrayList<>();

Deque<UserLikesResponse> userLikesResponses = new ArrayDeque<>();
for (Likes like : likes) {
Instance instance = like.getInstance();
FileResponse fileResponse = filesService.convertToFileResponse(instance.getFiles());
Expand All @@ -55,10 +57,13 @@ public Page<UserLikesResponse> getLikesList(User user, Pageable pageable) {
.fileResponse(fileResponse)
.build();

userLikesResponses.add(userLikesResponse);
userLikesResponses.addFirst(userLikesResponse);
}

return new PageImpl<>(userLikesResponses, pageable, userLikesResponses.size());
int start = (int) pageable.getOffset();
int end = Math.min((start + pageable.getPageSize()), userLikesResponses.size());
return new PageImpl<>(userLikesResponses.stream().toList().subList(start, end), pageable,
userLikesResponses.size());
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ void setup() {
+ likesResponse.getPointPerPerson());
}
assertThat(likesResponses.getContent().size()).isEqualTo(3);
assertThat(likesResponses.getContent().get(0).getTitle()).isEqualTo("1일 1커밋");
assertThat(likesResponses.getContent().get(0).getPointPerPerson()).isEqualTo(100);
assertThat(likesResponses.getContent().get(2).getTitle()).isEqualTo("1일 1커밋");
assertThat(likesResponses.getContent().get(2).getPointPerPerson()).isEqualTo(100);

assertThat(likesResponses.getContent().get(1).getTitle()).isEqualTo("1일 1커밋");
assertThat(likesResponses.getContent().get(1).getPointPerPerson()).isEqualTo(150);

assertThat(likesResponses.getContent().get(2).getTitle()).isEqualTo("1일 1알고리즘");
assertThat(likesResponses.getContent().get(2).getPointPerPerson()).isEqualTo(200);
assertThat(likesResponses.getContent().get(0).getTitle()).isEqualTo("1일 1알고리즘");
assertThat(likesResponses.getContent().get(0).getPointPerPerson()).isEqualTo(200);
}


Expand Down

0 comments on commit 31863e2

Please sign in to comment.