This commit is contained in:
2025-08-26 16:28:27 +03:00
parent ef93d51f77
commit 6e5b89469f
14 changed files with 218 additions and 47 deletions

View File

@@ -42,5 +42,12 @@ export class CandidateDataService {
);
}
deleteCandidate(id: number) {
return this.httpClient.delete(`${environment.hostUrl}/app/candidate/${id}`).pipe(
tap(() => {
this.cachedApplicationList = this.cachedApplicationList.filter(c => c.id !== id);
})
);
}
}

View File

@@ -25,10 +25,27 @@ export class SocketIOService {
});
}
disconnect() {
this.socket.disconnect();
onCandidateDeleted(): Observable<any> {
return new Observable(observer => {
this.socket.on('candidateDeleted', (data) => {
observer.next(data);
});
});
}
onStatsUpdated(): Observable<any> {
return new Observable(observer => {
this.socket.on('statsUpdated', (data) => {
observer.next(data);
});
});
}
// disconnect() {
// this.socket.disconnect();
// }
}

View File

@@ -0,0 +1,36 @@
import { Injectable, signal, effect, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { SocketIOService } from './socket-io.service';
import { environment } from '../../environments/environment';
@Injectable({ providedIn: 'root' })
export class StatsService {
http = inject(HttpClient);
socket = inject(SocketIOService);
totalVisits = signal(0);
totalClicks = signal(0);
private socketEffect = effect(() => {
this.socket.onStatsUpdated().subscribe(stats => {
this.totalVisits.set(stats.totalVisits);
this.totalClicks.set(stats.totalClicks);
});
});
loadInitial() {
this.http.get<any>(`${environment.hostUrl}/stats`).subscribe(stats => {
this.totalVisits.set(stats.totalVisits);
this.totalClicks.set(stats.totalClicks);
});
}
incrementVisit() {
return this.http.post(`${environment.hostUrl}/stats/visit`, {});
}
incrementClick() {
return this.http.post(`${environment.hostUrl}/stats/click`, {});
}
}