Merge pull request 'Add interfaces & services' (#4) from front/interfaces into feature/front

Reviewed-on: #4
This commit is contained in:
ExostFlash 2025-06-02 08:32:48 +00:00
commit 44269bed14
14 changed files with 248 additions and 6 deletions

View file

@ -4,7 +4,7 @@ import { Component } from '@angular/core';
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
standalone: false, standalone: false,
styleUrl: './app.component.css' styleUrl: './app.component.css',
}) })
export class AppComponent { export class AppComponent {
title = 'FencerJudgeFront'; title = 'FencerJudgeFront';

View file

@ -4,8 +4,6 @@ import { Component } from '@angular/core';
selector: 'app-header', selector: 'app-header',
standalone: false, standalone: false,
templateUrl: './header.component.html', templateUrl: './header.component.html',
styleUrl: './header.component.css' styleUrl: './header.component.css',
}) })
export class HeaderComponent { export class HeaderComponent {}
}

View file

@ -0,0 +1,19 @@
export enum MatchState {
ONGOING = 1,
OVER = 2,
NOT_STARTED = 3,
}
export interface Matches {
id: number;
refereeID: number;
player1ID: number;
score1: number;
player2ID: number;
score2: number;
country: String;
city: String;
weapon: String;
date: Date;
state: MatchState;
}

View file

@ -0,0 +1,5 @@
export interface UserModel {
id: number;
name: string;
firstName: string;
}

View file

@ -0,0 +1,5 @@
import { UserModel } from './models/user.model';
export interface Player extends UserModel {
club: string;
}

View file

@ -0,0 +1,12 @@
import { UserModel } from './models/user.model';
export enum RefereeLevel {
DEPARTMENTAL = 0,
REGIONAL = 1,
NATIONAL = 2,
INTERNATIONAL = 3,
}
export interface Referee extends UserModel {
level: RefereeLevel;
}

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { MatchesService } from './matches.service';
describe('MatchesService', () => {
let service: MatchesService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MatchesService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,71 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Matches, MatchState } from '@interfaces/matches';
@Injectable({ providedIn: 'root' })
export class MatchesService {
private matches: Matches[] = [
{
id: 1,
refereeID: 10,
player1ID: 1,
score1: 15,
player2ID: 2,
score2: 13,
country: 'France',
city: 'Paris',
weapon: 'Fleuret',
date: new Date('2025-06-10T14:00:00'),
state: MatchState.OVER,
},
{
id: 2,
refereeID: 11,
player1ID: 3,
score1: 5,
player2ID: 4,
score2: 7,
country: 'France',
city: 'Lyon',
weapon: 'Épée',
date: new Date('2025-06-15T10:00:00'),
state: MatchState.ONGOING,
},
{
id: 3,
refereeID: 12,
player1ID: 5,
score1: 0,
player2ID: 6,
score2: 0,
country: 'Belgique',
city: 'Bruxelles',
weapon: 'Sabre',
date: new Date('2025-06-20T16:30:00'),
state: MatchState.NOT_STARTED,
},
];
constructor() {
console.log('[MatchesService] Initial matches loaded:', this.matches);
}
getMatches(): Observable<Matches[]> {
console.log('[MatchesService] Fetching all matches');
return of(this.matches);
}
getMatchById(id: number): Observable<Matches | undefined> {
const match = this.matches.find((m) => m.id === id);
console.log(`[MatchesService] Fetching match ID: ${id}`, match);
return of(match);
}
// Préparation future pour WebSocket
connectToMatchUpdatesWebSocket(): void {
console.log(
'[MatchesService] WebSocket connection placeholder initialized'
);
// ici tu pourrais plus tard faire : this.socket = new WebSocket('ws://...') etc.
}
}

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { PlayerService } from './player.service';
describe('PlayerService', () => {
let service: PlayerService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(PlayerService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,30 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Player } from '@interfaces/player';
@Injectable({ providedIn: 'root' })
export class PlayerService {
private players: Player[] = [
{ id: 1, name: 'Martin', firstName: 'Alex', club: 'Lille Escrime' },
{ id: 2, name: 'Nguyen', firstName: 'Sophie', club: 'Paris Epée' },
{ id: 3, name: 'Klein', firstName: 'Thomas', club: 'Strasbourg Sabre' },
{ id: 4, name: 'Leclerc', firstName: 'Lucie', club: 'Nice Fleuret' },
{ id: 5, name: 'Dubois', firstName: 'Hugo', club: 'Lyon Epée' },
{ id: 6, name: 'Girard', firstName: 'Manon', club: 'Marseille Club' },
];
constructor() {
console.log('[PlayerService] Initial players loaded:', this.players);
}
getPlayers(): Observable<Player[]> {
console.log('[PlayerService] Fetching all players');
return of(this.players);
}
getPlayerById(id: number): Observable<Player | undefined> {
const player = this.players.find((p) => p.id === id);
console.log(`[PlayerService] Fetching player ID: ${id}`, player);
return of(player);
}
}

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { RefereeService } from './referee.service';
describe('RefereeService', () => {
let service: RefereeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(RefereeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,42 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Referee, RefereeLevel } from '@interfaces/referee';
@Injectable({ providedIn: 'root' })
export class RefereeService {
private referees: Referee[] = [
{
id: 10,
name: 'Durand',
firstName: 'Pierre',
level: RefereeLevel.NATIONAL,
},
{
id: 11,
name: 'Lemoine',
firstName: 'Anna',
level: RefereeLevel.REGIONAL,
},
{
id: 12,
name: 'Morel',
firstName: 'Lucas',
level: RefereeLevel.DEPARTMENTAL,
},
];
constructor() {
console.log('[RefereeService] Initial referees loaded:', this.referees);
}
getReferees(): Observable<Referee[]> {
console.log('[RefereeService] Fetching all referees');
return of(this.referees);
}
getRefereeById(id: number): Observable<Referee | undefined> {
const ref = this.referees.find((r) => r.id === id);
console.log(`[RefereeService] Fetching referee ID: ${id}`, ref);
return of(ref);
}
}

View file

@ -16,7 +16,13 @@
"moduleResolution": "bundler", "moduleResolution": "bundler",
"importHelpers": true, "importHelpers": true,
"target": "ES2022", "target": "ES2022",
"module": "ES2022" "module": "ES2022",
"baseUrl": "./src",
"paths": {
"@interfaces/*": ["app/interfaces/*"],
"@services/*": ["app/services/*"],
"@utils/*": ["app/utils/*"]
}
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false, "enableI18nLegacyMessageIdFormat": false,

6
package-lock.json generated Normal file
View file

@ -0,0 +1,6 @@
{
"name": "jpe-controle",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}