File tree 4 files changed +22
-2
lines changed
src/main/java/com/leets/commitatobe/domain
presentation/dto/response
4 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 8
8
import com .leets .commitatobe .domain .user .domain .repository .UserRepository ;
9
9
import jakarta .transaction .Transactional ;
10
10
import lombok .RequiredArgsConstructor ;
11
+ import org .springframework .data .domain .Pageable ;
11
12
import org .springframework .security .core .userdetails .UsernameNotFoundException ;
12
13
import org .springframework .stereotype .Service ;
13
14
@@ -69,6 +70,18 @@ public void calculateAndSaveExp(String githubId){
69
70
user .updateTotalCommitCount (totalCommitCount );
70
71
user .updateTodayCommitCount (todayCommitCount );
71
72
73
+ List <User > allUsers = userRepository .findAllByOrderByExpDesc (Pageable .unpaged ()).getContent ();
74
+ int ranking = 0 ;
75
+ int previousExp = -1 ;
76
+ for (User userToUpdate : allUsers ){
77
+ if (userToUpdate .getExp ()!=previousExp ) {
78
+ ranking += 1 ;
79
+ previousExp =userToUpdate .getExp ();//만약 경험치 같으면 동일한 랭킹부여.
80
+ }
81
+ userToUpdate .updateRank (ranking );//랭킹 업데이트
82
+ userRepository .save (userToUpdate );//데이터베이스에 저장
83
+ }
84
+
72
85
commitRepository .saveAll (commits );//변경된 커밋 정보 데이터베이스에 저장
73
86
userRepository .save (user );//변경된 사용자 정보 데이터베이스에 저장
74
87
}
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ public class User extends BaseTimeEntity {
50
50
@ Column
51
51
private Integer todayCommitCount ;
52
52
53
+ @ Column
54
+ private Integer ranking ;// 랭킹 추가
55
+
53
56
@ OneToMany (mappedBy = "user" )
54
57
@ JsonManagedReference
55
58
private List <Commit > commitList ;
@@ -77,4 +80,6 @@ public void updateTotalCommitCount(Integer totalCommitCount){
77
80
public void updateTodayCommitCount (Integer todayCommitCount ){
78
81
this .todayCommitCount =todayCommitCount ;
79
82
}
83
+
84
+ public void updateRank (Integer ranking ) { this .ranking = ranking ; }
80
85
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ public record UserRankResponse(
6
6
String username ,
7
7
Integer exp ,
8
8
Integer consecutiveCommitDays ,
9
- String tierName
9
+ String tierName ,
10
+ Integer ranking //랭킹 추가
10
11
) {
11
12
}
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ public Page<UserRankResponse> getUsersByExp(Pageable pageable){//경험치 순
60
60
user .getUsername (),
61
61
user .getExp (),
62
62
user .getConsecutiveCommitDays (),
63
- tier !=null ?tier .getTierName ():"Unranked" );
63
+ tier !=null ?tier .getTierName ():"Unranked" ,
64
+ user .getRanking ());//랭킹 추가
64
65
});
65
66
}
66
67
You can’t perform that action at this time.
0 commit comments