Skip to content

Commit 2d2522b

Browse files
committed
fix: 사용하지 않는 메소드 및 서비스 삭제
1 parent 268c015 commit 2d2522b

File tree

8 files changed

+90
-106
lines changed

8 files changed

+90
-106
lines changed

src/main/java/cmf/commitField/domain/commit/sinceCommit/controller/SinceCommitController.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import cmf.commitField.domain.commit.sinceCommit.dto.CommitAnalysisResponseDto;
44
import cmf.commitField.domain.commit.sinceCommit.dto.SinceCommitResponseDto;
5-
import cmf.commitField.domain.commit.sinceCommit.service.GithubService;
65
import cmf.commitField.domain.commit.sinceCommit.service.SinceCommitService;
76
import lombok.RequiredArgsConstructor;
87
import org.springframework.format.annotation.DateTimeFormat;
98
import org.springframework.http.ResponseEntity;
109
import org.springframework.web.bind.annotation.GetMapping;
11-
import org.springframework.web.bind.annotation.PathVariable;
1210
import org.springframework.web.bind.annotation.RequestParam;
1311
import org.springframework.web.bind.annotation.RestController;
1412

@@ -20,7 +18,6 @@
2018
@RequiredArgsConstructor
2119
public class SinceCommitController {
2220
private final SinceCommitService sinceCommitService;
23-
private final GithubService githubService;
2421

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

107-
// api 테스트 메소드 추가
108-
@GetMapping("/api/commit-count/{username}")
109-
public ResponseEntity<Integer> getCommitCount(@PathVariable String username) {
110-
System.out.println("⚡ API 엔드포인트 호출: " + username);
111-
int commitCount = githubService.getUserCommitCount(username);
112-
return ResponseEntity.ok(commitCount);
113-
}
114104
}

src/main/java/cmf/commitField/domain/commit/sinceCommit/service/CommitCacheService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CommitCacheService {
1414
private final StringRedisTemplate redisTemplate;
1515

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

2020
if (value != null) {

src/main/java/cmf/commitField/domain/commit/sinceCommit/service/GithubService.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/cmf/commitField/domain/redpanda/KafkaConsumer.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmf.commitField.domain.redpanda;
2+
3+
import cmf.commitField.domain.redpanda.dto.CommitUpdateMessageDto;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.apache.kafka.clients.consumer.ConsumerRecord;
6+
import org.springframework.kafka.annotation.KafkaListener;
7+
import org.springframework.stereotype.Service;
8+
9+
@Service
10+
public class RedpandaConsumer {
11+
12+
private final ObjectMapper objectMapper;
13+
14+
public RedpandaConsumer(ObjectMapper objectMapper) {
15+
this.objectMapper = objectMapper;
16+
}
17+
18+
@KafkaListener(topics = "commit-topic", groupId = "commit-group")
19+
public void listen(ConsumerRecord<String, String> record) {
20+
try {
21+
String message = record.value();
22+
CommitUpdateMessageDto commitUpdate = objectMapper.readValue(message, CommitUpdateMessageDto.class);
23+
System.out.println("✅ Received commit update: " + commitUpdate);
24+
} catch (Exception e) {
25+
System.err.println("❌ Failed to parse commit update: " + e.getMessage());
26+
}
27+
}
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cmf.commitField.domain.redpanda;
2+
3+
import cmf.commitField.domain.commit.scheduler.CommitScheduler;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
@RestController
8+
@RequestMapping("/api/kafka")
9+
public class RedpandaController {
10+
11+
private final RedpandaProducer redpandaProducer;
12+
private final CommitScheduler commitScheduler;
13+
14+
public RedpandaController(RedpandaProducer redpandaProducer, CommitScheduler commitScheduler) {
15+
this.redpandaProducer = redpandaProducer;
16+
this.commitScheduler = commitScheduler;
17+
}
18+
19+
}
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
package cmf.commitField.domain.redpanda;
22

3+
import cmf.commitField.domain.redpanda.dto.CommitUpdateMessageDto;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
35
import org.springframework.kafka.core.KafkaTemplate;
46
import org.springframework.stereotype.Service;
57

68
@Service
79
public class RedpandaProducer {
810

911
private final KafkaTemplate<String, String> kafkaTemplate;
10-
private static final String TOPIC = "commit-topic"; // Redpanda에서 사용할 토픽명
12+
private final ObjectMapper objectMapper; // JSON 변환을 위한 ObjectMapper
13+
private static final String TOPIC = "commit-topic";
1114

12-
public RedpandaProducer(KafkaTemplate<String, String> kafkaTemplate) {
15+
public RedpandaProducer(KafkaTemplate<String, String> kafkaTemplate, ObjectMapper objectMapper) {
1316
this.kafkaTemplate = kafkaTemplate;
17+
this.objectMapper = objectMapper;
1418
}
1519

16-
// 메시지 전송 메서드
17-
public void sendMessage(String message) {
18-
kafkaTemplate.send(TOPIC, message);
19-
System.out.println("📨 Sent message to Redpanda: " + message);
20-
}
21-
22-
// 커밋 업데이트 전송 메서드
20+
// 🔹 커밋 업데이트 전송 메서드
2321
public void sendCommitUpdate(String username, long commitCount) {
24-
String message = String.format("{\"user\": \"%s\", \"update-commits\": %d}", username, commitCount);
25-
kafkaTemplate.send(TOPIC, message);
26-
System.out.println("📨 Sent commit update to Redpanda: " + message);
22+
try {
23+
CommitUpdateMessageDto message = new CommitUpdateMessageDto(username, commitCount);
24+
String jsonMessage = objectMapper.writeValueAsString(message); // DTO를 JSON으로 변환
25+
kafkaTemplate.send(TOPIC, jsonMessage);
26+
System.out.println("📨 Sent commit update to Redpanda: " + jsonMessage);
27+
} catch (Exception e) {
28+
System.err.println("❌ Failed to send commit update: " + e.getMessage());
29+
}
2730
}
2831
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmf.commitField.domain.redpanda.dto;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Setter
10+
@Getter
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class CommitUpdateMessageDto {
14+
@JsonProperty("user")
15+
private String username;
16+
17+
@JsonProperty("update-commits")
18+
private long commitCount;
19+
20+
@Override
21+
public String toString() {
22+
return "CommitUpdateMessage{" +
23+
"username='" + username + '\'' +
24+
", updateCommitCount=" + commitCount +
25+
'}';
26+
}
27+
}

0 commit comments

Comments
 (0)