From fe5212bd97469cf154d8a37e8f519b78e7b27519 Mon Sep 17 00:00:00 2001 From: ExostFlash Date: Tue, 3 Jun 2025 14:14:54 +0200 Subject: [PATCH] modif api --- .../src/app/components/home/home.component.ts | 14 ++++++++-- .../matches-id/matches-id.component.html | 2 +- .../match/matches-id/matches-id.component.ts | 28 +++++++++++++++++-- .../match/matches/matches.component.ts | 13 +++++++++ .../src/app/services/api/api.service.ts | 1 + .../app/services/matches/matches.service.ts | 5 +++- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/FencerJudgeFront/src/app/components/home/home.component.ts b/FencerJudgeFront/src/app/components/home/home.component.ts index d91de8e..c8bbe5c 100644 --- a/FencerJudgeFront/src/app/components/home/home.component.ts +++ b/FencerJudgeFront/src/app/components/home/home.component.ts @@ -59,8 +59,14 @@ export class HomeComponent implements OnInit, OnDestroy { this.loadRelatedEntities(this.latestMatch); - if (this.latestMatch.state === MatchState.NOT_STARTED) { - console.log(this.latestMatch.state); + const stateEnum = parseMatchState( + this.latestMatch.state as unknown as string + ); + + if (stateEnum !== undefined) { + this.latestMatch.state = stateEnum; // Remplacement par l'enum numérique + } else { + console.warn('État de match inconnu :', this.latestMatch.state); } if (this.latestMatch.state === MatchState.NOT_STARTED) { @@ -155,3 +161,7 @@ export class HomeComponent implements OnInit, OnDestroy { return this.timeUntilMatch; } } + +function parseMatchState(stateStr: string): MatchState | undefined { + return MatchState[stateStr as keyof typeof MatchState]; +} diff --git a/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.html b/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.html index 2f926a0..6ce2a75 100644 --- a/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.html +++ b/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.html @@ -29,7 +29,7 @@
diff --git a/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.ts b/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.ts index 483aaa1..f226bae 100644 --- a/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.ts +++ b/FencerJudgeFront/src/app/components/match/matches-id/matches-id.component.ts @@ -41,6 +41,16 @@ export class MatchesIdComponent implements OnInit { if (match) { this.match = match; + const stateEnum = parseMatchState( + this.match.state as unknown as string + ); + + if (stateEnum !== undefined) { + this.match.state = stateEnum; + } else { + console.warn('État de match inconnu :', this.match.state); + } + this.playerService.getPlayerById(match.player1ID).subscribe((res1) => { this.player1 = res1.data; }); @@ -66,8 +76,16 @@ export class MatchesIdComponent implements OnInit { saveScores(): void { if (this.match) { this.matchService.updateMatch(this.match.id, { + refereeID: this.match.refereeID, + player1ID: this.match.player1ID, score1: this.match.score1, + player2ID: this.match.player2ID, score2: this.match.score2, + country: this.match.country, + city: this.match.city, + weapon: this.match.weapon, + date: this.match.date, + state: this.match.state, }); } } @@ -87,11 +105,11 @@ export class MatchesIdComponent implements OnInit { getMatchStateColor(state: MatchState): string { switch (state) { - case MatchState.NOT_STARTED: + case 2: return 'secondary'; - case MatchState.ONGOING: + case 0: return 'warning'; - case MatchState.OVER: + case 1: return 'success'; default: return 'light'; @@ -157,3 +175,7 @@ export class MatchesIdComponent implements OnInit { ]); } } + +function parseMatchState(stateStr: string): MatchState | undefined { + return MatchState[stateStr as keyof typeof MatchState]; +} diff --git a/FencerJudgeFront/src/app/components/match/matches/matches.component.ts b/FencerJudgeFront/src/app/components/match/matches/matches.component.ts index 8e34052..37c2845 100644 --- a/FencerJudgeFront/src/app/components/match/matches/matches.component.ts +++ b/FencerJudgeFront/src/app/components/match/matches/matches.component.ts @@ -24,6 +24,10 @@ export class MatchesComponent { private router: Router ) {} + parseMatchState(stateStr: string): MatchState | undefined { + return MatchState[stateStr as keyof typeof MatchState]; + } + ngOnInit(): void { this.playerService.getPlayers().subscribe({ next: (response) => { @@ -45,6 +49,15 @@ export class MatchesComponent { next: (response) => { if (response) { this.matches = response; + this.matches = this.matches.map((match) => { + const enumState = this.parseMatchState( + match.state as unknown as string + ); + return { + ...match, + state: enumState !== undefined ? enumState : match.state, + }; + }); } else { console.warn( '[MatchesComponent] Erreur lors du chargement des matchs' diff --git a/FencerJudgeFront/src/app/services/api/api.service.ts b/FencerJudgeFront/src/app/services/api/api.service.ts index af70f6b..aaabcc7 100644 --- a/FencerJudgeFront/src/app/services/api/api.service.ts +++ b/FencerJudgeFront/src/app/services/api/api.service.ts @@ -28,6 +28,7 @@ export class ApiService { } put(endpoint: string, body: any): Observable> { + console.log(endpoint, body); return this.http .put>(`${this.baseUrl}/${endpoint}`, body) .pipe(catchError(this.handleError)); diff --git a/FencerJudgeFront/src/app/services/matches/matches.service.ts b/FencerJudgeFront/src/app/services/matches/matches.service.ts index fbd909f..e211967 100644 --- a/FencerJudgeFront/src/app/services/matches/matches.service.ts +++ b/FencerJudgeFront/src/app/services/matches/matches.service.ts @@ -32,7 +32,10 @@ export class MatchesService { updatedData: Partial ): Observable> { console.log(`[MatchesService] PUT update match ID: ${id}`, updatedData); - return this.api.put(`${this.endpoint}/${id}`, updatedData); + return this.api.put( + `${this.endpoint}/update-match/${id}`, + updatedData + ); } deleteMatch(id: number): Observable> {