|
3 | 3 | import com.tennis.entity.*; |
4 | 4 | import com.tennis.repository.*; |
5 | 5 | import com.tennis.service.PredictionService; |
| 6 | +import com.tennis.service.LiveDataSyncService; |
6 | 7 | import lombok.RequiredArgsConstructor; |
7 | 8 | import lombok.extern.slf4j.Slf4j; |
8 | 9 | import org.springframework.http.ResponseEntity; |
@@ -31,9 +32,84 @@ public class TennisPredictionController { |
31 | 32 | private final MatchRepository matchRepository; |
32 | 33 | private final MatchPredictionRepository predictionRepository; |
33 | 34 | private final HeadToHeadRepository headToHeadRepository; |
| 35 | + private final LiveDataSyncService liveDataSyncService; |
34 | 36 |
|
35 | 37 |
|
36 | 38 |
|
| 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 | + |
37 | 113 | // ==================== PREDICTION ENDPOINTS ==================== |
38 | 114 |
|
39 | 115 | /** |
|
0 commit comments