website refactor
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient';
|
||||
import type { ProtestViewModel } from '@/lib/view-models/ProtestViewModel';
|
||||
import type { RaceViewModel } from '@/lib/view-models/RaceViewModel';
|
||||
import type { ProtestDriverViewModel } from '@/lib/view-models/ProtestDriverViewModel';
|
||||
import type { ApplyPenaltyCommandDTO } from '@/lib/types/generated/ApplyPenaltyCommandDTO';
|
||||
import type { RequestProtestDefenseCommandDTO } from '@/lib/types/generated/RequestProtestDefenseCommandDTO';
|
||||
import type { ReviewProtestCommandDTO } from '@/lib/types/generated/ReviewProtestCommandDTO';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
|
||||
/**
|
||||
* Protest Service - DTO Only
|
||||
@@ -12,30 +14,67 @@ import type { ReviewProtestCommandDTO } from '@/lib/types/generated/ReviewProtes
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
*/
|
||||
export class ProtestService {
|
||||
constructor(private readonly apiClient: ProtestsApiClient) {}
|
||||
export class ProtestService implements Service {
|
||||
private readonly apiClient: ProtestsApiClient;
|
||||
|
||||
async getLeagueProtests(leagueId: string): Promise<any> {
|
||||
return this.apiClient.getLeagueProtests(leagueId);
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
this.apiClient = new ProtestsApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
|
||||
async getProtestById(leagueId: string, protestId: string): Promise<any> {
|
||||
return this.apiClient.getLeagueProtest(leagueId, protestId);
|
||||
async getLeagueProtests(leagueId: string): Promise<Result<unknown, DomainError>> {
|
||||
try {
|
||||
const data = await this.apiClient.getLeagueProtests(leagueId);
|
||||
return Result.ok(data);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get league protests' });
|
||||
}
|
||||
}
|
||||
|
||||
async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<void> {
|
||||
return this.apiClient.applyPenalty(input);
|
||||
async getProtestById(leagueId: string, protestId: string): Promise<Result<unknown, DomainError>> {
|
||||
try {
|
||||
const data = await this.apiClient.getLeagueProtest(leagueId, protestId);
|
||||
return Result.ok(data);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get protest' });
|
||||
}
|
||||
}
|
||||
|
||||
async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<void> {
|
||||
return this.apiClient.requestDefense(input);
|
||||
async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.applyPenalty(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to apply penalty' });
|
||||
}
|
||||
}
|
||||
|
||||
async reviewProtest(input: ReviewProtestCommandDTO): Promise<void> {
|
||||
return this.apiClient.reviewProtest(input);
|
||||
async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.requestDefense(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to request defense' });
|
||||
}
|
||||
}
|
||||
|
||||
async findByRaceId(raceId: string): Promise<any> {
|
||||
return this.apiClient.getRaceProtests(raceId);
|
||||
async reviewProtest(input: ReviewProtestCommandDTO): Promise<Result<void, DomainError>> {
|
||||
try {
|
||||
await this.apiClient.reviewProtest(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to review protest' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async findByRaceId(raceId: string): Promise<Result<unknown, DomainError>> {
|
||||
try {
|
||||
const data = await this.apiClient.getRaceProtests(raceId);
|
||||
return Result.ok(data);
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to find protests' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user