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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ docker-compose.yaml
db/
.docker
data/
.dummy

### secret 프로필
application-secret.yml
Expand Down
12 changes: 0 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ dependencies {
// Spring Security OAuth2
implementation ("org.springframework.security:spring-security-oauth2-client:6.4.2") // Or the version you're using
implementation ("org.springframework.security:spring-security-oauth2-core:6.4.2") // Or the version you're using

// Spring Kafka
implementation("org.springframework.kafka:spring-kafka")

// Kafka 클라이언트 (Redpanda와 호환)
implementation("org.apache.kafka:kafka-clients:3.6.0")

// JSON 직렬화/역직렬화 (Kafka 메시지 처리)
implementation("com.fasterxml.jackson.core:jackson-databind")

// 테스트용 Kafka 임베디드 서버 (선택 사항)
testImplementation("org.springframework.kafka:spring-kafka-test")
}

tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cmf.commitField.domain.commit.sinceCommit.service.CommitCacheService;
import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService;
import cmf.commitField.domain.redpanda.RedpandaProducer;
import cmf.commitField.domain.user.entity.User;
import cmf.commitField.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,7 +22,6 @@
public class CommitScheduler {
private final TotalCommitService totalCommitService;
private final CommitCacheService commitCacheService;
private final RedpandaProducer redpandaProducer;
private final UserRepository userRepository;
private final StringRedisTemplate redisTemplate;
private final AtomicInteger counter = new AtomicInteger(0);
Expand Down Expand Up @@ -68,7 +66,7 @@ private void processUserCommit(User user) {
}

// 현재 커밋 개수 조회
long currentCommitCount = totalCommitService.getSeasonCommits(
long currentCommitCount = totalCommitService.getUpdateCommits(
user.getUsername(),
lastCommitted, // 🚀 Redis에 저장된 lastCommitted 기준으로 조회
LocalDateTime.now()
Expand All @@ -94,9 +92,6 @@ private void updateCommitData(User user, long currentCommitCount, long newCommit
// 2️⃣ Redis에 최신 커밋 개수 저장 (3시간 동안 유지)
commitCacheService.updateCachedCommitCount(user.getUsername(), currentCommitCount);

// 3️⃣ 메시지 큐 전송
redpandaProducer.sendCommitUpdate(user.getUsername(), newCommitCount);

log.info("✅ 커밋 반영 완료 - User: {}, New Commits: {}", user.getUsername(), newCommitCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import cmf.commitField.domain.commit.sinceCommit.dto.CommitAnalysisResponseDto;
import cmf.commitField.domain.commit.sinceCommit.dto.SinceCommitResponseDto;
import cmf.commitField.domain.commit.sinceCommit.service.GithubService;
import cmf.commitField.domain.commit.sinceCommit.service.SinceCommitService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -20,7 +18,6 @@
@RequiredArgsConstructor
public class SinceCommitController {
private final SinceCommitService sinceCommitService;
private final GithubService githubService;

@GetMapping("/api/github/commits-since")
public ResponseEntity<List<SinceCommitResponseDto>> getCommits(
Expand Down Expand Up @@ -104,11 +101,4 @@ public ResponseEntity<CommitAnalysisResponseDto> getWinterSeasonCommits(
return ResponseEntity.ok(analysis);
}

// api 테스트 메소드 추가
@GetMapping("/api/commit-count/{username}")
public ResponseEntity<Integer> getCommitCount(@PathVariable String username) {
System.out.println("⚡ API 엔드포인트 호출: " + username);
int commitCount = githubService.getUserCommitCount(username);
return ResponseEntity.ok(commitCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CommitCacheService {
private final StringRedisTemplate redisTemplate;

public Integer getCachedCommitCount(String username) {
String key = "commit_active:" + username; // Redis 키 생성 (ex: commit:hongildong)
String key = "commit_active:" + username; // Redis 키 생성
String value = redisTemplate.opsForValue().get(key); // Redis에서 값 가져오기

if (value != null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,43 @@ private StreakResult calculateStreaks(List<LocalDate> commitDates) {

return new StreakResult(currentStreak, maxStreak);
}

// 시간별 커밋 분석
public TotalCommitResponseDto getUpdateCommits(String username, LocalDateTime since, LocalDateTime until) {
String query = String.format("""
query {
user(login: "%s") {
contributionsCollection(from: "%s", to: "%s") {
commitContributionsByRepository {
contributions(first: 100) {
nodes {
occurredAt # ✅ 시간 정보 포함
}
}
}
}
}
}""", username, since.format(DateTimeFormatter.ISO_DATE_TIME), until.format(DateTimeFormatter.ISO_DATE_TIME));

Map<String, String> requestBody = Map.of("query", query);

TotalCommitGraphQLResponse response = webClient.post()
.header("Authorization", "bearer " + PAT)
.bodyValue(requestBody)
.retrieve()
.bodyToMono(TotalCommitGraphQLResponse.class)
.block();

if (response == null || response.getData() == null || response.getData().getUser() == null) {
throw new RuntimeException("Failed to fetch GitHub data");
}

TotalCommitGraphQLResponse.ContributionsCollection contributions =
response.getData().getUser().getContributionsCollection();

return new TotalCommitResponseDto(
contributions.getTotalCommitContributions(),
contributions.getRestrictedContributionsCount()
);
}
}
13 changes: 0 additions & 13 deletions src/main/java/cmf/commitField/domain/redpanda/KafkaConsumer.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/cmf/commitField/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class User extends BaseEntity {
private String avatarUrl; //아바타
private Boolean status; //로그인 true, 로그아웃 false
private LocalDateTime lastCommitted; // 마지막 커밋 시간
private long commitCount;

@Enumerated(EnumType.STRING) // DB에 저장될 때 String 형태로 저장됨
private Role role;
Expand Down Expand Up @@ -64,6 +65,7 @@ public User(String username, String email, String nickname, String avatarUrl, Bo
this.userChatRooms = ucr;
this.chatMsgs = cmsg;
this.lastCommitted = LocalDateTime.now();
this.commitCount = 0;
}

public void addPets(Pet pet){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmf.commitField.domain.user.service;

import cmf.commitField.domain.commit.sinceCommit.service.CommitCacheService;
import cmf.commitField.domain.commit.totalCommit.service.TotalCommitService;
import cmf.commitField.domain.pet.entity.Pet;
import cmf.commitField.domain.pet.repository.PetRepository;
import cmf.commitField.domain.user.entity.CustomOAuth2User;
Expand All @@ -25,6 +26,7 @@ public class CustomOAuth2UserService extends DefaultOAuth2UserService {
private final PetRepository petRepository;
private final HttpServletRequest request; // HttpServletRequest를 주입 받음.
private final CommitCacheService commitCacheService;
private final TotalCommitService totalCommitService;

@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) {
Expand Down Expand Up @@ -62,6 +64,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) {
petRepository.save(pet);

user.addPets(pet);
user.setCommitCount(totalCommitService.getTotalCommitCount(user.getUsername()).getTotalCommitContributions());

// 회원가입한 유저는 커밋 기록에 상관없이 Redis에 입력해둔다.
commitCacheService.updateCachedCommitCount(user.getUsername(),0);
Expand Down

This file was deleted.