81 lines
3.3 KiB
TypeScript
81 lines
3.3 KiB
TypeScript
import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient';
|
|
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
|
|
*
|
|
* Returns raw API DTOs. No ViewModels or UX logic.
|
|
* All client-side presentation logic must be handled by hooks/components.
|
|
*/
|
|
export class ProtestService implements Service {
|
|
private readonly apiClient: ProtestsApiClient;
|
|
|
|
constructor() {
|
|
const baseUrl = getWebsiteApiBaseUrl();
|
|
const logger = new ConsoleLogger();
|
|
const errorReporter = new EnhancedErrorReporter(logger);
|
|
this.apiClient = new ProtestsApiClient(baseUrl, errorReporter, logger);
|
|
}
|
|
|
|
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 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 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 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 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' });
|
|
}
|
|
}
|
|
}
|