website refactor
This commit is contained in:
@@ -1,39 +1,45 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { Service, DomainError } from '@/lib/contracts/services/Service';
|
||||
import { LeagueScheduleApiDto } from '@/lib/types/tbd/LeagueScheduleApiDto';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
|
||||
export class LeagueScheduleService implements Service {
|
||||
private apiClient: LeaguesApiClient;
|
||||
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
this.apiClient = new LeaguesApiClient(
|
||||
baseUrl,
|
||||
new ConsoleErrorReporter(),
|
||||
new ConsoleLogger()
|
||||
);
|
||||
}
|
||||
|
||||
async getScheduleData(leagueId: string): Promise<Result<LeagueScheduleApiDto, DomainError>> {
|
||||
// Mock data since backend not implemented
|
||||
const mockData: LeagueScheduleApiDto = {
|
||||
leagueId,
|
||||
races: [
|
||||
{
|
||||
id: 'race-1',
|
||||
name: 'Round 1 - Monza',
|
||||
date: '2024-10-15T14:00:00Z',
|
||||
track: 'Monza Circuit',
|
||||
car: 'Ferrari SF90',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
{
|
||||
id: 'race-2',
|
||||
name: 'Round 2 - Silverstone',
|
||||
date: '2024-10-22T13:00:00Z',
|
||||
track: 'Silverstone Circuit',
|
||||
car: 'Mercedes W10',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
{
|
||||
id: 'race-3',
|
||||
name: 'Round 3 - Spa-Francorchamps',
|
||||
date: '2024-10-29T12:00:00Z',
|
||||
track: 'Circuit de Spa-Francorchamps',
|
||||
car: 'Red Bull RB15',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
],
|
||||
};
|
||||
return Result.ok(mockData);
|
||||
try {
|
||||
const data = await this.apiClient.getSchedule(leagueId);
|
||||
|
||||
// Map LeagueScheduleDTO to LeagueScheduleApiDto
|
||||
const apiDto: LeagueScheduleApiDto = {
|
||||
leagueId,
|
||||
races: data.races.map(race => ({
|
||||
id: race.id,
|
||||
name: race.name,
|
||||
date: race.date,
|
||||
track: (race as any).track || 'TBA',
|
||||
car: (race as any).car || 'TBA',
|
||||
sessionType: (race as any).sessionType || 'Race',
|
||||
status: (race as any).status || 'scheduled',
|
||||
strengthOfField: (race as any).strengthOfField,
|
||||
})),
|
||||
};
|
||||
|
||||
return Result.ok(apiDto);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to fetch schedule' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user