File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
src/main/java/cmf/commitField Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 77
88@ SpringBootApplication
99@ EnableJpaAuditing
10- // 스케쥴링 활성화
11- // 테스트시에만 주석 풀기
1210@ EnableScheduling
1311public class CommitFieldApplication {
1412 public static void main (String [] args ) {
Original file line number Diff line number Diff line change 44import cmf .commitField .domain .user .service .UserService ;
55import lombok .RequiredArgsConstructor ;
66import org .springframework .context .event .EventListener ;
7+ import org .springframework .messaging .simp .SimpMessagingTemplate ;
78import org .springframework .stereotype .Component ;
89
910@ Component
@@ -12,6 +13,7 @@ public class CommitUpdateListener {
1213 private final UserService userService ;
1314 private final PetService petService ;
1415 private final CommitUpdateService commitUpdateService ;
16+ private final SimpMessagingTemplate messagingTemplate ;
1517
1618 @ EventListener
1719 public void handleCommitUserUpdateEvent (CommitUpdateEvent event ) {
@@ -41,4 +43,14 @@ public void handleCommitPetUpdateEvent(CommitUpdateEvent event) {
4143 // 커밋 갱신 후에 다른 서비스에서 필요한 작업 수행 (예: DB 업데이트, 상태 갱신 등)
4244 System .out .println ("유저명: " + username + "'s pet has updated " + commitCount + " commits." );
4345 }
46+
47+ @ EventListener
48+ public void onCommitCountUpdate (CommitUpdateEvent event ) {
49+ // 커밋 수 업데이트가 있을 때 메시지 발송
50+ String username = event .getUsername ();
51+ long newCommitCount = event .getNewCommitCount ();
52+
53+ // 메시지를 WebSocket을 통해 전송
54+ messagingTemplate .convertAndSend ("/topic/commit/" + username , newCommitCount );
55+ }
4456}
Original file line number Diff line number Diff line change 11package cmf .commitField .domain .commit .scheduler ;
22
33import cmf .commitField .domain .commit .totalCommit .service .TotalCommitService ;
4- import cmf .commitField .domain .pet .service .PetService ;
54import cmf .commitField .domain .user .dto .UserInfoDto ;
65import cmf .commitField .domain .user .entity .User ;
76import cmf .commitField .domain .user .repository .UserRepository ;
87import lombok .RequiredArgsConstructor ;
8+ import org .springframework .messaging .simp .SimpMessagingTemplate ;
99import org .springframework .stereotype .Service ;
1010
1111import java .time .LocalDateTime ;
1515public class CommitUpdateService {
1616 private final TotalCommitService totalCommitService ;
1717 private final UserRepository userRepository ;
18- private final PetService petService ;
18+ private final SimpMessagingTemplate messagingTemplate ;
1919
20+ // 유저 랭킹 상승 로짓
2021 public UserInfoDto updateUserTier (String username ){
2122 User user = userRepository .findByUsername (username ).get ();
2223 long seasonCommitCount ;
@@ -35,4 +36,5 @@ public UserInfoDto updateUserTier(String username){
3536 .tier (user .getTier ().name ())
3637 .build ();
3738 }
39+
3840}
You can’t perform that action at this time.
0 commit comments