From 09dbb30611db96e371a0e34ce5376324d396e9f5 Mon Sep 17 00:00:00 2001
From: ExostFlash
Date: Mon, 2 Jun 2025 22:18:29 +0200
Subject: [PATCH] Add match-del & button del, fix services
---
.../src/app/app-routing.module.ts | 6 +++
FencerJudgeFront/src/app/app.module.ts | 2 +
.../essentials/footer/footer.component.html | 14 ++-----
.../matches-del/matches-del.component.css | 0
.../matches-del/matches-del.component.html | 1 +
.../matches-del/matches-del.component.spec.ts | 23 +++++++++++
.../matches-del/matches-del.component.ts | 38 +++++++++++++++++++
.../matches-id/matches-id.component.html | 2 +
.../match/matches-id/matches-id.component.ts | 12 +++++-
.../app/services/matches/matches.service.ts | 14 +++++++
10 files changed, 100 insertions(+), 12 deletions(-)
create mode 100644 FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.css
create mode 100644 FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.html
create mode 100644 FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.spec.ts
create mode 100644 FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.ts
diff --git a/FencerJudgeFront/src/app/app-routing.module.ts b/FencerJudgeFront/src/app/app-routing.module.ts
index a1cc001..0440f68 100644
--- a/FencerJudgeFront/src/app/app-routing.module.ts
+++ b/FencerJudgeFront/src/app/app-routing.module.ts
@@ -11,6 +11,7 @@ import { HomeComponent } from './components/home/home.component';
import { MatchesComponent } from './components/match/matches/matches.component';
import { MatchesIdComponent } from './components/match/matches-id/matches-id.component';
import { MatchesAddComponent } from './components/match/matches-add/matches-add.component';
+import { MatchesDelComponent } from './components/match/matches-del/matches-del.component';
const routes: Routes = [
{ path: 'login', component: LoginComponent },
@@ -25,6 +26,11 @@ const routes: Routes = [
component: MatchesAddComponent,
canActivate: [authGuard],
},
+ {
+ path: 'matches/del/:id',
+ component: MatchesDelComponent,
+ canActivate: [authGuard],
+ },
{ path: 'matches/:id', component: MatchesIdComponent },
];
diff --git a/FencerJudgeFront/src/app/app.module.ts b/FencerJudgeFront/src/app/app.module.ts
index e3032f2..4490d31 100644
--- a/FencerJudgeFront/src/app/app.module.ts
+++ b/FencerJudgeFront/src/app/app.module.ts
@@ -13,6 +13,7 @@ import { MatchesComponent } from './components/match/matches/matches.component';
import { MatchesIdComponent } from './components/match/matches-id/matches-id.component';
import { MatchesAddComponent } from './components/match/matches-add/matches-add.component';
import { SponsortComponent } from './templates/sponsort/sponsort.component';
+import { MatchesDelComponent } from './components/match/matches-del/matches-del.component';
@NgModule({
declarations: [
@@ -26,6 +27,7 @@ import { SponsortComponent } from './templates/sponsort/sponsort.component';
MatchesIdComponent,
MatchesAddComponent,
SponsortComponent,
+ MatchesDelComponent,
],
imports: [BrowserModule, AppRoutingModule, FormsModule],
providers: [],
diff --git a/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html b/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html
index 86a3a7b..a110ff8 100644
--- a/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html
+++ b/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html
@@ -15,31 +15,25 @@
>
Suivez-nous
-
matches-del works!
diff --git a/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.spec.ts b/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.spec.ts
new file mode 100644
index 0000000..29459b8
--- /dev/null
+++ b/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.spec.ts
@@ -0,0 +1,23 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { MatchesDelComponent } from './matches-del.component';
+
+describe('MatchesDelComponent', () => {
+ let component: MatchesDelComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [MatchesDelComponent]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(MatchesDelComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.ts b/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.ts
new file mode 100644
index 0000000..b3b9bd4
--- /dev/null
+++ b/FencerJudgeFront/src/app/components/match/matches-del/matches-del.component.ts
@@ -0,0 +1,38 @@
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute, Router } from '@angular/router';
+
+import { AuthService } from '@services/auth/auth.service';
+import { MatchesService } from '@services/matches/matches.service';
+
+@Component({
+ selector: 'app-matches-del',
+ standalone: false,
+ templateUrl: './matches-del.component.html',
+ styleUrl: './matches-del.component.css',
+})
+export class MatchesDelComponent {
+ constructor(
+ private route: ActivatedRoute,
+ public authService: AuthService,
+ private router: Router,
+ private matchService: MatchesService
+ ) {}
+
+ ngOnInit(): void {
+ const id = Number(this.route.snapshot.paramMap.get('id'));
+
+ if (!isNaN(id)) {
+ this.matchService.deleteMatch(id).subscribe({
+ next: () => {
+ console.log(`Match ${id} supprimé`);
+ this.router.navigate(['/matches']); // redirection après suppression
+ },
+ error: (err) => {
+ console.error('Erreur lors de la suppression :', err);
+ },
+ });
+ } else {
+ console.error('ID de match invalide');
+ }
+ }
+}
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 3e82262..2f926a0 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
@@ -92,3 +92,5 @@
+
+Delete
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 7dbce17..7430beb 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
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
+import { Router, ActivatedRoute } from '@angular/router';
import { AuthService } from '@services/auth/auth.service';
import { MatchesService } from '@services/matches/matches.service';
@@ -28,7 +28,8 @@ export class MatchesIdComponent implements OnInit {
private matchService: MatchesService,
private playerService: PlayerService,
private refereeService: RefereeService,
- public authService: AuthService
+ public authService: AuthService,
+ private router: Router
) {}
ngOnInit(): void {
@@ -140,4 +141,11 @@ export class MatchesIdComponent implements OnInit {
this.updateScores();
}
+
+ goToMatchDel(): void {
+ this.router.navigate([
+ '/matches/del/',
+ this.route.snapshot.paramMap.get('id'),
+ ]);
+ }
}
diff --git a/FencerJudgeFront/src/app/services/matches/matches.service.ts b/FencerJudgeFront/src/app/services/matches/matches.service.ts
index 9e00fca..bbffd36 100644
--- a/FencerJudgeFront/src/app/services/matches/matches.service.ts
+++ b/FencerJudgeFront/src/app/services/matches/matches.service.ts
@@ -90,4 +90,18 @@ export class MatchesService {
console.log('[MatchesService] Match created:', newMatch);
return of(newMatch);
}
+
+ deleteMatch(id: number): Observable {
+ const index = this.matches.findIndex((m) => m.id === id);
+
+ if (index !== -1) {
+ const deletedMatch = this.matches.splice(index, 1)[0];
+ console.log(`[MatchesService] Match ${id} supprimé :`, deletedMatch);
+
+ return of(true);
+ } else {
+ console.warn(`[MatchesService] Match ${id} introuvable pour suppression`);
+ return of(false);
+ }
+ }
}