refactor league module (wip)

This commit is contained in:
2025-12-22 15:47:47 +01:00
parent 03dc81b0ba
commit f59e1b13e7
10 changed files with 444 additions and 819 deletions

View File

@@ -13,6 +13,8 @@ import type { IStandingRepository } from '@core/racing/domain/repositories/IStan
import type { Logger } from '@core/shared/application/Logger';
// Import concrete in-memory implementations
import type { ILeagueWalletRepository } from "@core/racing/domain/repositories/ILeagueWalletRepository";
import type { ITransactionRepository } from "@core/racing/domain/repositories/ITransactionRepository";
import { listLeagueScoringPresets } from '@adapters/bootstrap/LeagueScoringPresets';
import { getPointsSystems } from '@adapters/bootstrap/PointsSystems';
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';
@@ -63,6 +65,8 @@ import { GetLeagueProtestsPresenter } from './presenters/GetLeagueProtestsPresen
import { GetSeasonSponsorshipsPresenter } from './presenters/GetSeasonSponsorshipsPresenter';
import { LeagueScoringPresetsPresenter } from './presenters/LeagueScoringPresetsPresenter';
import { LeagueStandingsPresenter } from './presenters/LeagueStandingsPresenter';
import { GetLeagueWalletPresenter } from './presenters/GetLeagueWalletPresenter';
import { WithdrawFromLeagueWalletPresenter } from './presenters/WithdrawFromLeagueWalletPresenter';
export const LEAGUE_REPOSITORY_TOKEN = 'ILeagueRepository';
export const LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN = 'ILeagueMembershipRepository';
@@ -76,7 +80,7 @@ export const RACE_REPOSITORY_TOKEN = 'IRaceRepository';
export const DRIVER_REPOSITORY_TOKEN = 'IDriverRepository';
export const LEAGUE_WALLET_REPOSITORY_TOKEN = 'ILeagueWalletRepository';
export const TRANSACTION_REPOSITORY_TOKEN = 'ITransactionRepository';
export const LOGGER_TOKEN = 'Logger'; // Already defined in AuthProviders, but good to have here too
export const LOGGER_TOKEN = 'Logger';
export const GET_LEAGUE_STANDINGS_USE_CASE = 'GetLeagueStandingsUseCase';
export const GET_ALL_LEAGUES_WITH_CAPACITY_USE_CASE = 'GetAllLeaguesWithCapacityUseCase';
export const GET_LEAGUE_STATS_USE_CASE = 'GetLeagueStatsUseCase';
@@ -103,6 +107,30 @@ export const GET_LEAGUE_WALLET_USE_CASE = 'GetLeagueWalletUseCase';
export const WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE = 'WithdrawFromLeagueWalletUseCase';
export const GET_SEASON_SPONSORSHIPS_USE_CASE = 'GetSeasonSponsorshipsUseCase';
export const GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN = 'GetAllLeaguesWithCapacityOutputPort_TOKEN';
export const GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN = 'GetLeagueStandingsOutputPort_TOKEN';
export const GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN = 'GetLeagueProtestsOutputPort_TOKEN';
export const GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN = 'GetSeasonSponsorshipsOutputPort_TOKEN';
export const LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN = 'ListLeagueScoringPresetsOutputPort_TOKEN';
export const APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'ApproveLeagueJoinRequestOutputPort_TOKEN';
export const CREATE_LEAGUE_OUTPUT_PORT_TOKEN = 'CreateLeagueOutputPort_TOKEN';
export const GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN = 'GetLeagueAdminPermissionsOutputPort_TOKEN';
export const GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN = 'GetLeagueMembershipsOutputPort_TOKEN';
export const GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN = 'GetLeagueOwnerSummaryOutputPort_TOKEN';
export const GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN = 'GetLeagueSeasonsOutputPort_TOKEN';
export const JOIN_LEAGUE_OUTPUT_PORT_TOKEN = 'JoinLeagueOutputPort_TOKEN';
export const GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN = 'GetLeagueScheduleOutputPort_TOKEN';
export const GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN = 'GetLeagueStatsOutputPort_TOKEN';
export const REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'RejectLeagueJoinRequestOutputPort_TOKEN';
export const REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN = 'RemoveLeagueMemberOutputPort_TOKEN';
export const TOTAL_LEAGUES_OUTPUT_PORT_TOKEN = 'TotalLeaguesOutputPort_TOKEN';
export const TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN = 'TransferLeagueOwnershipOutputPort_TOKEN';
export const UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN = 'UpdateLeagueMemberRoleOutputPort_TOKEN';
export const GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueFullConfigOutputPort_TOKEN';
export const GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueScoringConfigOutputPort_TOKEN';
export const GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'GetLeagueWalletOutputPort_TOKEN';
export const WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'WithdrawFromLeagueWalletOutputPort_TOKEN';
export const LeagueProviders: Provider[] = [
LeagueService, // Provide the service itself
{
@@ -174,6 +202,43 @@ export const LeagueProviders: Provider[] = [
provide: LOGGER_TOKEN,
useClass: ConsoleLogger,
},
// Presenters
AllLeaguesWithCapacityPresenter,
LeagueStandingsPresenter,
GetLeagueProtestsPresenter,
GetSeasonSponsorshipsPresenter,
LeagueScoringPresetsPresenter,
GetLeagueWalletPresenter,
WithdrawFromLeagueWalletPresenter,
// Output ports
{
provide: GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN,
useExisting: AllLeaguesWithCapacityPresenter,
},
{
provide: GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN,
useExisting: LeagueStandingsPresenter,
},
{
provide: GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueProtestsPresenter,
},
{
provide: GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN,
useExisting: GetSeasonSponsorshipsPresenter,
},
{
provide: LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN,
useExisting: LeagueScoringPresetsPresenter,
},
{
provide: GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueWalletPresenter,
},
{
provide: WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
useExisting: WithdrawFromLeagueWalletPresenter,
},
// Use cases
{
provide: GetAllLeaguesWithCapacityUseCase,
@@ -260,11 +325,24 @@ export const LeagueProviders: Provider[] = [
},
{
provide: GET_LEAGUE_WALLET_USE_CASE,
useClass: GetLeagueWalletUseCase,
useFactory: (
leagueRepo: ILeagueRepository,
walletRepo: ILeagueWalletRepository,
transactionRepo: ITransactionRepository,
presenter: GetLeagueWalletPresenter,
) => new GetLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo, presenter),
inject: [LEAGUE_REPOSITORY_TOKEN, LEAGUE_WALLET_REPOSITORY_TOKEN, TRANSACTION_REPOSITORY_TOKEN, 'GetLeagueWalletPresenter'],
},
{
provide: WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE,
useClass: WithdrawFromLeagueWalletUseCase,
useFactory: (
leagueRepo: ILeagueRepository,
walletRepo: ILeagueWalletRepository,
transactionRepo: ITransactionRepository,
logger: Logger,
presenter: WithdrawFromLeagueWalletPresenter,
) => new WithdrawFromLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo, logger, presenter),
inject: [LEAGUE_REPOSITORY_TOKEN, LEAGUE_WALLET_REPOSITORY_TOKEN, TRANSACTION_REPOSITORY_TOKEN, LOGGER_TOKEN, 'WithdrawFromLeagueWalletPresenter'],
},
{
provide: GET_SEASON_SPONSORSHIPS_USE_CASE,
@@ -302,4 +380,4 @@ export const LeagueProviders: Provider[] = [
provide: GET_LEAGUE_SCORING_CONFIG_USE_CASE,
useClass: GetLeagueScoringConfigUseCase,
}
];
];