31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
|
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
|
import { RacesViewData } from '@/lib/view-data/RacesViewData';
|
|
import { RacesService } from '@/lib/services/races/RacesService';
|
|
import { RacesViewDataBuilder } from '@/lib/builders/view-data/RacesViewDataBuilder';
|
|
|
|
/**
|
|
* Races Page Query
|
|
*
|
|
* Fetches races data for the main races page.
|
|
* Returns Result<RacesViewData, PresentationError>
|
|
*/
|
|
export class RacesPageQuery implements PageQuery<RacesViewData, void> {
|
|
async execute(): Promise<Result<RacesViewData, PresentationError>> {
|
|
// Manual wiring: Service creates its own dependencies
|
|
const service = new RacesService();
|
|
|
|
// Get races data
|
|
const result = await service.getRacesPageData();
|
|
|
|
if (result.isErr()) {
|
|
return Result.err(mapToPresentationError(result.getError()));
|
|
}
|
|
|
|
// Transform to ViewData using builder
|
|
const viewData = RacesViewDataBuilder.build(result.unwrap());
|
|
return Result.ok(viewData);
|
|
}
|
|
}
|