modif api
This commit is contained in:
parent
e061b9d1c0
commit
fe5212bd97
6 changed files with 56 additions and 7 deletions
|
|
@ -59,8 +59,14 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.loadRelatedEntities(this.latestMatch);
|
this.loadRelatedEntities(this.latestMatch);
|
||||||
|
|
||||||
if (this.latestMatch.state === MatchState.NOT_STARTED) {
|
const stateEnum = parseMatchState(
|
||||||
console.log(this.latestMatch.state);
|
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) {
|
if (this.latestMatch.state === MatchState.NOT_STARTED) {
|
||||||
|
|
@ -155,3 +161,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||||
return this.timeUntilMatch;
|
return this.timeUntilMatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseMatchState(stateStr: string): MatchState | undefined {
|
||||||
|
return MatchState[stateStr as keyof typeof MatchState];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<ng-container
|
<ng-container
|
||||||
*ngIf="
|
*ngIf="
|
||||||
authService.isAuthenticated() && match.state != 2;
|
authService.isAuthenticated() && match.state != 1;
|
||||||
else displayScores
|
else displayScores
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,16 @@ export class MatchesIdComponent implements OnInit {
|
||||||
if (match) {
|
if (match) {
|
||||||
this.match = 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.playerService.getPlayerById(match.player1ID).subscribe((res1) => {
|
||||||
this.player1 = res1.data;
|
this.player1 = res1.data;
|
||||||
});
|
});
|
||||||
|
|
@ -66,8 +76,16 @@ export class MatchesIdComponent implements OnInit {
|
||||||
saveScores(): void {
|
saveScores(): void {
|
||||||
if (this.match) {
|
if (this.match) {
|
||||||
this.matchService.updateMatch(this.match.id, {
|
this.matchService.updateMatch(this.match.id, {
|
||||||
|
refereeID: this.match.refereeID,
|
||||||
|
player1ID: this.match.player1ID,
|
||||||
score1: this.match.score1,
|
score1: this.match.score1,
|
||||||
|
player2ID: this.match.player2ID,
|
||||||
score2: this.match.score2,
|
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 {
|
getMatchStateColor(state: MatchState): string {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case MatchState.NOT_STARTED:
|
case 2:
|
||||||
return 'secondary';
|
return 'secondary';
|
||||||
case MatchState.ONGOING:
|
case 0:
|
||||||
return 'warning';
|
return 'warning';
|
||||||
case MatchState.OVER:
|
case 1:
|
||||||
return 'success';
|
return 'success';
|
||||||
default:
|
default:
|
||||||
return 'light';
|
return 'light';
|
||||||
|
|
@ -157,3 +175,7 @@ export class MatchesIdComponent implements OnInit {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseMatchState(stateStr: string): MatchState | undefined {
|
||||||
|
return MatchState[stateStr as keyof typeof MatchState];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ export class MatchesComponent {
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
parseMatchState(stateStr: string): MatchState | undefined {
|
||||||
|
return MatchState[stateStr as keyof typeof MatchState];
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.playerService.getPlayers().subscribe({
|
this.playerService.getPlayers().subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
|
|
@ -45,6 +49,15 @@ export class MatchesComponent {
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
this.matches = 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 {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
'[MatchesComponent] Erreur lors du chargement des matchs'
|
'[MatchesComponent] Erreur lors du chargement des matchs'
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ export class ApiService {
|
||||||
}
|
}
|
||||||
|
|
||||||
put<T>(endpoint: string, body: any): Observable<ApiResponse<T>> {
|
put<T>(endpoint: string, body: any): Observable<ApiResponse<T>> {
|
||||||
|
console.log(endpoint, body);
|
||||||
return this.http
|
return this.http
|
||||||
.put<ApiResponse<T>>(`${this.baseUrl}/${endpoint}`, body)
|
.put<ApiResponse<T>>(`${this.baseUrl}/${endpoint}`, body)
|
||||||
.pipe(catchError(this.handleError));
|
.pipe(catchError(this.handleError));
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,10 @@ export class MatchesService {
|
||||||
updatedData: Partial<Matches>
|
updatedData: Partial<Matches>
|
||||||
): Observable<ApiResponse<Matches>> {
|
): Observable<ApiResponse<Matches>> {
|
||||||
console.log(`[MatchesService] PUT update match ID: ${id}`, updatedData);
|
console.log(`[MatchesService] PUT update match ID: ${id}`, updatedData);
|
||||||
return this.api.put<Matches>(`${this.endpoint}/${id}`, updatedData);
|
return this.api.put<Matches>(
|
||||||
|
`${this.endpoint}/update-match/${id}`,
|
||||||
|
updatedData
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMatch(id: number): Observable<ApiResponse<boolean>> {
|
deleteMatch(id: number): Observable<ApiResponse<boolean>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue