refactor core presenters

This commit is contained in:
2025-12-19 19:42:19 +01:00
parent 8116fe888f
commit 94fc538f44
228 changed files with 2817 additions and 3097 deletions

View File

@@ -1,7 +1,7 @@
import type { ITeamRepository } from '@core/racing/domain/repositories/ITeamRepository';
import type { ITeamMembershipRepository } from '@core/racing/domain/repositories/ITeamMembershipRepository';
import type { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
import type { TeamsLeaderboardResultDTO } from '@core/racing/application/presenters/ITeamsLeaderboardPresenter';
import type { TeamsLeaderboardOutputPort, SkillLevel } from '../ports/output/TeamsLeaderboardOutputPort';
import { SkillLevelService } from '@core/racing/domain/services/SkillLevelService';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
@@ -30,7 +30,7 @@ interface TeamLeaderboardItem {
/**
* Use case: GetTeamsLeaderboardUseCase
*/
export class GetTeamsLeaderboardUseCase implements AsyncUseCase<void, TeamsLeaderboardResultDTO, 'REPOSITORY_ERROR'>
export class GetTeamsLeaderboardUseCase implements AsyncUseCase<void, TeamsLeaderboardOutputPort, 'REPOSITORY_ERROR'>
{
constructor(
private readonly teamRepository: ITeamRepository,
@@ -40,7 +40,7 @@ export class GetTeamsLeaderboardUseCase implements AsyncUseCase<void, TeamsLeade
private readonly logger: Logger,
) {}
async execute(): Promise<Result<TeamsLeaderboardResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
async execute(): Promise<Result<TeamsLeaderboardOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const allTeams = await this.teamRepository.findAll();
const teams: TeamLeaderboardItem[] = [];
@@ -88,12 +88,28 @@ export class GetTeamsLeaderboardUseCase implements AsyncUseCase<void, TeamsLeade
const recruitingCount = teams.filter((t) => t.isRecruiting).length;
const result: TeamsLeaderboardResultDTO = {
teams,
recruitingCount,
const groupsBySkillLevel: Record<SkillLevel, typeof teams> = {
beginner: [],
intermediate: [],
advanced: [],
pro: [],
};
return Result.ok(result);
teams.forEach(team => {
const level = team.performanceLevel as SkillLevel;
groupsBySkillLevel[level].push(team);
});
const topTeams = teams.slice(0, 10); // Assuming top 10
const outputPort: TeamsLeaderboardOutputPort = {
teams,
recruitingCount,
groupsBySkillLevel,
topTeams,
};
return Result.ok(outputPort);
} catch (error) {
this.logger.error('Error retrieving teams leaderboard', error as Error);
return Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'Failed to retrieve teams leaderboard' } });