Skip to content

Commit

Permalink
refactor: (#515) score 반환 long으로 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Sep 6, 2023
1 parent f4c1261 commit 9eba1d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record RankingResponse(
int voteCount,

@Schema(description = "점수", example = "31")
int score
long score
) {
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ActivityRecord(int postCount, int voteCount) {
this.voteCount = voteCount;
}

public int calculateScore() {
public long calculateScore() {
return postCount * POST_WEIGHT + voteCount * VOTE_WEIGHT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.votogether.domain.member.entity.Member;
import com.votogether.domain.member.entity.vo.ActivityRecord;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -18,15 +19,15 @@ public RankingBoard(final Map<Member, ActivityRecord> passionBoard) {

private void calculateRank() {
final List<Member> members = passionBoard.entrySet().stream()
.sorted((e1, e2) -> e2.getValue().calculateScore() - e1.getValue().calculateScore())
.sorted(Comparator.comparingLong(entry -> -entry.getValue().calculateScore()))
.map(s -> s.getKey())
.toList();

int currentRanking = 1;
int previousRanking = -1;
int previousScore = -1;
long previousScore = -1;
for (Member member : members) {
int currentScore = passionBoard.get(member).calculateScore();
long currentScore = passionBoard.get(member).calculateScore();
int ranking = (currentScore == previousScore) ? previousRanking : currentRanking;

this.ranking.put(member, ranking);
Expand All @@ -37,7 +38,7 @@ private void calculateRank() {
}
}

public int score(Member member) {
public long score(Member member) {
return passionBoard.get(member).calculateScore();
}

Expand Down

0 comments on commit 9eba1d8

Please sign in to comment.