refactor dtos to ports
This commit is contained in:
@@ -5,7 +5,8 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
|
||||
import type { IStandingRepository } from '../../domain/repositories/IStandingRepository';
|
||||
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
|
||||
import type { IRaceRegistrationRepository } from '../../domain/repositories/IRaceRegistrationRepository';
|
||||
import type { IImageServicePort } from '../ports/IImageServicePort';
|
||||
import type { GetDriverAvatarInputPort } from '../ports/input/GetDriverAvatarInputPort';
|
||||
import type { GetDriverAvatarOutputPort } from '../ports/output/GetDriverAvatarOutputPort';
|
||||
import type { IFeedRepository } from '@core/social/domain/repositories/IFeedRepository';
|
||||
import type { ISocialGraphRepository } from '@core/social/domain/repositories/ISocialGraphRepository';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
@@ -50,7 +51,7 @@ export class DashboardOverviewUseCase {
|
||||
private readonly raceRegistrationRepository: IRaceRegistrationRepository,
|
||||
private readonly feedRepository: IFeedRepository,
|
||||
private readonly socialRepository: ISocialGraphRepository,
|
||||
private readonly imageService: IImageServicePort,
|
||||
private readonly getDriverAvatar: (input: GetDriverAvatarInputPort) => Promise<GetDriverAvatarOutputPort>,
|
||||
private readonly getDriverStats: (driverId: string) => DashboardDriverStatsAdapter | null,
|
||||
) {}
|
||||
|
||||
@@ -75,7 +76,7 @@ export class DashboardOverviewUseCase {
|
||||
id: driver.id,
|
||||
name: driver.name,
|
||||
country: driver.country,
|
||||
avatarUrl: this.imageService.getDriverAvatar(driver.id),
|
||||
avatarUrl: (await this.getDriverAvatar({ driverId: driver.id })).avatarUrl,
|
||||
rating: driverStats?.rating ?? null,
|
||||
globalRank: driverStats?.overallRank ?? null,
|
||||
totalRaces: driverStats?.totalRaces ?? 0,
|
||||
@@ -125,7 +126,7 @@ export class DashboardOverviewUseCase {
|
||||
|
||||
const feedSummary = this.buildFeedSummary(feedItems);
|
||||
|
||||
const friendsSummary = this.buildFriendsSummary(friends);
|
||||
const friendsSummary = await this.buildFriendsSummary(friends);
|
||||
|
||||
const viewModel: DashboardOverviewViewModel = {
|
||||
currentDriver,
|
||||
@@ -302,12 +303,19 @@ export class DashboardOverviewUseCase {
|
||||
};
|
||||
}
|
||||
|
||||
private buildFriendsSummary(friends: Driver[]): DashboardFriendSummaryViewModel[] {
|
||||
return friends.map(friend => ({
|
||||
id: friend.id,
|
||||
name: friend.name,
|
||||
country: friend.country,
|
||||
avatarUrl: this.imageService.getDriverAvatar(friend.id),
|
||||
}));
|
||||
private async buildFriendsSummary(friends: Driver[]): Promise<DashboardFriendSummaryViewModel[]> {
|
||||
const friendSummaries: DashboardFriendSummaryViewModel[] = [];
|
||||
|
||||
for (const friend of friends) {
|
||||
const avatarResult = await this.getDriverAvatar({ driverId: friend.id });
|
||||
friendSummaries.push({
|
||||
id: friend.id,
|
||||
name: friend.name,
|
||||
country: friend.country,
|
||||
avatarUrl: avatarResult.avatarUrl,
|
||||
});
|
||||
}
|
||||
|
||||
return friendSummaries;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user