website refactor

This commit is contained in:
2026-01-14 10:51:05 +01:00
parent 4522d41aef
commit 0d89ad027e
291 changed files with 6887 additions and 3685 deletions

View File

@@ -1,13 +1,87 @@
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
import { Result } from '@/lib/contracts/Result';
import { DomainError } from '@/lib/contracts/services/Service';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { ApiError } from '@/lib/api/base/ApiError';
/**
* Race Results Service - DTO Only
*
* Race Results Service
*
* Orchestration service for race results operations.
* Returns raw API DTOs. No ViewModels or UX logic.
* All client-side presentation logic must be handled by hooks/components.
*/
export class RaceResultsService {
constructor(private readonly apiClient: any) {}
private apiClient: RacesApiClient;
async getRaceResults(raceId: string): Promise<any> {
return { raceId, results: [] };
constructor() {
// Service creates its own dependencies
const baseUrl = getWebsiteApiBaseUrl();
const logger = new ConsoleLogger();
const errorReporter = new ConsoleErrorReporter();
this.apiClient = new RacesApiClient(baseUrl, errorReporter, logger);
}
/**
* Get race results detail
* Returns results for a specific race
*/
async getRaceResultsDetail(raceId: string): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getResultsDetail(raceId);
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch race results'
});
}
}
/**
* Get race with strength of field
* Returns race data with SOF calculation
*/
async getWithSOF(raceId: string): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getWithSOF(raceId);
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch race SOF'
});
}
}
private mapApiErrorType(apiErrorType: string): DomainError['type'] {
switch (apiErrorType) {
case 'NOT_FOUND':
return 'notFound';
case 'AUTH_ERROR':
return 'unauthorized';
case 'VALIDATION_ERROR':
return 'validation';
case 'SERVER_ERROR':
return 'serverError';
case 'NETWORK_ERROR':
return 'networkError';
default:
return 'unknown';
}
}
}

View File

@@ -17,4 +17,9 @@ export class RaceService {
async getRacesByLeagueId(leagueId: string): Promise<any> {
return this.apiClient.getPageData(leagueId);
}
async findByLeagueId(leagueId: string): Promise<any[]> {
const result = await this.apiClient.getPageData(leagueId);
return result.races || [];
}
}

View File

@@ -1,13 +1,110 @@
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient';
import { PenaltiesApiClient } from '@/lib/api/penalties/PenaltiesApiClient';
import { Result } from '@/lib/contracts/Result';
import { DomainError } from '@/lib/contracts/services/Service';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { ApiError } from '@/lib/api/base/ApiError';
/**
* Race Stewarding Service - DTO Only
*
* Race Stewarding Service
*
* Orchestration service for race stewarding operations.
* Returns raw API DTOs. No ViewModels or UX logic.
* All client-side presentation logic must be handled by hooks/components.
*/
export class RaceStewardingService {
constructor(private readonly raceApiClient: any, private readonly protestApiClient: any, private readonly penaltyApiClient: any) {}
private racesApiClient: RacesApiClient;
private protestsApiClient: ProtestsApiClient;
private penaltiesApiClient: PenaltiesApiClient;
async getRaceStewarding(raceId: string): Promise<any> {
return { raceId, protests: [], penalties: [] };
constructor() {
// Service creates its own dependencies
const baseUrl = getWebsiteApiBaseUrl();
const logger = new ConsoleLogger();
const errorReporter = new ConsoleErrorReporter();
this.racesApiClient = new RacesApiClient(baseUrl, errorReporter, logger);
this.protestsApiClient = new ProtestsApiClient(baseUrl, errorReporter, logger);
this.penaltiesApiClient = new PenaltiesApiClient(baseUrl, errorReporter, logger);
}
/**
* Get race stewarding data
* Returns protests and penalties for a race
*/
async getRaceStewarding(raceId: string): Promise<Result<any, DomainError>> {
try {
// Fetch data in parallel
const [raceDetail, protests, penalties] = await Promise.all([
this.racesApiClient.getDetail(raceId, ''),
this.protestsApiClient.getRaceProtests(raceId),
this.penaltiesApiClient.getRacePenalties(raceId),
]);
// Transform data to match view model structure
const protestsData = protests.protests.map((p: any) => ({
id: p.id,
protestingDriverId: p.protestingDriverId,
accusedDriverId: p.accusedDriverId,
incident: {
lap: p.lap,
description: p.description,
},
filedAt: p.filedAt,
status: p.status,
}));
const pendingProtests = protestsData.filter((p: any) => p.status === 'pending' || p.status === 'under_review');
const resolvedProtests = protestsData.filter((p: any) =>
p.status === 'upheld' ||
p.status === 'dismissed' ||
p.status === 'withdrawn'
);
const data = {
race: raceDetail.race,
league: raceDetail.league,
protests: protestsData,
penalties: penalties.penalties,
driverMap: { ...protests.driverMap, ...penalties.driverMap },
pendingProtests,
resolvedProtests,
pendingCount: pendingProtests.length,
resolvedCount: resolvedProtests.length,
penaltiesCount: penalties.penalties.length,
};
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch stewarding data'
});
}
}
private mapApiErrorType(apiErrorType: string): DomainError['type'] {
switch (apiErrorType) {
case 'NOT_FOUND':
return 'notFound';
case 'AUTH_ERROR':
return 'unauthorized';
case 'VALIDATION_ERROR':
return 'validation';
case 'SERVER_ERROR':
return 'serverError';
case 'NETWORK_ERROR':
return 'networkError';
default:
return 'unknown';
}
}
}

