view models
This commit is contained in:
@@ -1,34 +1,35 @@
|
||||
import { RacesApiClient } from '../../api/races/RacesApiClient';
|
||||
import { RaceDetailPresenter } from '../../presenters/RaceDetailPresenter';
|
||||
import type { RaceDetailViewModel } from '../../view-models/RaceDetailViewModel';
|
||||
import type { RacesPageDataDto, RaceStatsDto } from '../../dtos';
|
||||
import { RaceDetailViewModel } from '../../view-models/RaceDetailViewModel';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type RacesPageDataDto = { races: Array<any> };
|
||||
type RaceStatsDto = { totalRaces: number };
|
||||
|
||||
/**
|
||||
* Race Service
|
||||
*
|
||||
* Orchestrates race operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates race operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class RaceService {
|
||||
constructor(
|
||||
private readonly apiClient: RacesApiClient,
|
||||
private readonly raceDetailPresenter: RaceDetailPresenter
|
||||
private readonly apiClient: RacesApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get race detail with presentation transformation
|
||||
* Get race detail with view model transformation
|
||||
*/
|
||||
async getRaceDetail(
|
||||
raceId: string,
|
||||
driverId: string
|
||||
): Promise<RaceDetailViewModel> {
|
||||
const dto = await this.apiClient.getDetail(raceId, driverId);
|
||||
return this.raceDetailPresenter.present(dto);
|
||||
return new RaceDetailViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get races page data
|
||||
* TODO: Add presenter transformation when presenter is available
|
||||
* TODO: Add view model transformation when view model is available
|
||||
*/
|
||||
async getRacesPageData(): Promise<RacesPageDataDto> {
|
||||
return this.apiClient.getPageData();
|
||||
@@ -36,7 +37,7 @@ export class RaceService {
|
||||
|
||||
/**
|
||||
* Get total races statistics
|
||||
* TODO: Add presenter transformation when presenter is available
|
||||
* TODO: Add view model transformation when view model is available
|
||||
*/
|
||||
async getRacesTotal(): Promise<RaceStatsDto> {
|
||||
return this.apiClient.getTotal();
|
||||
|
||||
Reference in New Issue
Block a user