Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/java/cmf/commitField/CommitFieldApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@

@SpringBootApplication
@EnableJpaAuditing
// 스케쥴링 활성화
// 테스트시에만 주석 풀기
@EnableScheduling
public class CommitFieldApplication {
public static void main(String[] args) {
SpringApplication.run(CommitFieldApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cmf.commitField.domain.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -12,6 +13,7 @@ public class CommitUpdateListener {
private final UserService userService;
private final PetService petService;
private final CommitUpdateService commitUpdateService;
private final SimpMessagingTemplate messagingTemplate;

@EventListener
public void handleCommitUserUpdateEvent(CommitUpdateEvent event) {
Expand Down Expand Up @@ -41,4 +43,14 @@ public void handleCommitPetUpdateEvent(CommitUpdateEvent event) {
// 커밋 갱신 후에 다른 서비스에서 필요한 작업 수행 (예: DB 업데이트, 상태 갱신 등)
System.out.println("유저명: " + username + "'s pet has updated " + commitCount + " commits.");
}

@EventListener
public void onCommitCountUpdate(CommitUpdateEvent event) {
// 커밋 수 업데이트가 있을 때 메시지 발송
String username = event.getUsername();
long newCommitCount = event.getNewCommitCount();

// 메시지를 WebSocket을 통해 전송
messagingTemplate.convertAndSend("/topic/commit/" + username, newCommitCount);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmf.commitField.domain.commit.scheduler;

import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService;
import cmf.commitField.domain.pet.service.PetService;
import cmf.commitField.domain.user.dto.UserInfoDto;
import cmf.commitField.domain.user.entity.User;
import cmf.commitField.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
Expand All @@ -15,8 +15,9 @@
public class CommitUpdateService {
private final TotalCommitService totalCommitService;
private final UserRepository userRepository;
private final PetService petService;
private final SimpMessagingTemplate messagingTemplate;

// 유저 랭킹 상승 로짓
public UserInfoDto updateUserTier(String username){
User user = userRepository.findByUsername(username).get();
long seasonCommitCount;
Expand All @@ -35,4 +36,5 @@ public UserInfoDto updateUserTier(String username){
.tier(user.getTier().name())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<CommitAnalysisResponseDto> getWinterSeasonCommits(
) {
int currentYear = LocalDateTime.now().getYear();
LocalDateTime since = LocalDateTime.of(2024, 12, 1, 0, 0);
LocalDateTime until = LocalDateTime.of(2024 + 1, 2, 1, 23, 59, 59)
LocalDateTime until = LocalDateTime.of(2024 + 1, 2, 28, 23, 59, 59)
.with(TemporalAdjusters.lastDayOfMonth());

CommitAnalysisResponseDto analysis = sinceCommitService.getCommitAnalysis(owner, repo, since, until);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Optional<User> getUserByEmail(String email) {

public void setUserActive(String username) {
String count = String.valueOf(userRepository.findByUsername(username).get().getCommitCount());
redisTemplate.opsForValue().set("commit_active:" + username, count);
redisTemplate.opsForValue().set("commit_active:" + username, count, 3, TimeUnit.HOURS);
redisTemplate.opsForValue().set("commit_lastCommitted:" + username, LocalDateTime.now().toString(),3, TimeUnit.HOURS);

}
Expand Down