View File

@@ -0,0 +1,153 @@
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
import { Result } from '@/lib/contracts/Result';
import { DomainError } from '@/lib/contracts/services/Service';
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { ApiError } from '@/lib/api/base/ApiError';
/**
* Races Service
*
* Orchestration service for race-related operations.
* Returns raw API DTOs. No ViewModels or UX logic.
*/
export class RacesService {
private apiClient: RacesApiClient;
constructor() {
// Service creates its own dependencies
const baseUrl = getWebsiteApiBaseUrl();
const logger = new ConsoleLogger();
const errorReporter = new ConsoleErrorReporter();
this.apiClient = new RacesApiClient(baseUrl, errorReporter, logger);
}
/**
* Get races page data
* Returns races for the main races page
*/
async getRacesPageData(): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getPageData();
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch races page data'
});
}
}
/**
* Get race detail
* Returns detailed information for a specific race
*/
async getRaceDetail(raceId: string, driverId: string): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getDetail(raceId, driverId);
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch race detail'
});
}
}
/**
* Get race results detail
* Returns results for a specific race
*/
async getRaceResultsDetail(raceId: string): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getResultsDetail(raceId);
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch race results'
});
}
}
/**
* Get race with strength of field
* Returns race data with SOF calculation
*/
async getRaceWithSOF(raceId: string): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getWithSOF(raceId);
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch race SOF'
});
}
}
/**
* Get all races for the all races page
* Returns all races with pagination support
*/
async getAllRacesPageData(): Promise<Result<any, DomainError>> {
try {
const data = await this.apiClient.getPageData();
return Result.ok(data);
} catch (error) {
if (error instanceof ApiError) {
return Result.err({
type: this.mapApiErrorType(error.type),
message: error.message
});
}
return Result.err({
type: 'unknown',
message: 'Failed to fetch all races'
});
}
}
private mapApiErrorType(apiErrorType: string): DomainError['type'] {
switch (apiErrorType) {
case 'NOT_FOUND':
return 'notFound';
case 'AUTH_ERROR':
return 'unauthorized';
case 'VALIDATION_ERROR':
return 'validation';
case 'SERVER_ERROR':
return 'serverError';
case 'NETWORK_ERROR':
return 'networkError';
default:
return 'unknown';
}
}
}