Skip to content

Commit

Permalink
Merge pull request #346 from Hous-Release/fix/#344
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejungg committed Aug 2, 2023
2 parents 7d45586 + dfa38c0 commit 67d3484
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonProperty;

import hous.core.domain.rule.Rule;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -36,6 +38,11 @@ private static class RuleInfo {
private String name;
private boolean isRepresent;

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

public static RuleInfo of(Rule rule) {
return RuleInfo.builder()
.id(rule.getId())
Expand Down
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

0 comments on commit 67d3484

Please sign in to comment.