Sostituito frontend angular new con frontend angular. Sostituito frontend angular con frontend angular old

This commit is contained in:
Lorenzo Sanesi
2026-08-10 13:10:18 +02:00
parent 3d4eac4ea5
commit 0ed70eaa18
54 changed files with 7685 additions and 12730 deletions
@@ -0,0 +1,65 @@
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Bet, CreateBetRequest, UpdateBetRequest } from '../../models/bet.model';
import { SuccessResponse } from '../../models/api-responses.model';
import { map } from 'rxjs/operators';
import { toDate } from '../../utils/type-guards';
function mapBet(bet: any): Bet {
return {
...bet,
startDate: toDate(bet.startDate)!,
endDate: toDate(bet.endDate)
};
}
@Injectable({
providedIn: 'root'
})
export class BetApiService {
private http = inject(HttpClient);
private readonly apiUrl = 'http://localhost:3000/api/v1/bets';
getUserBets(): Observable<Bet[]> {
return this.http.get<SuccessResponse<Bet[]>>(`${this.apiUrl}/user`).pipe(
map(res => res.data.map(mapBet))
);
}
getPublicBets(): Observable<Bet[]> {
return this.http.get<SuccessResponse<Bet[]>>(`${this.apiUrl}/public`).pipe(
map(res => res.data.map(mapBet))
);
}
getBets(): Observable<Bet[]> {
return this.http.get<SuccessResponse<Bet[]>>(this.apiUrl).pipe(
map(res => res.data.map(mapBet))
);
}
getBet(id: string): Observable<Bet> {
return this.http.get<SuccessResponse<Bet>>(`${this.apiUrl}/${id}`).pipe(
map(res => mapBet(res.data))
);
}
createBet(bet: CreateBetRequest): Observable<Bet> {
return this.http.post<SuccessResponse<Bet>>(this.apiUrl, bet).pipe(
map(res => mapBet(res.data))
);
}
updateBet(id: string, bet: UpdateBetRequest): Observable<Bet> {
return this.http.put<SuccessResponse<Bet>>(`${this.apiUrl}/${id}`, bet).pipe(
map(res => mapBet(res.data))
);
}
deleteBet(id: string): Observable<void> {
return this.http.delete<SuccessResponse<null>>(`${this.apiUrl}/${id}`).pipe(
map(() => undefined)
);
}
}