view models
This commit is contained in:
@@ -1,32 +1,33 @@
|
||||
import type { LeaguesApiClient } from '../../api/leagues/LeaguesApiClient';
|
||||
import type { LeagueSummaryPresenter } from '../../presenters/LeagueSummaryPresenter';
|
||||
import type { LeagueStandingsPresenter } from '../../presenters/LeagueStandingsPresenter';
|
||||
import type { LeagueSummaryViewModel, LeagueStandingsViewModel } from '../../view-models';
|
||||
import type { CreateLeagueInputDto, CreateLeagueOutputDto, LeagueStatsDto, LeagueScheduleDto, LeagueMembershipsDto } from '../../dtos';
|
||||
import { LeagueSummaryViewModel, LeagueStandingsViewModel } from '../../view-models';
|
||||
import type { CreateLeagueInputDTO, CreateLeagueOutputDTO, LeagueWithCapacityDTO } from '../../types/generated';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type LeagueStatsDto = { totalLeagues: number };
|
||||
type LeagueScheduleDto = { races: Array<unknown> };
|
||||
type LeagueMembershipsDto = { memberships: Array<unknown> };
|
||||
|
||||
/**
|
||||
* League Service
|
||||
*
|
||||
* Orchestrates league operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates league operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class LeagueService {
|
||||
constructor(
|
||||
private readonly apiClient: LeaguesApiClient,
|
||||
private readonly leagueSummaryPresenter: LeagueSummaryPresenter,
|
||||
private readonly leagueStandingsPresenter: LeagueStandingsPresenter
|
||||
private readonly apiClient: LeaguesApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get all leagues with presentation transformation
|
||||
* Get all leagues with view model transformation
|
||||
*/
|
||||
async getAllLeagues(): Promise<LeagueSummaryViewModel[]> {
|
||||
const dto = await this.apiClient.getAllWithCapacity();
|
||||
return this.leagueSummaryPresenter.present(dto);
|
||||
return dto.leagues.map((league: LeagueWithCapacityDTO) => new LeagueSummaryViewModel(league));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get league standings with presentation transformation
|
||||
* Get league standings with view model transformation
|
||||
*/
|
||||
async getLeagueStandings(leagueId: string, currentUserId: string): Promise<LeagueStandingsViewModel> {
|
||||
const dto = await this.apiClient.getStandings(leagueId);
|
||||
@@ -36,7 +37,7 @@ export class LeagueService {
|
||||
drivers: [], // TODO: fetch drivers
|
||||
memberships: [], // TODO: fetch memberships
|
||||
};
|
||||
return this.leagueStandingsPresenter.present(dtoWithExtras, currentUserId);
|
||||
return new LeagueStandingsViewModel(dtoWithExtras, currentUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,7 @@ export class LeagueService {
|
||||
/**
|
||||
* Create a new league
|
||||
*/
|
||||
async createLeague(input: CreateLeagueInputDto): Promise<CreateLeagueOutputDto> {
|
||||
async createLeague(input: CreateLeagueInputDTO): Promise<CreateLeagueOutputDTO> {
|
||||
return await this.apiClient.create(input);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user