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

@@ -1,15 +1,26 @@
import { GetAllTeamsOutputPort } from '@core/racing/application/ports/output/GetAllTeamsOutputPort';
import type { GetAllTeamsErrorCode, GetAllTeamsResult } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { GetAllTeamsOutputDTO } from '../dtos/GetAllTeamsOutputDTO';
export class AllTeamsPresenter {
private result: GetAllTeamsOutputDTO | null = null;
export type GetAllTeamsError = ApplicationErrorCode<GetAllTeamsErrorCode, { message: string }>;
reset() {
this.result = null;
export class AllTeamsPresenter {
private model: GetAllTeamsOutputDTO | null = null;
reset(): void {
this.model = null;
}
async present(output: GetAllTeamsOutputPort) {
this.result = {
present(result: Result<GetAllTeamsResult, GetAllTeamsError>): void {
if (result.isErr()) {
const error = result.unwrapErr();
throw new Error(error.details?.message ?? 'Failed to get teams');
}
const output = result.unwrap();
this.model = {
teams: output.teams.map(team => ({
id: team.id,
name: team.name,
@@ -17,18 +28,18 @@ export class AllTeamsPresenter {
description: team.description,
memberCount: team.memberCount,
leagues: team.leagues || [],
// Note: specialization, region, languages not available in output port
// Note: specialization, region, languages not available in output
})),
totalCount: output.totalCount || output.teams.length,
totalCount: output.totalCount ?? output.teams.length,
};
}
getViewModel(): GetAllTeamsOutputDTO | null {
return this.result;
getResponseModel(): GetAllTeamsOutputDTO | null {
return this.model;
}
get viewModel(): GetAllTeamsOutputDTO {
if (!this.result) throw new Error('Presenter not presented');
return this.result;
get responseModel(): GetAllTeamsOutputDTO {
if (!this.model) throw new Error('Presenter not presented');
return this.model;
}
}