website refactor
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user