Skip to content

Commit

Permalink
✨ [Feature] Agenda 조회 전체 정렬 기준 수정 #998 (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Sep 3, 2024
1 parent 0d56342 commit c82ebca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ResponseEntity<PageResponseDto<AgendaSimpleResDto>> agendaListHistory(
@ModelAttribute @Valid PageRequestDto pageRequest) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("startTime").descending());
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("startTime").ascending());

Page<Agenda> agendas = agendaService.findHistoryAgendaList(pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public Agenda findAgendaByAgendaKey(UUID agendaKey) {
public List<Agenda> findOpenAgendaList() {
return agendaRepository.findAllByStatusIs(AgendaStatus.OPEN).stream()
.filter(agenda -> agenda.getDeadline().isAfter(LocalDateTime.now()))
.sorted(agendaComparatorWithIsOfficialThenDeadline())
.sorted(agendaComparatorWithDeadlineThenIsOfficial())
.collect(Collectors.toList());
}

private Comparator<Agenda> agendaComparatorWithIsOfficialThenDeadline() {
return Comparator.comparing(Agenda::getIsOfficial, Comparator.reverseOrder())
.thenComparing(Agenda::getDeadline, Comparator.reverseOrder());
private Comparator<Agenda> agendaComparatorWithDeadlineThenIsOfficial() {
return Comparator.comparing(Agenda::getDeadline)
.thenComparing(Agenda::getIsOfficial);
}

/**
Expand All @@ -87,13 +87,13 @@ public List<Agenda> findConfirmAgendaList() {
return agendaRepository.findAllByStatusIs(AgendaStatus.OPEN, AgendaStatus.CONFIRM).stream()
.filter(agenda -> agenda.getDeadline().isBefore(LocalDateTime.now())
|| agenda.getStatus() == AgendaStatus.CONFIRM)
.sorted(agendaComparatorWithIsOfficialThenStartTime())
.sorted(agendaComparatorWithStartTimeThenIsOfficial())
.collect(Collectors.toList());
}

private Comparator<Agenda> agendaComparatorWithIsOfficialThenStartTime() {
return Comparator.comparing(Agenda::getIsOfficial, Comparator.reverseOrder())
.thenComparing(Agenda::getStartTime, Comparator.reverseOrder());
private Comparator<Agenda> agendaComparatorWithStartTimeThenIsOfficial() {
return Comparator.comparing(Agenda::getDeadline)
.thenComparing(Agenda::getIsOfficial);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,10 @@ void getAgendaListOpenSuccess() throws Exception {
// then
assertThat(result.length).isEqualTo(officialAgendaList.size() + nonOfficialAgendaList.size());
for (int i = 0; i < result.length; i++) {
assertThat(result[i].getIsOfficial()).isEqualTo(i < officialAgendaList.size());
if (i == 0 || i == officialAgendaList.size()) {
continue;
}
assertThat(result[i].getAgendaDeadLine()).isBefore(result[i - 1].getAgendaDeadLine());
assertThat(result[i].getAgendaDeadLine()).isAfter(result[i - 1].getAgendaDeadLine());
}
}

Expand Down Expand Up @@ -300,11 +299,10 @@ void getAgendaListConfirmSuccess() throws Exception {
// then
assertThat(result.length).isEqualTo(totalSize);
for (int i = 0; i < result.length; i++) {
assertThat(result[i].getIsOfficial()).isEqualTo(i < officialAgendaList.size());
if (i == 0 || i == officialAgendaList.size()) {
continue;
}
assertThat(result[i].getAgendaStartTime()).isBefore(result[i - 1].getAgendaStartTime());
assertThat(result[i].getAgendaStartTime()).isAfter(result[i - 1].getAgendaDeadLine());
}
}

Expand Down Expand Up @@ -587,12 +585,10 @@ void getAgendaListHistorySuccess(int page) throws Exception {
// then
assertThat(result.size()).isEqualTo(size * page < totalCount ? size : totalCount % size);
for (int i = 0; i < result.size(); i++) {
assertThat(result.get(i).getAgendaTitle())
.isEqualTo(agendaHistory.get(size * (page - 1) + i).getTitle());
if (i == 0) {
continue;
}
assertThat(result.get(i).getAgendaStartTime()).isBefore(result.get(i - 1).getAgendaStartTime());
assertThat(result.get(i).getAgendaStartTime()).isAfter(result.get(i - 1).getAgendaStartTime());
}
}

Expand Down Expand Up @@ -711,11 +707,10 @@ void getAgendaListHistoryWithoutSize() throws Exception {
// then
assertThat(result.size()).isEqualTo(20);
for (int i = 0; i < result.size(); i++) {
assertThat(result.get(i).getAgendaTitle()).isEqualTo(agendaHistory.get(i).getTitle());
if (i == 0) {
continue;
}
assertThat(result.get(i).getAgendaStartTime()).isBefore(result.get(i - 1).getAgendaStartTime());
assertThat(result.get(i).getAgendaStartTime()).isAfter(result.get(i - 1).getAgendaStartTime());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ void getAgendaListSuccess() {
// then
verify(agendaRepository, times(1)).findAllByStatusIs(any());
for (int i = 0; i < result.size(); i++) {
assertThat(result.get(i).getIsOfficial()).isEqualTo(i < officialSize);
if (i == 0 || i == officialSize) {
continue;
}
assertThat(result.get(i).getDeadline()).isBefore(result.get(i - 1).getDeadline());
assertThat(result.get(i).getDeadline()).isAfter(result.get(i - 1).getDeadline());
}
}

Expand Down

0 comments on commit c82ebca

Please sign in to comment.