Skip to content

Commit 00c308f

Browse files
cursoragentram.dafale
andcommitted
Add live data sync and FlashScore API integration for tennis matches
Co-authored-by: ram.dafale <ram.dafale@cognizant.com>
1 parent 24927e4 commit 00c308f

14 files changed

Lines changed: 1101 additions & 4 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.tennis.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.http.client.SimpleClientHttpRequestFactory;
6+
import org.springframework.web.client.RestTemplate;
7+
8+
/**
9+
* Configuration for RestTemplate to handle HTTP requests
10+
*/
11+
@Configuration
12+
public class RestTemplateConfig {
13+
14+
@Bean
15+
public RestTemplate restTemplate() {
16+
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
17+
factory.setConnectTimeout(10000); // 10 seconds
18+
factory.setReadTimeout(30000); // 30 seconds
19+
20+
return new RestTemplate(factory);
21+
}
22+
}

src/main/java/com/tennis/controller/TennisPredictionController.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.tennis.entity.*;
44
import com.tennis.repository.*;
55
import com.tennis.service.PredictionService;
6+
import com.tennis.service.LiveDataSyncService;
67
import lombok.RequiredArgsConstructor;
78
import lombok.extern.slf4j.Slf4j;
89
import org.springframework.http.ResponseEntity;
@@ -31,9 +32,84 @@ public class TennisPredictionController {
3132
private final MatchRepository matchRepository;
3233
private final MatchPredictionRepository predictionRepository;
3334
private final HeadToHeadRepository headToHeadRepository;
35+
private final LiveDataSyncService liveDataSyncService;
3436

3537

3638

39+
// ==================== LIVE DATA ENDPOINTS ====================
40+
41+
/**
42+
* Trigger manual sync of live data from FlashScore API
43+
*/
44+
@PostMapping("/sync/live-data")
45+
@ResponseBody
46+
public ResponseEntity<Map<String, Object>> syncLiveData() {
47+
log.info("Manual live data sync triggered");
48+
49+
try {
50+
liveDataSyncService.triggerManualSync();
51+
52+
Map<String, Object> response = new HashMap<>();
53+
response.put("message", "Live data sync completed successfully");
54+
response.put("timestamp", LocalDateTime.now());
55+
response.put("status", "success");
56+
57+
return ResponseEntity.ok(response);
58+
59+
} catch (Exception e) {
60+
log.error("Error during live data sync: {}", e.getMessage());
61+
62+
Map<String, Object> response = new HashMap<>();
63+
response.put("message", "Error during live data sync: " + e.getMessage());
64+
response.put("timestamp", LocalDateTime.now());
65+
response.put("status", "error");
66+
67+
return ResponseEntity.status(500).body(response);
68+
}
69+
}
70+
71+
/**
72+
* Get live matches with real-time data
73+
*/
74+
@GetMapping("/matches/live/realtime")
75+
@ResponseBody
76+
public ResponseEntity<List<Match>> getLiveMatchesRealtime() {
77+
log.info("Getting real-time live matches");
78+
79+
List<Match> liveMatches = liveDataSyncService.getLiveMatches();
80+
return ResponseEntity.ok(liveMatches);
81+
}
82+
83+
/**
84+
* Mark match as completed
85+
*/
86+
@PutMapping("/matches/{matchId}/complete")
87+
@ResponseBody
88+
public ResponseEntity<Map<String, Object>> markMatchAsCompleted(@PathVariable Long matchId) {
89+
log.info("Marking match {} as completed", matchId);
90+
91+
try {
92+
liveDataSyncService.markMatchAsCompleted(matchId);
93+
94+
Map<String, Object> response = new HashMap<>();
95+
response.put("message", "Match marked as completed");
96+
response.put("matchId", matchId);
97+
response.put("timestamp", LocalDateTime.now());
98+
99+
return ResponseEntity.ok(response);
100+
101+
} catch (Exception e) {
102+
log.error("Error marking match as completed: {}", e.getMessage());
103+
104+
Map<String, Object> response = new HashMap<>();
105+
response.put("message", "Error marking match as completed: " + e.getMessage());
106+
response.put("matchId", matchId);
107+
response.put("timestamp", LocalDateTime.now());
108+
109+
return ResponseEntity.status(500).body(response);
110+
}
111+
}
112+
37113
// ==================== PREDICTION ENDPOINTS ====================
38114

39115
/**

0 commit comments

Comments
 (0)