Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] #261 - O-KR 히스토리 조회 API 변경사항 반영 #262

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading