website refactor
This commit is contained in:
@@ -6,10 +6,7 @@ import { CreateLeagueInputDTO } from "@/lib/types/generated/CreateLeagueInputDTO
|
||||
import { CreateLeagueOutputDTO } from "@/lib/types/generated/CreateLeagueOutputDTO";
|
||||
import type { MembershipRole } from "@/lib/types/MembershipRole";
|
||||
import type { LeagueRosterJoinRequestDTO } from "@/lib/types/generated/LeagueRosterJoinRequestDTO";
|
||||
import type { RaceDTO } from "@/lib/types/generated/RaceDTO";
|
||||
import type { TotalLeaguesDTO } from '@/lib/types/generated/TotalLeaguesDTO';
|
||||
import type { LeagueScoringConfigDTO } from "@/lib/types/generated/LeagueScoringConfigDTO";
|
||||
import type { LeagueMembership } from "@/lib/types/LeagueMembership";
|
||||
import type { LeagueSeasonSummaryDTO } from '@/lib/types/generated/LeagueSeasonSummaryDTO';
|
||||
import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO';
|
||||
import type { CreateLeagueScheduleRaceInputDTO } from '@/lib/types/generated/CreateLeagueScheduleRaceInputDTO';
|
||||
@@ -19,27 +16,52 @@ import type { LeagueScheduleRaceMutationSuccessDTO } from '@/lib/types/generated
|
||||
import type { LeagueSeasonSchedulePublishOutputDTO } from '@/lib/types/generated/LeagueSeasonSchedulePublishOutputDTO';
|
||||
import type { LeagueRosterMemberDTO } from '@/lib/types/generated/LeagueRosterMemberDTO';
|
||||
import type { LeagueMembershipsDTO } from '@/lib/types/generated/LeagueMembershipsDTO';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
import { getWebsiteServerEnv } from '@/lib/config/env';
|
||||
import { AllLeaguesWithCapacityAndScoringDTO } from '@/lib/types/AllLeaguesWithCapacityAndScoringDTO';
|
||||
|
||||
/**
|
||||
* League Service - DTO Only
|
||||
*
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* Returns Result<ApiDto, DomainError>. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
* @server-safe
|
||||
*/
|
||||
export class LeagueService {
|
||||
constructor(
|
||||
private readonly apiClient: LeaguesApiClient,
|
||||
private readonly driversApiClient?: DriversApiClient,
|
||||
private readonly sponsorsApiClient?: SponsorsApiClient,
|
||||
private readonly racesApiClient?: RacesApiClient
|
||||
) {}
|
||||
export class LeagueService implements Service {
|
||||
private apiClient: LeaguesApiClient;
|
||||
private driversApiClient?: DriversApiClient;
|
||||
private sponsorsApiClient?: SponsorsApiClient;
|
||||
private racesApiClient?: RacesApiClient;
|
||||
|
||||
async getAllLeagues(): Promise<any> {
|
||||
return this.apiClient.getAllWithCapacityAndScoring();
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const { NODE_ENV } = getWebsiteServerEnv();
|
||||
const errorReporter = new EnhancedErrorReporter(logger, {
|
||||
showUserNotifications: false,
|
||||
logToConsole: true,
|
||||
reportToExternal: NODE_ENV === 'production',
|
||||
});
|
||||
this.apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
// Optional clients can be initialized if needed
|
||||
}
|
||||
|
||||
async getLeagueStandings(leagueId: string): Promise<any> {
|
||||
return this.apiClient.getStandings(leagueId);
|
||||
async getAllLeagues(): Promise<Result<AllLeaguesWithCapacityAndScoringDTO, DomainError>> {
|
||||
try {
|
||||
const dto = await this.apiClient.getAllWithCapacityAndScoring();
|
||||
return Result.ok(dto);
|
||||
} catch (error) {
|
||||
console.error('LeagueService.getAllLeagues failed:', error);
|
||||
return Result.err({ type: 'serverError', message: 'Failed to fetch leagues' });
|
||||
}
|
||||
}
|
||||
|
||||
async getLeagueStandings(): Promise<Result<never, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'League standings endpoint not implemented' });
|
||||
}
|
||||
|
||||
async getLeagueStats(): Promise<TotalLeaguesDTO> {
|
||||
@@ -166,16 +188,15 @@ export class LeagueService {
|
||||
return { success: dto.success };
|
||||
}
|
||||
|
||||
async getLeagueDetail(leagueId: string): Promise<any> {
|
||||
return this.apiClient.getAllWithCapacityAndScoring();
|
||||
async getLeagueDetail(): Promise<Result<never, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'League detail endpoint not implemented' });
|
||||
}
|
||||
|
||||
async getLeagueDetailPageData(leagueId: string): Promise<any> {
|
||||
return this.apiClient.getAllWithCapacityAndScoring();
|
||||
async getLeagueDetailPageData(): Promise<Result<never, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'League detail page data endpoint not implemented' });
|
||||
}
|
||||
|
||||
async getScoringPresets(): Promise<any[]> {
|
||||
const result = await this.apiClient.getScoringPresets();
|
||||
return result.presets;
|
||||
async getScoringPresets(): Promise<Result<never, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'Scoring presets endpoint not implemented' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user