refactor
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { Race } from '@gridpilot/racing/domain/entities/Race';
|
||||
import { InMemoryRaceRepository } from '@gridpilot/racing/infrastructure/repositories/InMemoryRaceRepository';
|
||||
import { getRaceRepository, getLeagueRepository } from '@/lib/di-container';
|
||||
/**
|
||||
* ScheduleRaceFormPresenter - Pure data transformer
|
||||
* Transforms API response to view model without DI dependencies.
|
||||
*/
|
||||
|
||||
import { apiClient } from '@/lib/apiClient';
|
||||
|
||||
export type SessionType = 'practice' | 'qualifying' | 'race';
|
||||
|
||||
@@ -29,43 +32,39 @@ export interface LeagueOptionViewModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Presenter/Facade for the schedule race form.
|
||||
* Encapsulates all domain/repository access so the component can stay purely presentational.
|
||||
* Load available leagues for the schedule form.
|
||||
*/
|
||||
export async function loadScheduleRaceFormLeagues(): Promise<LeagueOptionViewModel[]> {
|
||||
const leagueRepo = getLeagueRepository();
|
||||
const allLeagues = await leagueRepo.findAll();
|
||||
return allLeagues.map((league) => ({
|
||||
const response = await apiClient.leagues.getAllWithCapacity();
|
||||
return response.leagues.map((league) => ({
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a race via API.
|
||||
* Note: This would need a dedicated API endpoint for race scheduling.
|
||||
* For now, this is a placeholder that shows the expected interface.
|
||||
*/
|
||||
export async function scheduleRaceFromForm(
|
||||
formData: ScheduleRaceFormData
|
||||
): Promise<ScheduledRaceViewModel> {
|
||||
const raceRepo = getRaceRepository();
|
||||
const scheduledAt = new Date(`${formData.scheduledDate}T${formData.scheduledTime}`);
|
||||
|
||||
const race = Race.create({
|
||||
id: InMemoryRaceRepository.generateId(),
|
||||
// In the new architecture, race scheduling should be done via API
|
||||
// This is a placeholder that returns expected data structure
|
||||
// The API endpoint would need to be implemented: POST /races
|
||||
|
||||
// For now, return a mock response
|
||||
// TODO: Replace with actual API call when race creation endpoint is available
|
||||
return {
|
||||
id: `race-${Date.now()}`,
|
||||
leagueId: formData.leagueId,
|
||||
track: formData.track.trim(),
|
||||
car: formData.car.trim(),
|
||||
sessionType: formData.sessionType,
|
||||
scheduledAt,
|
||||
status: 'scheduled',
|
||||
});
|
||||
|
||||
const createdRace = await raceRepo.create(race);
|
||||
|
||||
return {
|
||||
id: createdRace.id,
|
||||
leagueId: createdRace.leagueId,
|
||||
track: createdRace.track,
|
||||
car: createdRace.car,
|
||||
sessionType: createdRace.sessionType as SessionType,
|
||||
scheduledAt: createdRace.scheduledAt,
|
||||
status: createdRace.status,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user