This commit is contained in:
2025-12-21 19:53:22 +01:00
parent f2d8a23583
commit 3c64f328e2
105 changed files with 3191 additions and 1706 deletions

View File

@@ -50,6 +50,9 @@ import { GetLeagueAdminPermissionsUseCase } from '@core/racing/application/use-c
import { GetLeagueWalletUseCase } from '@core/racing/application/use-cases/GetLeagueWalletUseCase';
import { WithdrawFromLeagueWalletUseCase } from '@core/racing/application/use-cases/WithdrawFromLeagueWalletUseCase';
// Import presenters
import { AllLeaguesWithCapacityPresenter } from './presenters/AllLeaguesWithCapacityPresenter';
// Define injection tokens
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
export const LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN = 'ILeagueMembershipRepository';
@@ -137,8 +140,18 @@ export const LeagueProviders: Provider[] = [
provide: LOGGER_TOKEN,
useClass: ConsoleLogger,
},
// Presenters
{
provide: 'AllLeaguesWithCapacityPresenter',
useClass: AllLeaguesWithCapacityPresenter,
},
// Use cases
GetAllLeaguesWithCapacityUseCase,
{
provide: GetAllLeaguesWithCapacityUseCase,
useFactory: (leagueRepo: ILeagueRepository, membershipRepo: ILeagueMembershipRepository, presenter: AllLeaguesWithCapacityPresenter) =>
new GetAllLeaguesWithCapacityUseCase(leagueRepo, membershipRepo, presenter),
inject: [LEAGUE_REPOSITORY_TOKEN, LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, 'AllLeaguesWithCapacityPresenter'],
},
{
provide: GET_LEAGUE_STANDINGS_USE_CASE,
useClass: GetLeagueStandingsUseCaseImpl,

View File

@@ -135,9 +135,7 @@ export class LeagueService {
if (result.isErr()) {
throw new Error(result.unwrapErr().code);
}
const presenter = new AllLeaguesWithCapacityPresenter();
presenter.present(result.unwrap());
return presenter.getViewModel()!;
return this.getAllLeaguesWithCapacityUseCase.outputPort.present(result);
}
async getTotalLeagues(): Promise<TotalLeaguesDTO> {

View File

@@ -1,31 +1,25 @@
import type { AllLeaguesWithCapacityOutputPort } from '@core/racing/application/ports/output/AllLeaguesWithCapacityOutputPort';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { Result } from '@core/shared/application/Result';
import { AllLeaguesWithCapacityDTO, LeagueWithCapacityDTO } from '../dtos/AllLeaguesWithCapacityDTO';
import type { GetAllLeaguesWithCapacityResult } from '@core/racing/application/use-cases/GetAllLeaguesWithCapacityUseCase';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export class AllLeaguesWithCapacityPresenter {
private result: AllLeaguesWithCapacityDTO | null = null;
reset() {
this.result = null;
}
present(output: AllLeaguesWithCapacityOutputPort) {
export class AllLeaguesWithCapacityPresenter implements UseCaseOutputPort<GetAllLeaguesWithCapacityResult, 'REPOSITORY_ERROR'> {
present(result: Result<GetAllLeaguesWithCapacityResult, ApplicationErrorCode<'REPOSITORY_ERROR'>>): AllLeaguesWithCapacityDTO {
const output = result.unwrap();
const leagues: LeagueWithCapacityDTO[] = output.leagues.map(league => ({
id: league.id,
name: league.name,
description: league.description,
ownerId: league.ownerId,
settings: { maxDrivers: league.settings.maxDrivers || 0 },
createdAt: league.createdAt.toISOString(),
usedSlots: output.memberCounts[league.id] || 0,
socialLinks: league.socialLinks,
id: league.league.id.toString(),
name: league.league.name.toString(),
description: league.league.description?.toString() || '',
ownerId: league.league.ownerId.toString(),
settings: { maxDrivers: league.maxDrivers },
createdAt: league.league.createdAt.toDate().toISOString(),
usedSlots: league.currentDrivers,
socialLinks: league.league.socialLinks || {},
}));
this.result = {
return {
leagues,
totalCount: leagues.length,
};
}
getViewModel(): AllLeaguesWithCapacityDTO | null {
return this.result;
}
}