add Matches Add
This commit is contained in:
parent
05157e6d38
commit
5a73a70e02
13 changed files with 220 additions and 6 deletions
|
|
@ -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 },
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -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: [],
|
||||
|
|
|
|||
|
|
@ -47,12 +47,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="text-center mt-3">
|
||||
<span>© FencerJudge - Tous droits réservés </span>
|
||||
<a href="#" class="text-white me-3 SpaceMargin-02">Mentions légales</a>
|
||||
<a href="#" class="text-white me-3">Cookies</a>
|
||||
<a href="#" class="text-white me-3">Accessibilité</a>
|
||||
<a routerLink="/contact" class="text-white me-3">Nous contacter</a>
|
||||
<a routerLink="/blogs" class="text-white me-3">Presse</a>
|
||||
<span>© FencerJudge - Tous droits réservés</span>
|
||||
</div>
|
||||
<div class="flag-bar" title="France"></div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,15 @@
|
|||
Matchs
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item" *ngIf="authService.isAuthenticated()">
|
||||
<a
|
||||
class="nav-link"
|
||||
routerLink="/matches/add"
|
||||
routerLinkActive="active-link"
|
||||
>
|
||||
MatchAdd
|
||||
</a>
|
||||
</li>
|
||||
<li
|
||||
class="nav-item"
|
||||
*ngIf="authService.isAuthenticated(); else notLoggedIn"
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<p>matches-add works!</p>
|
||||
|
|
@ -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<MatchesAddComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [MatchesAddComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(MatchesAddComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -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']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Matches, 'id'>): Observable<Matches> {
|
||||
const newMatch: Matches = {
|
||||
...match,
|
||||
id: this.nextId++,
|
||||
};
|
||||
|
||||
this.matches.push(newMatch);
|
||||
console.log('[MatchesService] Match created:', newMatch);
|
||||
return of(newMatch);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Player> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Referee> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
db.lock.db
Normal file
6
db.lock.db
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue