Skip to content

Commit

Permalink
Merge pull request #262 from MOONSHOT-Team/feature/#261
Browse files Browse the repository at this point in the history
[Fix] #261 - O-KR 히스토리 조회 API 변경사항 반영
  • Loading branch information
its-sky authored Apr 8, 2024
2 parents 5003db9 + 469a969 commit 044f341
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package org.moonshot.objective.dto.response;

import java.util.List;
import java.util.Map;
import org.moonshot.objective.model.Criteria;

public record HistoryResponseDto(
List<ObjectiveGroupByYearDto> groups,
List<YearDto> years,
List<String> categories
) {
public static HistoryResponseDto of(List<ObjectiveGroupByYearDto> groups, Map<Integer, Integer> years,
List<String> categories, Criteria criteria) {
return new HistoryResponseDto(
groups,
YearDto.of(years),
categories.stream().distinct().toList()
);
public static HistoryResponseDto of(List<ObjectiveGroupByYearDto> groups, List<String> categories) {
return new HistoryResponseDto(groups, categories.stream().distinct().toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.moonshot.common.model.Period;
Expand Down Expand Up @@ -120,11 +119,6 @@ public HistoryResponseDto getObjectiveHistory(final Long userId, final Integer y
List<Objective> objectives = objectiveRepository.findObjectives(userId, year, category, criteria);
Map<Integer, List<Objective>> groups = objectives.stream()
.collect(Collectors.groupingBy(objective -> objective.getPeriod().getStartAt().getYear()));
Map<Integer, Integer> years = groups.entrySet().stream()
.collect(Collectors.toMap(
Entry::getKey,
entry -> entry.getValue().size()
));
List<String> categories = objectives.stream().map(objective -> objective.getCategory().getValue()).toList();

List<ObjectiveGroupByYearDto> groupList = groups.entrySet().stream()
Expand All @@ -142,7 +136,7 @@ public HistoryResponseDto getObjectiveHistory(final Long userId, final Integer y
.sorted(Comparator.comparingInt(ObjectiveGroupByYearDto::year).reversed()).toList();
}

return HistoryResponseDto.of(groupsSortedByCriteria, years, categories, criteria);
return HistoryResponseDto.of(groupsSortedByCriteria, categories);
}

@Override
Expand Down

0 comments on commit 044f341

Please sign in to comment.