Initial commit

This commit is contained in:
Lorenzo Sanesi
2026-03-26 22:57:02 +01:00
parent 18e0e04700
commit 8752acd2c4
44 changed files with 10272 additions and 0 deletions
@@ -0,0 +1,53 @@
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';
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)
);
}
}