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
Merged
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,6 +1,7 @@
package hous.api.service.rule.dto.response;

import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -26,7 +27,11 @@ 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()))
.map(rule -> RuleInfo.of(rule, now))
.collect(Collectors.toList())
.stream()
.sorted(Comparator.comparing(RuleInfo::isRepresent).reversed())
.collect(Collectors.toList()))
.build();
}

Expand All @@ -36,23 +41,27 @@ public static RulesResponse of(List<Rule> rules, LocalDateTime now) {
private static class RuleInfo {

private Long id;

private String name;

private boolean isNew;

private boolean isRepresent;
private String createdAt;

@JsonProperty("isNew")
public boolean isNew() {
return isNew;
}

@JsonProperty("isRepresent")
public boolean isRepresent() {
return isRepresent;
}

public static RuleInfo of(Rule rule, LocalDateTime now) {
return RuleInfo.builder()
.id(rule.getId())
.name(rule.getName())
.isNew(now.isBefore(rule.getCreatedAt().plusHours(12)))
.isRepresent(rule.isRepresent())
.createdAt(rule.getCreatedAt().toString())
.build();
}
Expand Down