website refactor
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user