website refactor
This commit is contained in:
@@ -1,39 +1,29 @@
|
||||
import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO';
|
||||
import type { LeagueSeasonSummaryDTO } from '@/lib/types/generated/LeagueSeasonSummaryDTO';
|
||||
import type { LeagueScheduleViewData, ScheduleRaceData } from '@/lib/view-data/LeagueScheduleViewData';
|
||||
import { LeagueScheduleViewData } from '@/lib/view-data/leagues/LeagueScheduleViewData';
|
||||
import { LeagueScheduleApiDto } from '@/lib/types/tbd/LeagueScheduleApiDto';
|
||||
|
||||
/**
|
||||
* LeagueScheduleViewDataBuilder
|
||||
*
|
||||
* Transforms API DTOs into LeagueScheduleViewData for server-side rendering.
|
||||
* Deterministic; side-effect free; no HTTP calls.
|
||||
*/
|
||||
export class LeagueScheduleViewDataBuilder {
|
||||
static build(input: {
|
||||
schedule: LeagueScheduleDTO;
|
||||
seasons: LeagueSeasonSummaryDTO[];
|
||||
leagueId: string;
|
||||
}): LeagueScheduleViewData {
|
||||
const { schedule, seasons, leagueId } = input;
|
||||
|
||||
// Transform races - using available fields from RaceDTO
|
||||
const races: ScheduleRaceData[] = (schedule.races || []).map(race => ({
|
||||
id: race.id,
|
||||
name: race.name,
|
||||
track: race.leagueName || 'Unknown Track',
|
||||
car: 'Unknown Car',
|
||||
scheduledAt: race.date,
|
||||
status: 'scheduled',
|
||||
}));
|
||||
|
||||
static build(apiDto: LeagueScheduleApiDto): LeagueScheduleViewData {
|
||||
const now = new Date();
|
||||
|
||||
return {
|
||||
leagueId,
|
||||
races,
|
||||
seasons: seasons.map(s => ({
|
||||
seasonId: s.seasonId,
|
||||
name: s.name,
|
||||
status: s.status,
|
||||
})),
|
||||
leagueId: apiDto.leagueId,
|
||||
races: apiDto.races.map((race) => {
|
||||
const scheduledAt = new Date(race.date);
|
||||
const isPast = scheduledAt.getTime() < now.getTime();
|
||||
const isUpcoming = !isPast;
|
||||
|
||||
return {
|
||||
id: race.id,
|
||||
name: race.name,
|
||||
scheduledAt: race.date,
|
||||
track: race.track,
|
||||
car: race.car,
|
||||
sessionType: race.sessionType,
|
||||
isPast,
|
||||
isUpcoming,
|
||||
status: isPast ? 'completed' : 'scheduled',
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { LeagueSettingsViewData } from '@/lib/view-data/leagues/LeagueSettingsViewData';
|
||||
import { LeagueSettingsApiDto } from '@/lib/types/tbd/LeagueSettingsApiDto';
|
||||
|
||||
export class LeagueSettingsViewDataBuilder {
|
||||
static build(apiDto: LeagueSettingsApiDto): LeagueSettingsViewData {
|
||||
return {
|
||||
leagueId: apiDto.leagueId,
|
||||
league: apiDto.league,
|
||||
config: apiDto.config,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { LeagueSponsorshipsViewData } from '@/lib/view-data/leagues/LeagueSponsorshipsViewData';
|
||||
import { LeagueSponsorshipsApiDto } from '@/lib/types/tbd/LeagueSponsorshipsApiDto';
|
||||
|
||||
export class LeagueSponsorshipsViewDataBuilder {
|
||||
static build(apiDto: LeagueSponsorshipsApiDto): LeagueSponsorshipsViewData {
|
||||
return {
|
||||
leagueId: apiDto.leagueId,
|
||||
league: apiDto.league,
|
||||
sponsorshipSlots: apiDto.sponsorshipSlots,
|
||||
sponsorshipRequests: apiDto.sponsorshipRequests,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { LeagueWalletViewData } from '@/lib/view-data/leagues/LeagueWalletViewData';
|
||||
import { LeagueWalletApiDto } from '@/lib/types/tbd/LeagueWalletApiDto';
|
||||
|
||||
export class LeagueWalletViewDataBuilder {
|
||||
static build(apiDto: LeagueWalletApiDto): LeagueWalletViewData {
|
||||
return {
|
||||
leagueId: apiDto.leagueId,
|
||||
balance: apiDto.balance,
|
||||
currency: apiDto.currency,
|
||||
transactions: apiDto.transactions,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,28 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { LeagueScheduleService } from '@/lib/services/leagues/LeagueScheduleService';
|
||||
import { LeagueScheduleViewDataBuilder } from '@/lib/builders/view-data/LeagueScheduleViewDataBuilder';
|
||||
import { LeagueScheduleViewData } from '@/lib/view-data/leagues/LeagueScheduleViewData';
|
||||
|
||||
/**
|
||||
* LeagueSchedulePageQuery
|
||||
*
|
||||
* Fetches league schedule data for the schedule page.
|
||||
* Returns raw API DTO for now - would need ViewDataBuilder for proper transformation.
|
||||
*/
|
||||
export class LeagueSchedulePageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SCHEDULE_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// Manual wiring: create API client
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
try {
|
||||
const scheduleDto = await apiClient.getSchedule(leagueId);
|
||||
|
||||
if (!scheduleDto) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
return Result.ok(scheduleDto);
|
||||
} catch (error) {
|
||||
console.error('LeagueSchedulePageQuery failed:', error);
|
||||
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('403') || error.message.includes('401')) {
|
||||
return Result.err('redirect');
|
||||
}
|
||||
if (error.message.includes('404')) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
if (error.message.includes('5') || error.message.includes('server')) {
|
||||
return Result.err('SCHEDULE_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueSchedulePageQuery implements PageQuery<LeagueScheduleViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueScheduleViewData, PresentationError>> {
|
||||
const service = new LeagueScheduleService();
|
||||
const result = await service.getScheduleData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load schedule data' });
|
||||
}
|
||||
|
||||
const viewData = LeagueScheduleViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SCHEDULE_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<LeagueScheduleViewData, PresentationError>> {
|
||||
const query = new LeagueSchedulePageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
@@ -1,54 +1,28 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { LeagueSettingsService } from '@/lib/services/leagues/LeagueSettingsService';
|
||||
import { LeagueSettingsViewDataBuilder } from '@/lib/builders/view-data/LeagueSettingsViewDataBuilder';
|
||||
import { LeagueSettingsViewData } from '@/lib/view-data/leagues/LeagueSettingsViewData';
|
||||
|
||||
/**
|
||||
* LeagueSettingsPageQuery
|
||||
*
|
||||
* Fetches league settings data.
|
||||
*/
|
||||
export class LeagueSettingsPageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SETTINGS_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// Manual wiring: create API client
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
try {
|
||||
// Get league config
|
||||
const config = await apiClient.getLeagueConfig(leagueId);
|
||||
|
||||
if (!config) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
return Result.ok({
|
||||
leagueId,
|
||||
config,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('LeagueSettingsPageQuery failed:', error);
|
||||
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('403') || error.message.includes('401')) {
|
||||
return Result.err('redirect');
|
||||
}
|
||||
if (error.message.includes('404')) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
if (error.message.includes('5') || error.message.includes('server')) {
|
||||
return Result.err('SETTINGS_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueSettingsPageQuery implements PageQuery<LeagueSettingsViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueSettingsViewData, PresentationError>> {
|
||||
const service = new LeagueSettingsService();
|
||||
const result = await service.getSettingsData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load settings data' });
|
||||
}
|
||||
|
||||
const viewData = LeagueSettingsViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SETTINGS_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<LeagueSettingsViewData, PresentationError>> {
|
||||
const query = new LeagueSettingsPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
@@ -1,60 +1,28 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { LeagueSponsorshipsService } from '@/lib/services/leagues/LeagueSponsorshipsService';
|
||||
import { LeagueSponsorshipsViewDataBuilder } from '@/lib/builders/view-data/LeagueSponsorshipsViewDataBuilder';
|
||||
import { LeagueSponsorshipsViewData } from '@/lib/view-data/leagues/LeagueSponsorshipsViewData';
|
||||
|
||||
/**
|
||||
* LeagueSponsorshipsPageQuery
|
||||
*
|
||||
* Fetches league sponsorships data.
|
||||
*/
|
||||
export class LeagueSponsorshipsPageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SPONSORSHIPS_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// Manual wiring: create API client
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
try {
|
||||
// Get seasons first to find active season
|
||||
const seasons = await apiClient.getSeasons(leagueId);
|
||||
|
||||
if (!seasons || seasons.length === 0) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
// Get sponsorships for the first season (or active season)
|
||||
const activeSeason = seasons.find(s => s.status === 'active') || seasons[0];
|
||||
const sponsorshipsData = await apiClient.getSeasonSponsorships(activeSeason.seasonId);
|
||||
|
||||
return Result.ok({
|
||||
leagueId,
|
||||
seasonId: activeSeason.seasonId,
|
||||
sponsorships: sponsorshipsData.sponsorships || [],
|
||||
seasons,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('LeagueSponsorshipsPageQuery failed:', error);
|
||||
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('403') || error.message.includes('401')) {
|
||||
return Result.err('redirect');
|
||||
}
|
||||
if (error.message.includes('404')) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
if (error.message.includes('5') || error.message.includes('server')) {
|
||||
return Result.err('SPONSORSHIPS_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueSponsorshipsPageQuery implements PageQuery<LeagueSponsorshipsViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueSponsorshipsViewData, PresentationError>> {
|
||||
const service = new LeagueSponsorshipsService();
|
||||
const result = await service.getSponsorshipsData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load sponsorships data' });
|
||||
}
|
||||
|
||||
const viewData = LeagueSponsorshipsViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'SPONSORSHIPS_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<LeagueSponsorshipsViewData, PresentationError>> {
|
||||
const query = new LeagueSponsorshipsPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
@@ -1,62 +1,28 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { LeagueWalletService } from '@/lib/services/leagues/LeagueWalletService';
|
||||
import { LeagueWalletViewDataBuilder } from '@/lib/builders/view-data/LeagueWalletViewDataBuilder';
|
||||
import { LeagueWalletViewData } from '@/lib/view-data/leagues/LeagueWalletViewData';
|
||||
|
||||
/**
|
||||
* LeagueWalletPageQuery
|
||||
*
|
||||
* Fetches league wallet data.
|
||||
*/
|
||||
export class LeagueWalletPageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'WALLET_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// Manual wiring: create API client
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
try {
|
||||
// Get league memberships to verify access
|
||||
const memberships = await apiClient.getMemberships(leagueId);
|
||||
|
||||
if (!memberships) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
// Return wallet data structure
|
||||
// In real implementation, would need wallet API endpoints
|
||||
return Result.ok({
|
||||
leagueId,
|
||||
balance: 0,
|
||||
totalRevenue: 0,
|
||||
totalFees: 0,
|
||||
pendingPayouts: 0,
|
||||
transactions: [],
|
||||
canWithdraw: false,
|
||||
withdrawalBlockReason: 'Wallet system not yet implemented',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('LeagueWalletPageQuery failed:', error);
|
||||
|
||||
if (error instanceof Error) {
|
||||
if (error.message.includes('403') || error.message.includes('401')) {
|
||||
return Result.err('redirect');
|
||||
}
|
||||
if (error.message.includes('404')) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
if (error.message.includes('5') || error.message.includes('server')) {
|
||||
return Result.err('WALLET_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueWalletPageQuery implements PageQuery<LeagueWalletViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueWalletViewData, PresentationError>> {
|
||||
const service = new LeagueWalletService();
|
||||
const result = await service.getWalletData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load wallet data' });
|
||||
}
|
||||
|
||||
const viewData = LeagueWalletViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'WALLET_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<LeagueWalletViewData, PresentationError>> {
|
||||
const query = new LeagueWalletPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
39
apps/website/lib/services/leagues/LeagueScheduleService.ts
Normal file
39
apps/website/lib/services/leagues/LeagueScheduleService.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { Service } from '@/lib/contracts/services/Service';
|
||||
import { LeagueScheduleApiDto } from '@/lib/types/tbd/LeagueScheduleApiDto';
|
||||
|
||||
export class LeagueScheduleService implements Service {
|
||||
async getScheduleData(leagueId: string): Promise<Result<LeagueScheduleApiDto, never>> {
|
||||
// Mock data since backend not implemented
|
||||
const mockData: LeagueScheduleApiDto = {
|
||||
leagueId,
|
||||
races: [
|
||||
{
|
||||
id: 'race-1',
|
||||
name: 'Round 1 - Monza',
|
||||
date: '2024-10-15T14:00:00Z',
|
||||
track: 'Monza Circuit',
|
||||
car: 'Ferrari SF90',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
{
|
||||
id: 'race-2',
|
||||
name: 'Round 2 - Silverstone',
|
||||
date: '2024-10-22T13:00:00Z',
|
||||
track: 'Silverstone Circuit',
|
||||
car: 'Mercedes W10',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
{
|
||||
id: 'race-3',
|
||||
name: 'Round 3 - Spa-Francorchamps',
|
||||
date: '2024-10-29T12:00:00Z',
|
||||
track: 'Circuit de Spa-Francorchamps',
|
||||
car: 'Red Bull RB15',
|
||||
sessionType: 'Race',
|
||||
},
|
||||
],
|
||||
};
|
||||
return Result.ok(mockData);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,28 @@
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { DriversApiClient } from '@/lib/api/drivers/DriversApiClient';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError } from '@/lib/contracts/services/Service';
|
||||
import { Service } from '@/lib/contracts/services/Service';
|
||||
import { LeagueSettingsApiDto } from '@/lib/types/tbd/LeagueSettingsApiDto';
|
||||
|
||||
/**
|
||||
* League Settings Service - DTO Only
|
||||
*
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
*/
|
||||
export class LeagueSettingsService {
|
||||
constructor(
|
||||
private readonly leagueApiClient: LeaguesApiClient,
|
||||
private readonly driverApiClient: DriversApiClient
|
||||
) {}
|
||||
|
||||
async getLeagueSettings(leagueId: string): Promise<any> {
|
||||
// This would typically call multiple endpoints to gather all settings data
|
||||
// For now, return a basic structure
|
||||
return {
|
||||
league: await this.leagueApiClient.getAllWithCapacityAndScoring(),
|
||||
config: { /* config data */ }
|
||||
export class LeagueSettingsService implements Service {
|
||||
async getSettingsData(leagueId: string): Promise<Result<LeagueSettingsApiDto, never>> {
|
||||
// Mock data since backend not implemented
|
||||
const mockData: LeagueSettingsApiDto = {
|
||||
leagueId,
|
||||
league: {
|
||||
id: leagueId,
|
||||
name: 'Mock League',
|
||||
description: 'A mock league for demonstration',
|
||||
visibility: 'public',
|
||||
ownerId: 'owner-123',
|
||||
createdAt: '2024-01-01T00:00:00Z',
|
||||
updatedAt: '2024-01-01T00:00:00Z',
|
||||
},
|
||||
config: {
|
||||
maxDrivers: 20,
|
||||
scoringPresetId: 'preset-1',
|
||||
allowLateJoin: true,
|
||||
requireApproval: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async transferOwnership(leagueId: string, currentOwnerId: string, newOwnerId: string): Promise<{ success: boolean }> {
|
||||
return this.leagueApiClient.transferOwnership(leagueId, currentOwnerId, newOwnerId);
|
||||
}
|
||||
|
||||
async selectScoringPreset(leagueId: string, preset: string): Promise<Result<void, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'selectScoringPreset' });
|
||||
}
|
||||
|
||||
async toggleCustomScoring(leagueId: string, enabled: boolean): Promise<Result<void, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'toggleCustomScoring' });
|
||||
}
|
||||
|
||||
getPresetEmoji(preset: string): string {
|
||||
return '🏆';
|
||||
}
|
||||
|
||||
getPresetDescription(preset: string): string {
|
||||
return `Scoring preset: ${preset}`;
|
||||
return Result.ok(mockData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { Service } from '@/lib/contracts/services/Service';
|
||||
import { LeagueSponsorshipsApiDto } from '@/lib/types/tbd/LeagueSponsorshipsApiDto';
|
||||
|
||||
export class LeagueSponsorshipsService implements Service {
|
||||
async getSponsorshipsData(leagueId: string): Promise<Result<LeagueSponsorshipsApiDto, never>> {
|
||||
// Mock data since backend not implemented
|
||||
const mockData: LeagueSponsorshipsApiDto = {
|
||||
leagueId,
|
||||
league: {
|
||||
id: leagueId,
|
||||
name: 'Mock League',
|
||||
description: 'A league with sponsorship opportunities',
|
||||
},
|
||||
sponsorshipSlots: [
|
||||
{
|
||||
id: 'slot-1',
|
||||
name: 'Main Sponsor',
|
||||
description: 'Primary sponsorship slot',
|
||||
price: 5000,
|
||||
currency: 'USD',
|
||||
isAvailable: false,
|
||||
sponsoredBy: {
|
||||
id: 'sponsor-1',
|
||||
name: 'Acme Racing',
|
||||
logoUrl: 'https://example.com/logo.png',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'slot-2',
|
||||
name: 'Helmet Sponsor',
|
||||
description: 'Helmet branding sponsorship',
|
||||
price: 2000,
|
||||
currency: 'USD',
|
||||
isAvailable: true,
|
||||
},
|
||||
{
|
||||
id: 'slot-3',
|
||||
name: 'Car Sponsor',
|
||||
description: 'Car livery sponsorship',
|
||||
price: 3000,
|
||||
currency: 'USD',
|
||||
isAvailable: true,
|
||||
},
|
||||
],
|
||||
sponsorshipRequests: [
|
||||
{
|
||||
id: 'request-1',
|
||||
slotId: 'slot-2',
|
||||
sponsorId: 'sponsor-2',
|
||||
sponsorName: 'SpeedWorks',
|
||||
requestedAt: '2024-10-01T10:00:00Z',
|
||||
status: 'pending',
|
||||
},
|
||||
],
|
||||
};
|
||||
return Result.ok(mockData);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,49 @@
|
||||
import { WalletsApiClient } from '@/lib/api/wallets/WalletsApiClient';
|
||||
import type { LeagueWalletDTO, WithdrawRequestDTO, WithdrawResponseDTO } from '@/lib/api/wallets/WalletsApiClient';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { Service } from '@/lib/contracts/services/Service';
|
||||
import { LeagueWalletApiDto } from '@/lib/types/tbd/LeagueWalletApiDto';
|
||||
|
||||
/**
|
||||
* LeagueWalletService - DTO Only
|
||||
*
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
*/
|
||||
export class LeagueWalletService {
|
||||
constructor(
|
||||
private readonly apiClient: WalletsApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get wallet for a league
|
||||
*/
|
||||
async getWalletForLeague(leagueId: string): Promise<LeagueWalletDTO> {
|
||||
return this.apiClient.getLeagueWallet(leagueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw from league wallet
|
||||
*/
|
||||
async withdraw(
|
||||
leagueId: string,
|
||||
amount: number,
|
||||
currency: string,
|
||||
seasonId: string,
|
||||
destinationAccount: string
|
||||
): Promise<WithdrawResponseDTO> {
|
||||
const payload: WithdrawRequestDTO = {
|
||||
amount,
|
||||
currency,
|
||||
seasonId,
|
||||
destinationAccount,
|
||||
export class LeagueWalletService implements Service {
|
||||
async getWalletData(leagueId: string): Promise<Result<LeagueWalletApiDto, never>> {
|
||||
// Mock data since backend not implemented
|
||||
const mockData: LeagueWalletApiDto = {
|
||||
leagueId,
|
||||
balance: 15750.00,
|
||||
currency: 'USD',
|
||||
transactions: [
|
||||
{
|
||||
id: 'txn-1',
|
||||
type: 'sponsorship',
|
||||
amount: 5000.00,
|
||||
description: 'Main sponsorship from Acme Racing',
|
||||
createdAt: '2024-10-01T10:00:00Z',
|
||||
status: 'completed',
|
||||
},
|
||||
{
|
||||
id: 'txn-2',
|
||||
type: 'prize',
|
||||
amount: 2500.00,
|
||||
description: 'Prize money from championship',
|
||||
createdAt: '2024-09-15T14:30:00Z',
|
||||
status: 'completed',
|
||||
},
|
||||
{
|
||||
id: 'txn-3',
|
||||
type: 'withdrawal',
|
||||
amount: -1200.00,
|
||||
description: 'Equipment purchase',
|
||||
createdAt: '2024-09-10T09:15:00Z',
|
||||
status: 'completed',
|
||||
},
|
||||
{
|
||||
id: 'txn-4',
|
||||
type: 'deposit',
|
||||
amount: 5000.00,
|
||||
description: 'Entry fees from season registration',
|
||||
createdAt: '2024-08-01T12:00:00Z',
|
||||
status: 'completed',
|
||||
},
|
||||
],
|
||||
};
|
||||
return this.apiClient.withdrawFromLeagueWallet(leagueId, payload);
|
||||
return Result.ok(mockData);
|
||||
}
|
||||
}
|
||||
11
apps/website/lib/types/tbd/LeagueScheduleApiDto.ts
Normal file
11
apps/website/lib/types/tbd/LeagueScheduleApiDto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface LeagueScheduleApiDto {
|
||||
leagueId: string;
|
||||
races: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
date: string; // ISO string
|
||||
track?: string;
|
||||
car?: string;
|
||||
sessionType?: string;
|
||||
}>;
|
||||
}
|
||||
18
apps/website/lib/types/tbd/LeagueSettingsApiDto.ts
Normal file
18
apps/website/lib/types/tbd/LeagueSettingsApiDto.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export interface LeagueSettingsApiDto {
|
||||
leagueId: string;
|
||||
league: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
visibility: 'public' | 'private';
|
||||
ownerId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
config: {
|
||||
maxDrivers: number;
|
||||
scoringPresetId: string;
|
||||
allowLateJoin: boolean;
|
||||
requireApproval: boolean;
|
||||
};
|
||||
}
|
||||
29
apps/website/lib/types/tbd/LeagueSponsorshipsApiDto.ts
Normal file
29
apps/website/lib/types/tbd/LeagueSponsorshipsApiDto.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export interface LeagueSponsorshipsApiDto {
|
||||
leagueId: string;
|
||||
league: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
sponsorshipSlots: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
isAvailable: boolean;
|
||||
sponsoredBy?: {
|
||||
id: string;
|
||||
name: string;
|
||||
logoUrl?: string;
|
||||
};
|
||||
}>;
|
||||
sponsorshipRequests: Array<{
|
||||
id: string;
|
||||
slotId: string;
|
||||
sponsorId: string;
|
||||
sponsorName: string;
|
||||
requestedAt: string;
|
||||
status: 'pending' | 'approved' | 'rejected';
|
||||
}>;
|
||||
}
|
||||
13
apps/website/lib/types/tbd/LeagueWalletApiDto.ts
Normal file
13
apps/website/lib/types/tbd/LeagueWalletApiDto.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface LeagueWalletApiDto {
|
||||
leagueId: string;
|
||||
balance: number;
|
||||
currency: string;
|
||||
transactions: Array<{
|
||||
id: string;
|
||||
type: 'deposit' | 'withdrawal' | 'sponsorship' | 'prize';
|
||||
amount: number;
|
||||
description: string;
|
||||
createdAt: string;
|
||||
status: 'completed' | 'pending' | 'failed';
|
||||
}>;
|
||||
}
|
||||
14
apps/website/lib/view-data/leagues/LeagueScheduleViewData.ts
Normal file
14
apps/website/lib/view-data/leagues/LeagueScheduleViewData.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export interface LeagueScheduleViewData {
|
||||
leagueId: string;
|
||||
races: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
scheduledAt: string; // ISO string
|
||||
track?: string;
|
||||
car?: string;
|
||||
sessionType?: string;
|
||||
isPast: boolean;
|
||||
isUpcoming: boolean;
|
||||
status: 'scheduled' | 'completed';
|
||||
}>;
|
||||
}
|
||||
18
apps/website/lib/view-data/leagues/LeagueSettingsViewData.ts
Normal file
18
apps/website/lib/view-data/leagues/LeagueSettingsViewData.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export interface LeagueSettingsViewData {
|
||||
leagueId: string;
|
||||
league: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
visibility: 'public' | 'private';
|
||||
ownerId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
config: {
|
||||
maxDrivers: number;
|
||||
scoringPresetId: string;
|
||||
allowLateJoin: boolean;
|
||||
requireApproval: boolean;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
export interface LeagueSponsorshipsViewData {
|
||||
leagueId: string;
|
||||
league: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
sponsorshipSlots: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
isAvailable: boolean;
|
||||
sponsoredBy?: {
|
||||
id: string;
|
||||
name: string;
|
||||
logoUrl?: string;
|
||||
};
|
||||
}>;
|
||||
sponsorshipRequests: Array<{
|
||||
id: string;
|
||||
slotId: string;
|
||||
sponsorId: string;
|
||||
sponsorName: string;
|
||||
requestedAt: string;
|
||||
status: 'pending' | 'approved' | 'rejected';
|
||||
}>;
|
||||
}
|
||||
13
apps/website/lib/view-data/leagues/LeagueWalletViewData.ts
Normal file
13
apps/website/lib/view-data/leagues/LeagueWalletViewData.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface LeagueWalletViewData {
|
||||
leagueId: string;
|
||||
balance: number;
|
||||
currency: string;
|
||||
transactions: Array<{
|
||||
id: string;
|
||||
type: 'deposit' | 'withdrawal' | 'sponsorship' | 'prize';
|
||||
amount: number;
|
||||
description: string;
|
||||
createdAt: string;
|
||||
status: 'completed' | 'pending' | 'failed';
|
||||
}>;
|
||||
}
|
||||
Reference in New Issue
Block a user