From 5a73a70e0252b22c51b2a3a78e858d4ba25f9664 Mon Sep 17 00:00:00 2001
From: ExostFlash
Date: Mon, 2 Jun 2025 18:35:15 +0200
Subject: [PATCH] add Matches Add
---
.../src/app/app-routing.module.ts | 6 ++
FencerJudgeFront/src/app/app.module.ts | 2 +
.../essentials/footer/footer.component.html | 7 +-
.../essentials/header/header.component.html | 9 ++
.../matches-add/matches-add.component.css | 0
.../matches-add/matches-add.component.html | 1 +
.../matches-add/matches-add.component.spec.ts | 23 +++++
.../matches-add/matches-add.component.ts | 96 +++++++++++++++++++
.../match/matches-id/matches-id.component.ts | 2 +
.../app/services/matches/matches.service.ts | 12 +++
.../src/app/services/player/player.service.ts | 31 ++++++
.../app/services/referee/referee.service.ts | 31 ++++++
db.lock.db | 6 ++
13 files changed, 220 insertions(+), 6 deletions(-)
create mode 100644 FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.css
create mode 100644 FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.html
create mode 100644 FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.spec.ts
create mode 100644 FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.ts
create mode 100644 db.lock.db
diff --git a/FencerJudgeFront/src/app/app-routing.module.ts b/FencerJudgeFront/src/app/app-routing.module.ts
index b958478..a1cc001 100644
--- a/FencerJudgeFront/src/app/app-routing.module.ts
+++ b/FencerJudgeFront/src/app/app-routing.module.ts
@@ -10,6 +10,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';
const routes: Routes = [
{ path: 'login', component: LoginComponent },
@@ -19,6 +20,11 @@ const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'matches', component: MatchesComponent },
+ {
+ path: 'matches/add',
+ component: MatchesAddComponent,
+ canActivate: [authGuard],
+ },
{ path: 'matches/:id', component: MatchesIdComponent },
];
diff --git a/FencerJudgeFront/src/app/app.module.ts b/FencerJudgeFront/src/app/app.module.ts
index e17ffe8..f035f52 100644
--- a/FencerJudgeFront/src/app/app.module.ts
+++ b/FencerJudgeFront/src/app/app.module.ts
@@ -11,6 +11,7 @@ import { LoginComponent } from './components/essentials/login/login.component';
import { LogoutComponent } from './components/essentials/logout/logout.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';
@NgModule({
declarations: [
@@ -22,6 +23,7 @@ import { MatchesIdComponent } from './components/match/matches-id/matches-id.com
LogoutComponent,
MatchesComponent,
MatchesIdComponent,
+ MatchesAddComponent,
],
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 01eca56..86a3a7b 100644
--- a/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html
+++ b/FencerJudgeFront/src/app/components/essentials/footer/footer.component.html
@@ -47,12 +47,7 @@
-
© FencerJudge - Tous droits réservés
-
Mentions légales
-
Cookies
-
Accessibilité
-
Nous contacter
-
Presse
+
© FencerJudge - Tous droits réservés
diff --git a/FencerJudgeFront/src/app/components/essentials/header/header.component.html b/FencerJudgeFront/src/app/components/essentials/header/header.component.html
index d0e7a6f..c8ae8e8 100644
--- a/FencerJudgeFront/src/app/components/essentials/header/header.component.html
+++ b/FencerJudgeFront/src/app/components/essentials/header/header.component.html
@@ -21,6 +21,15 @@
Matchs
+
+
+ MatchAdd
+
+
matches-add works!
diff --git a/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.spec.ts b/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.spec.ts
new file mode 100644
index 0000000..5cd8289
--- /dev/null
+++ b/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.spec.ts
@@ -0,0 +1,23 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { MatchesAddComponent } from './matches-add.component';
+
+describe('MatchesAddComponent', () => {
+ let component: MatchesAddComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [MatchesAddComponent]
+ })
+ .compileComponents();
+
+ fixture = TestBed.createComponent(MatchesAddComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.ts b/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.ts
new file mode 100644
index 0000000..1de2680
--- /dev/null
+++ b/FencerJudgeFront/src/app/components/match/matches-add/matches-add.component.ts
@@ -0,0 +1,96 @@
+import { Component } from '@angular/core';
+import { Router } from '@angular/router';
+
+import { MatchesService } from '@services/matches/matches.service';
+import { MatchState } from '@interfaces/matches';
+
+import { PlayerService } from '@services/player/player.service';
+
+import { RefereeService } from '@services/referee/referee.service';
+import { Referee, RefereeLevel } from '@interfaces/referee';
+
+@Component({
+ selector: 'app-matches-add',
+ standalone: false,
+ templateUrl: './matches-add.component.html',
+ styleUrl: './matches-add.component.css',
+})
+export class MatchesAddComponent {
+ formData = {
+ player1Id: 0,
+ player1FirstName: '',
+ player1Name: '',
+ player1Club: '',
+
+ player2Id: 0,
+ player2FirstName: '',
+ player2Name: '',
+ player2Club: '',
+
+ refereeId: 0,
+ refereeFirstName: '',
+ refereeName: '',
+ refereelevel: 0,
+
+ city: '',
+ country: '',
+ date: '',
+ weapon: '',
+ };
+
+ constructor(
+ private matchService: MatchesService,
+ private playerService: PlayerService,
+ private refereeService: RefereeService,
+ private router: Router
+ ) {}
+
+ onSubmit(): void {
+ this.playerService
+ .getOrCreateByName(
+ this.formData.player1FirstName,
+ this.formData.player1Name,
+ this.formData.player1Club
+ )
+ .subscribe((player1) => {
+ this.formData['player1Id'] = player1.id;
+
+ this.playerService
+ .getOrCreateByName(
+ this.formData.player2FirstName,
+ this.formData.player2Name,
+ this.formData.player2Club
+ )
+ .subscribe((player2) => {
+ this.formData['player2Id'] = player2.id;
+
+ this.refereeService
+ .getOrCreateByName(
+ this.formData.refereeFirstName,
+ this.formData.refereeName,
+ this.formData.refereelevel
+ )
+ .subscribe((referee) => {
+ this.formData['refereeId'] = referee.id;
+
+ const matchPayload = {
+ refereeID: referee.id,
+ player1ID: player1.id,
+ score1: 0,
+ player2ID: player2.id,
+ score2: 0,
+ country: this.formData.country,
+ city: this.formData.city,
+ weapon: this.formData.weapon,
+ date: new Date(this.formData.date),
+ state: MatchState.NOT_STARTED,
+ };
+
+ this.matchService.create(matchPayload).subscribe(() => {
+ this.router.navigate(['/matches']);
+ });
+ });
+ });
+ });
+ }
+}
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 65d932b..7dbce17 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
@@ -4,8 +4,10 @@ import { AuthService } from '@services/auth/auth.service';
import { MatchesService } from '@services/matches/matches.service';
import { MatchState, Matches } from '@interfaces/matches';
+
import { PlayerService } from '@services/player/player.service';
import { Player } from '@interfaces/player';
+
import { RefereeService } from '@services/referee/referee.service';
import { Referee, RefereeLevel } from '@interfaces/referee';
diff --git a/FencerJudgeFront/src/app/services/matches/matches.service.ts b/FencerJudgeFront/src/app/services/matches/matches.service.ts
index fef45dd..58e004c 100644
--- a/FencerJudgeFront/src/app/services/matches/matches.service.ts
+++ b/FencerJudgeFront/src/app/services/matches/matches.service.ts
@@ -45,6 +45,7 @@ export class MatchesService {
state: MatchState.NOT_STARTED,
},
];
+ private nextId = 1;
constructor() {
console.log('[MatchesService] Initial matches loaded:', this.matches);
@@ -78,4 +79,15 @@ export class MatchesService {
console.warn(`[MatchesService] Match ${id} introuvable`);
}
}
+
+ create(match: Omit): Observable {
+ const newMatch: Matches = {
+ ...match,
+ id: this.nextId++,
+ };
+
+ this.matches.push(newMatch);
+ console.log('[MatchesService] Match created:', newMatch);
+ return of(newMatch);
+ }
}
diff --git a/FencerJudgeFront/src/app/services/player/player.service.ts b/FencerJudgeFront/src/app/services/player/player.service.ts
index 53d4350..c5f3a1b 100644
--- a/FencerJudgeFront/src/app/services/player/player.service.ts
+++ b/FencerJudgeFront/src/app/services/player/player.service.ts
@@ -27,4 +27,35 @@ export class PlayerService {
console.log(`[PlayerService] Fetching player ID: ${id}`, player);
return of(player);
}
+
+ getOrCreateByName(
+ firstName: string,
+ name: string,
+ club: string = 'Inconnu'
+ ): Observable {
+ const existing = this.players.find(
+ (p) =>
+ p.firstName.toLowerCase() === firstName.toLowerCase() &&
+ p.name.toLowerCase() === name.toLowerCase()
+ );
+
+ if (existing) {
+ console.log('[PlayerService] Joueur trouvé :', existing);
+ return of(existing);
+ }
+
+ const newPlayer: Player = {
+ id:
+ this.players.length > 0
+ ? Math.max(...this.players.map((p) => p.id)) + 1
+ : 1,
+ firstName,
+ name,
+ club,
+ };
+
+ this.players.push(newPlayer);
+ console.log('[PlayerService] Nouveau joueur créé :', newPlayer);
+ return of(newPlayer);
+ }
}
diff --git a/FencerJudgeFront/src/app/services/referee/referee.service.ts b/FencerJudgeFront/src/app/services/referee/referee.service.ts
index 6963230..8d26a06 100644
--- a/FencerJudgeFront/src/app/services/referee/referee.service.ts
+++ b/FencerJudgeFront/src/app/services/referee/referee.service.ts
@@ -39,4 +39,35 @@ export class RefereeService {
console.log(`[RefereeService] Fetching referee ID: ${id}`, ref);
return of(ref);
}
+
+ getOrCreateByName(
+ firstName: string,
+ name: string,
+ level: RefereeLevel
+ ): Observable {
+ const existing = this.referees.find(
+ (r) =>
+ r.firstName.toLowerCase() === firstName.toLowerCase() &&
+ r.name.toLowerCase() === name.toLowerCase()
+ );
+
+ if (existing) {
+ console.log('[RefereeService] Arbitre trouvé :', existing);
+ return of(existing);
+ }
+
+ const newPlayer: Referee = {
+ id:
+ this.referees.length > 0
+ ? Math.max(...this.referees.map((r) => r.id)) + 1
+ : 1,
+ firstName,
+ name,
+ level,
+ };
+
+ this.referees.push(newPlayer);
+ console.log('[RefereeService] Nouveau arbitre créé :', newPlayer);
+ return of(newPlayer);
+ }
}
diff --git a/db.lock.db b/db.lock.db
new file mode 100644
index 0000000..072e750
--- /dev/null
+++ b/db.lock.db
@@ -0,0 +1,6 @@
+#FileLock
+#Mon Jun 02 17:40:34 CEST 2025
+hostName=ExostFlash
+id=197313393c88a931fa21bf5ce1281b7253870b00683
+method=file
+server=192.167.2.100\:54366