website refactor
This commit is contained in:
@@ -1,28 +1,68 @@
|
||||
import { ContainerManager } from '@/lib/di/container';
|
||||
import { SESSION_SERVICE_TOKEN, LANDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
||||
import { LandingService } from '@/lib/services/landing/LandingService';
|
||||
import { SessionService } from '@/lib/services/auth/SessionService';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { FeatureFlagService } from '@/lib/feature/FeatureFlagService';
|
||||
|
||||
export async function getHomeData() {
|
||||
const container = ContainerManager.getInstance().getContainer();
|
||||
const sessionService = container.get<SessionService>(SESSION_SERVICE_TOKEN);
|
||||
const landingService = container.get<LandingService>(LANDING_SERVICE_TOKEN);
|
||||
// API Clients
|
||||
import { AuthApiClient } from '@/lib/api/auth/AuthApiClient';
|
||||
import { RacesApiClient } from '@/lib/api/races/RacesApiClient';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { TeamsApiClient } from '@/lib/api/teams/TeamsApiClient';
|
||||
|
||||
// Services
|
||||
import { SessionService } from '@/lib/services/auth/SessionService';
|
||||
|
||||
// Infrastructure
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
|
||||
// DTO types
|
||||
import type { RacesPageDataRaceDTO } from '@/lib/types/generated/RacesPageDataRaceDTO';
|
||||
import type { LeagueWithCapacityDTO } from '@/lib/types/generated/LeagueWithCapacityDTO';
|
||||
import type { TeamListItemDTO } from '@/lib/types/generated/TeamListItemDTO';
|
||||
|
||||
export interface HomeDataDTO {
|
||||
isAlpha: boolean;
|
||||
upcomingRaces: RacesPageDataRaceDTO[];
|
||||
topLeagues: LeagueWithCapacityDTO[];
|
||||
teams: TeamListItemDTO[];
|
||||
}
|
||||
|
||||
export async function getHomeData(): Promise<HomeDataDTO> {
|
||||
// Manual wiring: construct dependencies explicitly
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
|
||||
// Construct API clients
|
||||
const authApiClient = new AuthApiClient(baseUrl, errorReporter, logger);
|
||||
const racesApiClient = new RacesApiClient(baseUrl, errorReporter, logger);
|
||||
const leaguesApiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
const teamsApiClient = new TeamsApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
// Construct services
|
||||
const sessionService = new SessionService(authApiClient);
|
||||
|
||||
// Check session and redirect if logged in
|
||||
const session = await sessionService.getSession();
|
||||
if (session) {
|
||||
redirect('/dashboard');
|
||||
}
|
||||
|
||||
// Get feature flags
|
||||
const featureService = await FeatureFlagService.fromAPI();
|
||||
const isAlpha = featureService.isEnabled('alpha_features');
|
||||
const discovery = await landingService.getHomeDiscovery();
|
||||
|
||||
|
||||
// Get home discovery data (manual implementation)
|
||||
const [racesDto, leaguesDto, teamsDto] = await Promise.all([
|
||||
racesApiClient.getPageData(),
|
||||
leaguesApiClient.getAllWithCapacity(),
|
||||
teamsApiClient.getAll(),
|
||||
]);
|
||||
|
||||
// Return DTOs directly (no ViewModels)
|
||||
return {
|
||||
isAlpha,
|
||||
upcomingRaces: discovery.upcomingRaces,
|
||||
topLeagues: discovery.topLeagues,
|
||||
teams: discovery.teams,
|
||||
upcomingRaces: racesDto.races.slice(0, 4),
|
||||
topLeagues: leaguesDto.leagues.slice(0, 4),
|
||||
teams: teamsDto.teams.slice(0, 4),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user