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

#344 [fix] 규칙 메인 조회에서 대표 규칙 여부 함께 전달하도록 수정 #346

Merged
merged 3 commits into from
Aug 2, 2023

Conversation

hyejungg
Copy link
Member

@hyejungg hyejungg commented Jul 31, 2023

✒️ 관련 이슈번호

🔑 Key Changes

  1. 규칙 메인 조회에서 대표 규칙 여부 함께 전달하도록 수정했습니다.

📢 To Reviewers

  • 정렬은 수정할 사항이 없고, 대표 규칙 여부만 전달이 빠져있어서 추가했습니다~

@hyejungg hyejungg added 🐣 혜정 🐣 혜정이가 했다아~ 🔧 Fix 간단한 수정 labels Jul 31, 2023
@hyejungg hyejungg requested a review from orijoon98 July 31, 2023 13:57
@hyejungg hyejungg self-assigned this Jul 31, 2023
Copy link
Member

@orijoon98 orijoon98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사함니다!!

@hyejungg hyejungg requested a review from orijoon98 July 31, 2023 14:20
Comment on lines 27 to 42
public static RulesResponse of(List<Rule> rules, LocalDateTime now) {
List<RuleInfo> sortedRuleInfo = rules.stream()
.sorted(Rule::compareTo)
.map(rule -> RuleInfo.of(rule, now)).collect(Collectors.toList());

Map<Boolean, List<RuleInfo>> ruleInfoMap = sortedRuleInfo.stream()
.collect(Collectors.partitioningBy(RuleInfo::isRepresent));

List<RuleInfo> representRuleInfo = ruleInfoMap.get(true);
List<RuleInfo> nonRepresentRuleInfo = ruleInfoMap.get(false);

return RulesResponse.builder()
.rules(rules.stream()
.sorted(Rule::compareTo)
.map(rule -> RuleInfo.of(rule, now)).collect(Collectors.toList()))
.rules(Stream.concat(representRuleInfo.stream(), nonRepresentRuleInfo.stream())
.collect(Collectors.toList()))
.build();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오홍.. 처음보는 메서드들이 많네요! 신기합니당..
이 방식도 좋은데 아래와 같이 하면 코드 라인수를 좀 줄일 수 있을 것 같아서 의견 내봅니당!!

public static RulesResponse of(List<Rule> rules, LocalDateTime now) {
	return RulesResponse.builder()
		.rules(rules.stream()
			.sorted(Rule::compareTo)
			.map(rule -> RuleInfo.of(rule, now))
			.collect(Collectors.toList())
			.stream()
			.sorted(Comparator.comparing(RuleInfo::isRepresent).reversed())
			.collect(Collectors.toList()))
		.build();
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 stream 을 이을 생각은 못했네요.. 좋습니당

@hyejungg hyejungg merged commit 9be2ffe into develop Aug 2, 2023
1 check passed
@hyejungg hyejungg deleted the fix/#344 branch August 2, 2023 11:39
hyejungg added a commit that referenced this pull request Aug 2, 2023
hyejungg added a commit that referenced this pull request Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐣 혜정 🐣 혜정이가 했다아~ 🔧 Fix 간단한 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rules 조회 API 수정
2 participants