Add match-del & button del, fix services

This commit is contained in:
ExostFlash 2025-06-02 22:18:29 +02:00
parent 79413081bd
commit 09dbb30611
10 changed files with 100 additions and 12 deletions

View file

@ -11,6 +11,7 @@ import { HomeComponent } from './components/home/home.component';
import { MatchesComponent } from './components/match/matches/matches.component'; import { MatchesComponent } from './components/match/matches/matches.component';
import { MatchesIdComponent } from './components/match/matches-id/matches-id.component'; import { MatchesIdComponent } from './components/match/matches-id/matches-id.component';
import { MatchesAddComponent } from './components/match/matches-add/matches-add.component'; import { MatchesAddComponent } from './components/match/matches-add/matches-add.component';
import { MatchesDelComponent } from './components/match/matches-del/matches-del.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'login', component: LoginComponent }, { path: 'login', component: LoginComponent },
@ -25,6 +26,11 @@ const routes: Routes = [
component: MatchesAddComponent, component: MatchesAddComponent,
canActivate: [authGuard], canActivate: [authGuard],
}, },
{
path: 'matches/del/:id',
component: MatchesDelComponent,
canActivate: [authGuard],
},
{ path: 'matches/:id', component: MatchesIdComponent }, { path: 'matches/:id', component: MatchesIdComponent },
]; ];

View file

@ -13,6 +13,7 @@ import { MatchesComponent } from './components/match/matches/matches.component';
import { MatchesIdComponent } from './components/match/matches-id/matches-id.component'; import { MatchesIdComponent } from './components/match/matches-id/matches-id.component';
import { MatchesAddComponent } from './components/match/matches-add/matches-add.component'; import { MatchesAddComponent } from './components/match/matches-add/matches-add.component';
import { SponsortComponent } from './templates/sponsort/sponsort.component'; import { SponsortComponent } from './templates/sponsort/sponsort.component';
import { MatchesDelComponent } from './components/match/matches-del/matches-del.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -26,6 +27,7 @@ import { SponsortComponent } from './templates/sponsort/sponsort.component';
MatchesIdComponent, MatchesIdComponent,
MatchesAddComponent, MatchesAddComponent,
SponsortComponent, SponsortComponent,
MatchesDelComponent,
], ],
imports: [BrowserModule, AppRoutingModule, FormsModule], imports: [BrowserModule, AppRoutingModule, FormsModule],
providers: [], providers: [],

View file

@ -15,31 +15,25 @@
> >
<span class="me-3">Suivez-nous</span> <span class="me-3">Suivez-nous</span>
<a <a
href="#" href="https://x.com/ffescrime"
class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2"
style="width: 40px; height: 40px"
><i class="bi bi-rss text-dark"></i
></a>
<a
href="#"
class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2" class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2"
style="width: 40px; height: 40px" style="width: 40px; height: 40px"
><i class="bi bi-twitter-x text-dark"></i ><i class="bi bi-twitter-x text-dark"></i
></a> ></a>
<a <a
href="#" href="https://www.facebook.com/ffescrime/"
class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2" class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2"
style="width: 40px; height: 40px" style="width: 40px; height: 40px"
><i class="bi bi-facebook text-dark"></i ><i class="bi bi-facebook text-dark"></i
></a> ></a>
<a <a
href="#" href="https://www.youtube.com/channel/UCSjeeZaP92mdOICSXsaGdiw"
class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2" class="text-white me-2 d-flex align-items-center justify-content-center rounded-circle bg-light p-2"
style="width: 40px; height: 40px" style="width: 40px; height: 40px"
><i class="bi bi-youtube text-dark"></i ><i class="bi bi-youtube text-dark"></i
></a> ></a>
<a <a
href="#" href="https://www.linkedin.com/company/ffescrime/"
class="text-white d-flex align-items-center justify-content-center rounded-circle bg-light p-2" class="text-white d-flex align-items-center justify-content-center rounded-circle bg-light p-2"
style="width: 40px; height: 40px" style="width: 40px; height: 40px"
><i class="bi bi-linkedin text-dark"></i ><i class="bi bi-linkedin text-dark"></i

View file

@ -0,0 +1 @@
<p>matches-del works!</p>

View file

@ -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<MatchesDelComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MatchesDelComponent]
})
.compileComponents();
fixture = TestBed.createComponent(MatchesDelComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -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');
}
}
}

View file

@ -92,3 +92,5 @@
<div class="container my-5 text-center text-danger" *ngIf="!match"> <div class="container my-5 text-center text-danger" *ngIf="!match">
<p>Match non trouvé.</p> <p>Match non trouvé.</p>
</div> </div>
<a (click)="goToMatchDel()" *ngIf="authService.isAuthenticated()">Delete</a>

View file

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core'; 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 { AuthService } from '@services/auth/auth.service';
import { MatchesService } from '@services/matches/matches.service'; import { MatchesService } from '@services/matches/matches.service';
@ -28,7 +28,8 @@ export class MatchesIdComponent implements OnInit {
private matchService: MatchesService, private matchService: MatchesService,
private playerService: PlayerService, private playerService: PlayerService,
private refereeService: RefereeService, private refereeService: RefereeService,
public authService: AuthService public authService: AuthService,
private router: Router
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -140,4 +141,11 @@ export class MatchesIdComponent implements OnInit {
this.updateScores(); this.updateScores();
} }
goToMatchDel(): void {
this.router.navigate([
'/matches/del/',
this.route.snapshot.paramMap.get('id'),
]);
}
} }

View file

@ -90,4 +90,18 @@ export class MatchesService {
console.log('[MatchesService] Match created:', newMatch); console.log('[MatchesService] Match created:', newMatch);
return of(newMatch); return of(newMatch);
} }
deleteMatch(id: number): Observable<boolean> {
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);
}
}
} }