website refactor
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { ProtestDetailService } from '@/lib/services/leagues/ProtestDetailService';
|
||||
import { ProtestDetailViewDataBuilder } from '@/lib/builders/view-data/ProtestDetailViewDataBuilder';
|
||||
import { ProtestDetailViewData } from '@/lib/view-data/leagues/ProtestDetailViewData';
|
||||
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueProtestDetailPageQuery implements PageQuery<ProtestDetailViewData, { leagueId: string; protestId: string }, PresentationError> {
|
||||
async execute(params: { leagueId: string; protestId: string }): Promise<Result<ProtestDetailViewData, PresentationError>> {
|
||||
const service = new ProtestDetailService();
|
||||
const result = await service.getProtestDetail(params.leagueId, params.protestId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load protest details' });
|
||||
}
|
||||
|
||||
const viewData = ProtestDetailViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(params: { leagueId: string; protestId: string }): Promise<Result<ProtestDetailViewData, PresentationError>> {
|
||||
const query = new LeagueProtestDetailPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,28 @@
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeagueRulebookService } from '@/lib/services/leagues/LeagueRulebookService';
|
||||
import { RulebookViewDataBuilder } from '@/lib/builders/view-data/RulebookViewDataBuilder';
|
||||
import { RulebookViewData } from '@/lib/view-data/leagues/RulebookViewData';
|
||||
|
||||
/**
|
||||
* LeagueRulebookPageQuery
|
||||
*
|
||||
* Fetches league rulebook data.
|
||||
* Currently returns empty data - would need API endpoint.
|
||||
*/
|
||||
export class LeagueRulebookPageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'RULEBOOK_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// TODO: Implement when API endpoint is available
|
||||
// For now, return empty data
|
||||
return Result.ok({ leagueId, rules: [] });
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueRulebookPageQuery implements PageQuery<RulebookViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<RulebookViewData, PresentationError>> {
|
||||
const service = new LeagueRulebookService();
|
||||
const result = await service.getRulebookData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load rulebook data' });
|
||||
}
|
||||
|
||||
const viewData = RulebookViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'RULEBOOK_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<RulebookViewData, PresentationError>> {
|
||||
const query = new LeagueRulebookPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
@@ -1,64 +1,29 @@
|
||||
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 type { LeagueStandingsViewData } from '@/lib/view-data/LeagueStandingsViewData';
|
||||
import { LeagueStandingsService } from '@/lib/services/leagues/LeagueStandingsService';
|
||||
import { LeagueStandingsViewDataBuilder } from '@/lib/builders/view-data/LeagueStandingsViewDataBuilder';
|
||||
import { LeagueStandingsViewData } from '@/lib/view-data/LeagueStandingsViewData';
|
||||
|
||||
/**
|
||||
* LeagueStandingsPageQuery
|
||||
*
|
||||
* Fetches league standings data for the standings page.
|
||||
* Returns Result<LeagueStandingsViewData, PresentationError>
|
||||
*/
|
||||
export class LeagueStandingsPageQuery implements PageQuery<LeagueStandingsViewData, string> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueStandingsViewData, 'notFound' | 'redirect' | 'STANDINGS_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 {
|
||||
// Fetch standings
|
||||
const standingsDto = await apiClient.getStandings(leagueId);
|
||||
|
||||
if (!standingsDto) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
// For now, return empty data structure
|
||||
// In a real implementation, this would transform the DTO to ViewData
|
||||
const viewData: LeagueStandingsViewData = {
|
||||
standings: [],
|
||||
drivers: [],
|
||||
memberships: [],
|
||||
leagueId,
|
||||
currentDriverId: null,
|
||||
isAdmin: false,
|
||||
};
|
||||
|
||||
return Result.ok(viewData);
|
||||
} catch (error) {
|
||||
console.error('LeagueStandingsPageQuery 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('STANDINGS_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueStandingsPageQuery implements PageQuery<LeagueStandingsViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<LeagueStandingsViewData, PresentationError>> {
|
||||
const service = new LeagueStandingsService();
|
||||
const result = await service.getStandingsData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load standings data' });
|
||||
}
|
||||
|
||||
const { standings, memberships } = result.unwrap();
|
||||
const viewData = LeagueStandingsViewDataBuilder.build(standings, memberships, leagueId);
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<LeagueStandingsViewData, 'notFound' | 'redirect' | 'STANDINGS_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
static async execute(leagueId: string): Promise<Result<LeagueStandingsViewData, PresentationError>> {
|
||||
const query = new LeagueStandingsPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
@@ -1,66 +1,30 @@
|
||||
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 { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { LeagueStewardingService } from '@/lib/services/leagues/LeagueStewardingService';
|
||||
import { StewardingViewDataBuilder } from '@/lib/builders/view-data/StewardingViewDataBuilder';
|
||||
import { StewardingViewData } from '@/lib/view-data/leagues/StewardingViewData';
|
||||
|
||||
/**
|
||||
* LeagueStewardingPageQuery
|
||||
*
|
||||
* Fetches league stewarding data (protests and penalties).
|
||||
*/
|
||||
export class LeagueStewardingPageQuery implements PageQuery<any, string> {
|
||||
async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'STEWARDING_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 races for the league
|
||||
const racesData = await apiClient.getRaces(leagueId);
|
||||
|
||||
if (!racesData) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
// Get memberships for driver lookup
|
||||
const memberships = await apiClient.getMemberships(leagueId);
|
||||
|
||||
// Return data structure for stewarding page
|
||||
// In real implementation, would need protest/penalty API endpoints
|
||||
return Result.ok({
|
||||
leagueId,
|
||||
races: racesData.races || [],
|
||||
memberships: memberships || { members: [] },
|
||||
totalPending: 0,
|
||||
totalResolved: 0,
|
||||
totalPenalties: 0,
|
||||
racesWithData: [],
|
||||
allDrivers: [],
|
||||
driverMap: {},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('LeagueStewardingPageQuery 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('STEWARDING_FETCH_FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
return Result.err('UNKNOWN_ERROR');
|
||||
interface PresentationError {
|
||||
type: 'notFound' | 'forbidden' | 'notImplemented' | 'serverError';
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class LeagueStewardingPageQuery implements PageQuery<StewardingViewData, string, PresentationError> {
|
||||
async execute(leagueId: string): Promise<Result<StewardingViewData, PresentationError>> {
|
||||
const service = new LeagueStewardingService();
|
||||
const result = await service.getStewardingData(leagueId);
|
||||
|
||||
if (result.isErr()) {
|
||||
// Map domain errors to presentation errors
|
||||
return Result.err({ type: 'serverError', message: 'Failed to load stewarding data' });
|
||||
}
|
||||
|
||||
const viewData = StewardingViewDataBuilder.build(result.unwrap());
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
static async execute(leagueId: string): Promise<Result<any, 'notFound' | 'redirect' | 'STEWARDING_FETCH_FAILED' | 'UNKNOWN_ERROR'>> {
|
||||
// Static method to avoid object construction in server code
|
||||
static async execute(leagueId: string): Promise<Result<StewardingViewData, PresentationError>> {
|
||||
const query = new LeagueStewardingPageQuery();
|
||||
return query.execute(leagueId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user