Fonctionne git add .git add .
This commit is contained in:
parent
db352ab6bf
commit
4797a3ee53
8 changed files with 32 additions and 105 deletions
|
|
@ -11,7 +11,7 @@ import java.util.Date
|
|||
|
||||
enum class MatchState {
|
||||
ONGOING,
|
||||
FINISHED,
|
||||
OVER,
|
||||
NOT_STARTED
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class MatchRestController(private val matchService: MatchService) {
|
|||
// Lister les matchs terminés
|
||||
@GetMapping("/over")
|
||||
fun getAllFinished(): ResponseEntity<List<MatchBean>?> {
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.state == MatchState.FINISHED })
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.state == MatchState.OVER })
|
||||
}
|
||||
|
||||
// Lister les matchs non commencés
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class RefereeWebSocketController(
|
|||
id = refereeUpdateMessage.refereeId,
|
||||
name = refereeUpdateMessage.name,
|
||||
firstName = refereeUpdateMessage.firstName,
|
||||
qualification = refereeUpdateMessage.qualification
|
||||
level = refereeUpdateMessage.level
|
||||
)
|
||||
|
||||
// Update the referee in the database
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.teamflash.fencerjudgeback.websocket.models
|
||||
|
||||
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Message model for match updates sent through WebSocket
|
||||
|
|
@ -12,7 +13,7 @@ data class MatchUpdateMessage(
|
|||
val refereeId: Long?,
|
||||
val score1: Int,
|
||||
val score2: Int,
|
||||
val date: String?,
|
||||
val date: Date?,
|
||||
val type: UpdateType = UpdateType.SCORE_UPDATE
|
||||
) {
|
||||
enum class UpdateType {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.teamflash.fencerjudgeback.websocket.models
|
||||
|
||||
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
||||
import fr.teamflash.fencerjudgeback.entities.RefereeLevel
|
||||
|
||||
/**
|
||||
* Message model for referee updates sent through WebSocket
|
||||
|
|
@ -9,7 +10,7 @@ data class RefereeUpdateMessage(
|
|||
val refereeId: Long,
|
||||
val name: String?,
|
||||
val firstName: String?,
|
||||
val qualification: String?,
|
||||
val level: RefereeLevel?,
|
||||
val type: UpdateType = UpdateType.REFEREE_UPDATE
|
||||
) {
|
||||
enum class UpdateType {
|
||||
|
|
@ -27,7 +28,7 @@ data class RefereeUpdateMessage(
|
|||
refereeId = refereeBean.id ?: 0,
|
||||
name = refereeBean.name,
|
||||
firstName = refereeBean.firstName,
|
||||
qualification = refereeBean.qualification,
|
||||
level = refereeBean.level,
|
||||
type = type
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export enum MatchState {
|
||||
ONGOING = 1,
|
||||
OVER = 2,
|
||||
NOT_STARTED = 3,
|
||||
ONGOING = 0,
|
||||
OVER = 1,
|
||||
NOT_STARTED = 2,
|
||||
}
|
||||
|
||||
export interface Matches {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, Subject, BehaviorSubject, of } from 'rxjs';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Matches, MatchState } from '@interfaces/matches';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
|
|
@ -46,115 +45,41 @@ export class MatchesService {
|
|||
state: MatchState.NOT_STARTED,
|
||||
},
|
||||
];
|
||||
private socket?: WebSocket;
|
||||
private apiUrl = 'http://localhost:8080';
|
||||
private matchUpdates$ = new Subject<Matches[]>();
|
||||
private allMatches: Matches[] = [];
|
||||
private nextMatchId = Math.max(...this.matches.map((m) => m.id)) + 1;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.sendCurrentMatches();
|
||||
}
|
||||
|
||||
public sendCurrentMatches(): void {
|
||||
if (!this.matches || this.matches.length === 0) {
|
||||
console.warn('[HTTP] ⚠️ Aucun match à envoyer.');
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
|
||||
this.matches.forEach((match) => {
|
||||
this.http
|
||||
.post(
|
||||
this.apiUrl + '/matches/create-match',
|
||||
JSON.stringify(match),
|
||||
headers
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
console.log('[HTTP] ✅ Match envoyé avec succès :', response);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(
|
||||
'[HTTP] ❌ Erreur lors de l’envoi d’un match :',
|
||||
error
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private connectToMatchUpdatesWebSocket(): void {
|
||||
const wsUrl = 'http://localhost:8080/ws';
|
||||
this.socket = new WebSocket(wsUrl);
|
||||
|
||||
this.socket.onopen = () => {
|
||||
console.log('[WebSocket] ✅ Connecté à', wsUrl);
|
||||
};
|
||||
|
||||
this.socket.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data) as Matches[];
|
||||
console.log('[WebSocket] 📥 Données reçues :', data);
|
||||
this.matchUpdates$.next(data);
|
||||
} catch (e) {
|
||||
console.error('[WebSocket] ❌ Erreur de parsing JSON', e);
|
||||
}
|
||||
};
|
||||
|
||||
this.socket.onerror = (err) => {
|
||||
console.error('[WebSocket] ❌ Erreur :', err);
|
||||
};
|
||||
|
||||
this.socket.onclose = () => {
|
||||
console.warn('[WebSocket] 🔌 Fermeture de la connexion');
|
||||
};
|
||||
}
|
||||
|
||||
private sendMatchesToWebSocket(): void {
|
||||
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
||||
const dataToSend = JSON.stringify(this.matches);
|
||||
this.socket.send(dataToSend);
|
||||
console.log('[WebSocket] 📤 Données envoyées :', dataToSend);
|
||||
} else {
|
||||
console.warn("[WebSocket] ⚠️ Le WebSocket n'est pas encore ouvert.");
|
||||
}
|
||||
constructor() {
|
||||
console.log('[MatchesService] Initial matches loaded:', this.matches);
|
||||
}
|
||||
|
||||
getMatches(): Observable<Matches[]> {
|
||||
return this.matchUpdates$.asObservable();
|
||||
console.log('[MatchesService] Fetching all matches');
|
||||
return of(this.matches);
|
||||
}
|
||||
|
||||
getMatchById(id: number): Observable<Matches | undefined> {
|
||||
const match = this.allMatches.find((m) => m.id === id);
|
||||
console.log(`[MatchesService] Match ID ${id} récupéré :`, match);
|
||||
return new BehaviorSubject(match).asObservable();
|
||||
const match = this.matches.find((m) => m.id === id);
|
||||
console.log(`[MatchesService] Fetching match ID: ${id}`, match);
|
||||
return of(match);
|
||||
}
|
||||
|
||||
// Préparation future pour WebSocket
|
||||
connectToMatchUpdatesWebSocket(): void {
|
||||
console.log(
|
||||
'[MatchesService] WebSocket connection placeholder initialized'
|
||||
);
|
||||
// ici tu pourrais plus tard faire : this.socket = new WebSocket('ws://...') etc.
|
||||
}
|
||||
|
||||
updateMatch(id: number, updatedData: Partial<Matches>): void {
|
||||
const matchIndex = this.allMatches.findIndex((m) => m.id === id);
|
||||
if (matchIndex !== -1) {
|
||||
const updatedMatch = { ...this.allMatches[matchIndex], ...updatedData };
|
||||
this.allMatches[matchIndex] = updatedMatch;
|
||||
this.matchUpdates$.next([...this.allMatches]); // émettre un nouveau tableau
|
||||
console.log(
|
||||
`[MatchesService] Match ${id} mis à jour localement :`,
|
||||
updatedMatch
|
||||
);
|
||||
const match = this.matches.find((m) => m.id === id);
|
||||
if (match) {
|
||||
Object.assign(match, updatedData);
|
||||
console.log(`[MatchesService] Match ${id} mis à jour :`, match);
|
||||
} else {
|
||||
console.warn(`[MatchesService] Match ${id} non trouvé pour mise à jour`);
|
||||
console.warn(`[MatchesService] Match ${id} introuvable`);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.socket?.close();
|
||||
}
|
||||
|
||||
create(match: Omit<Matches, 'id'>): Observable<Matches> {
|
||||
const newMatch: Matches = {
|
||||
...match,
|
||||
|
|
|
|||
BIN
db.mv.db
BIN
db.mv.db
Binary file not shown.
Loading…
Add table
Reference in a new issue