refactor
This commit is contained in:
37
core/racing/application/use-cases/GetLeagueAdminUseCase.ts
Normal file
37
core/racing/application/use-cases/GetLeagueAdminUseCase.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { IGetLeagueAdminPresenter, GetLeagueAdminResultDTO, GetLeagueAdminViewModel } from '../presenters/IGetLeagueAdminPresenter';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
|
||||
export interface GetLeagueAdminUseCaseParams {
|
||||
leagueId: string;
|
||||
}
|
||||
|
||||
export interface GetLeagueAdminResultDTO {
|
||||
league: {
|
||||
id: string;
|
||||
ownerId: string;
|
||||
};
|
||||
// Additional data would be populated by combining multiple use cases
|
||||
}
|
||||
|
||||
export class GetLeagueAdminUseCase implements UseCase<GetLeagueAdminUseCaseParams, GetLeagueAdminResultDTO, GetLeagueAdminViewModel, IGetLeagueAdminPresenter> {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
) {}
|
||||
|
||||
async execute(params: GetLeagueAdminUseCaseParams, presenter: IGetLeagueAdminPresenter): Promise<void> {
|
||||
const league = await this.leagueRepository.findById(params.leagueId);
|
||||
if (!league) {
|
||||
throw new Error('League not found');
|
||||
}
|
||||
|
||||
const dto: GetLeagueAdminResultDTO = {
|
||||
league: {
|
||||
id: league.id,
|
||||
ownerId: league.ownerId,
|
||||
},
|
||||
};
|
||||
presenter.reset();
|
||||
presenter.present(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user