Skip to content

Commit

Permalink
Merge pull request #67 from TeamGromit/feat/LHS-11
Browse files Browse the repository at this point in the history
fix : 유저 커밋 갱신 로직 버그 수정
  • Loading branch information
LHS-11 authored Sep 10, 2023
2 parents 00ae790 + 30e90f3 commit c3fae75
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/main/java/com/example/gromit/service/UserAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

import static com.example.gromit.exception.ErrorCode.*;

Expand Down Expand Up @@ -132,8 +133,7 @@ public void reloadCommits(UserAccount userAccount) {

//챌린지 정보와 해당 유저의 멤버 커밋 수 저장
List<Member> members = memberRepository.findAllByUserAccountIdAndIsDeleted(userAccount.getId(), false);
renewCommits(userAccount, oldTodayCommit, totalCommit, todayCommit,now, members);

renewCommits(userAccount, oldTodayCommit, totalCommit, todayCommit, now, members);
userAccountRepository.save(userAccount);
}

Expand Down Expand Up @@ -163,29 +163,30 @@ private static int getTodayCommitByGithub(String now, String gitHubName) {
return todayCommit;
}

private void renewCommits(UserAccount userAccount, int oldTodayCommit, int totalCommit, int todayCommit,LocalDate now, List<Member> members) {
private void renewCommits(UserAccount userAccount, int oldTodayCommit, int totalCommit, int todayCommit, LocalDate now, List<Member> members) {


// 새로고침 누른 유저에 해당하는 참여 챌린지 커밋 갱신
for (Member member : members) {
LocalDate memberCommitDate = member.getCommitDate();
if (memberCommitDate == null || !memberCommitDate.equals(now) || (memberCommitDate.equals(now) && oldTodayCommit != todayCommit)) {
member.setCommits(member.getCommits() + todayCommit);
member.setCommitDate(now);
}
}

// 같은 날에 새로고침 시 커밋 수가 다를 떄
// if (members != null || members.size()!=0) {
// for (Member member : members) {
// LocalDate memberCommitDate = member.getCommitDate();
// if (memberCommitDate == null || !memberCommitDate.equals(now) || (memberCommitDate.equals(now) && oldTodayCommit != todayCommit)) {
// member.setCommits(member.getCommits() + todayCommit);
// member.setCommitDate(now);
// }
// }
// }
LocalDate userCommitDate = userAccount.getCommitDate();
if (userCommitDate.equals(now) && oldTodayCommit != todayCommit) {
userAccount.setCommits(totalCommit + todayCommit-oldTodayCommit);
// 처음 커밋을 하거나 다른 날에 새로고침 시
if (userCommitDate == null || !userCommitDate.equals(now)) {
userAccount.setCommits(totalCommit + todayCommit);
userAccount.setCommitDate(now);
userAccount.setTodayCommit(todayCommit);
}

// 처음 커밋을 하거나 다른 날에 새로고침 시
if(userCommitDate == null || !userCommitDate.equals(now)){
userAccount.setCommits(totalCommit + todayCommit);
// 같은 날에 새로고침 시 커밋 수가 다를 떄
if (userCommitDate != null && userCommitDate.equals(now) && oldTodayCommit != todayCommit) {
userAccount.setCommits(totalCommit + todayCommit - oldTodayCommit);
userAccount.setCommitDate(now);
userAccount.setTodayCommit(todayCommit);
}
Expand Down

0 comments on commit c3fae75

Please sign in to comment.