41 lines
1.6 KiB
TypeScript
41 lines
1.6 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 All Page Query
|
|
*
|
|
* Fetches all races data for the all races page.
|
|
* Returns Result<RacesViewData, PresentationError>
|
|
*/
|
|
export class RacesAllPageQuery implements PageQuery<RacesViewData, void> {
|
|
async execute(): Promise<Result<RacesViewData, PresentationError>> {
|
|
try {
|
|
// Manual wiring: Service creates its own dependencies
|
|
const service = new RacesService();
|
|
|
|
// Get all races data
|
|
const result = await service.getAllRacesPageData();
|
|
|
|
if (result.isErr()) {
|
|
return Result.err(mapToPresentationError(result.getError()));
|
|
}
|
|
|
|
// Transform to ViewData using builder
|
|
const viewData = RacesViewDataBuilder.build(result.unwrap());
|
|
return Result.ok(viewData);
|
|
} catch (error: unknown) {
|
|
const message = error instanceof Error ? error.message : 'Failed to execute races all page query';
|
|
return Result.err(message as PresentationError);
|
|
}
|
|
}
|
|
|
|
// Static method to avoid object construction in server code
|
|
static async execute(): Promise<Result<RacesViewData, PresentationError>> {
|
|
const query = new RacesAllPageQuery();
|
|
return await query.execute();
|
|
}
|
|
} |