Skip to content

Commit

Permalink
HOTFIX: 커밋 업데이트 날짜 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yechan-kim committed Aug 1, 2024
1 parent 29eb0eb commit 2b7e512
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record CommitResponse(
Integer consecutiveCommitDays,
Integer todayCommitCount,
Integer totalCommitCount,
LocalDateTime updatedAt
LocalDateTime lastCommitUpdateTime
) {
public static CommitResponse of(boolean isMyAccount, User user){
return CommitResponse.builder()
Expand All @@ -30,7 +30,7 @@ public static CommitResponse of(boolean isMyAccount, User user){
.consecutiveCommitDays(user.getConsecutiveCommitDays())
.todayCommitCount(user.getTodayCommitCount())
.totalCommitCount(user.getTotalCommitCount())
.updatedAt(user.getUpdatedAt())
.lastCommitUpdateTime(user.getLastCommitUpdateTime())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ public CommitResponse execute(HttpServletRequest request) {
User user = userRepository.findByGithubId(gitHubId)
.orElseThrow(() -> new UsernameNotFoundException("해당하는 깃허브 닉네임과 일치하는 유저를 찾을 수 없음: " + gitHubId));

LocalDateTime dateTime;
try {
dateTime = commitRepository.findAllByUser(user).stream()
.max(Comparator.comparing(Commit::getUpdatedAt))
.orElseThrow(() -> new ApiException(ErrorStatus._COMMIT_NOT_FOUND))
.getUpdatedAt();
} catch (ApiException e) {
LocalDateTime dateTime = user.getLastCommitUpdateTime();

if(dateTime == null) {
dateTime = user.getCreatedAt().toLocalDate().atStartOfDay();
}

Expand Down Expand Up @@ -74,6 +70,9 @@ public CommitResponse execute(HttpServletRequest request) {

executor.shutdown();

user.updateLastCommitUpdateTime(LocalDateTime.now());
userRepository.save(user);

saveCommits(user);

expService.calculateAndSaveExp(gitHubId);//커밋 가져온 후 경험치 계산 및 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ public CommitResponse execute(HttpServletRequest request) {
User user = userRepository.findByGithubId(gitHubId)
.orElseThrow(() -> new UsernameNotFoundException("해당하는 깃허브 닉네임과 일치하는 유저를 찾을 수 없음: " + gitHubId));

LocalDateTime dateTime;
try {
dateTime = commitRepository.findAllByUser(user).stream()
.max(Comparator.comparing(Commit::getUpdatedAt))
.orElseThrow(() -> new ApiException(ErrorStatus._COMMIT_NOT_FOUND))
.getUpdatedAt();
} catch (ApiException e) {
LocalDateTime dateTime = user.getLastCommitUpdateTime();

if(dateTime == null) {
dateTime = LocalDateTime.of(2024, 7, 1, 0, 0, 0);
}

Expand Down Expand Up @@ -71,6 +67,9 @@ public CommitResponse execute(HttpServletRequest request) {

executor.shutdown();

user.updateLastCommitUpdateTime(LocalDateTime.now());
userRepository.save(user);

saveCommits(user);

expService.calculateAndSaveExp(gitHubId);//커밋 가져온 후 경험치 계산 및 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;

@Entity(name = "users")
Expand Down Expand Up @@ -54,6 +56,9 @@ public class User extends BaseTimeEntity {
@JoinColumn(name = "tier_id")
private Tier tier;

@Column
private LocalDateTime lastCommitUpdateTime;

public void updateExp(Integer exp) {
this.exp = exp;
}
Expand All @@ -77,4 +82,8 @@ public void updateTodayCommitCount(Integer todayCommitCount) {
public void updateRank(Integer ranking) {
this.ranking = ranking;
}

public void updateLastCommitUpdateTime (LocalDateTime lastCommitUpdateTime) {
this.lastCommitUpdateTime = lastCommitUpdateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record UserInfoResponse(
Integer consecutiveCommitDays,
Integer todayCommitCount,
Integer totalCommitCount,
LocalDateTime updatedAt
LocalDateTime lastCommitUpdateTime
) {
public static UserInfoResponse of(boolean isMyAccount, User user){
return UserInfoResponse.builder()
Expand All @@ -30,7 +30,7 @@ public static UserInfoResponse of(boolean isMyAccount, User user){
.consecutiveCommitDays(user.getConsecutiveCommitDays())
.todayCommitCount(user.getTodayCommitCount())
.totalCommitCount(user.getTotalCommitCount())
.updatedAt(user.getUpdatedAt())
.lastCommitUpdateTime(user.getLastCommitUpdateTime())
.build();
}
}

0 comments on commit 2b7e512

Please sign in to comment.