resolve todos in website and api
This commit is contained in:
@@ -10,7 +10,10 @@ import { DriverExtendedProfileProvider } from '@core/racing/application/ports/Dr
|
||||
import { IImageServicePort } from '@core/racing/application/ports/IImageServicePort';
|
||||
import { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';
|
||||
import { INotificationPreferenceRepository } from '@core/notifications/domain/repositories/INotificationPreferenceRepository';
|
||||
import type { Logger } from "@core/shared/application";
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { ITeamRepository } from '@core/racing/domain/repositories/ITeamRepository';
|
||||
import type { ITeamMembershipRepository } from '@core/racing/domain/repositories/ITeamMembershipRepository';
|
||||
import type { ISocialGraphRepository } from '@core/social/domain/repositories/ISocialGraphRepository';
|
||||
|
||||
// Import use cases
|
||||
import { GetDriversLeaderboardUseCase } from '@core/racing/application/use-cases/GetDriversLeaderboardUseCase';
|
||||
@@ -29,6 +32,9 @@ import { InMemoryDriverExtendedProfileProvider } from '@adapters/racing/ports/In
|
||||
import { InMemoryImageServiceAdapter } from '@adapters/media/ports/InMemoryImageServiceAdapter';
|
||||
import { InMemoryRaceRegistrationRepository } from '@adapters/racing/persistence/inmemory/InMemoryRaceRegistrationRepository';
|
||||
import { InMemoryNotificationPreferenceRepository } from '@adapters/notifications/persistence/inmemory/InMemoryNotificationPreferenceRepository';
|
||||
import { InMemoryTeamRepository } from '@adapters/racing/persistence/inmemory/InMemoryTeamRepository';
|
||||
import { InMemoryTeamMembershipRepository } from '@adapters/racing/persistence/inmemory/InMemoryTeamMembershipRepository';
|
||||
import { InMemorySocialGraphRepository } from '@core/social/infrastructure/inmemory/InMemorySocialAndFeed';
|
||||
import { ConsoleLogger } from '@adapters/logging/ConsoleLogger';
|
||||
|
||||
// Define injection tokens
|
||||
@@ -40,6 +46,9 @@ export const DRIVER_EXTENDED_PROFILE_PROVIDER_TOKEN = 'DriverExtendedProfileProv
|
||||
export const IMAGE_SERVICE_PORT_TOKEN = 'IImageServicePort';
|
||||
export const RACE_REGISTRATION_REPOSITORY_TOKEN = 'IRaceRegistrationRepository';
|
||||
export const NOTIFICATION_PREFERENCE_REPOSITORY_TOKEN = 'INotificationPreferenceRepository';
|
||||
export const TEAM_REPOSITORY_TOKEN = 'ITeamRepository';
|
||||
export const TEAM_MEMBERSHIP_REPOSITORY_TOKEN = 'ITeamMembershipRepository';
|
||||
export const SOCIAL_GRAPH_REPOSITORY_TOKEN = 'ISocialGraphRepository';
|
||||
export const LOGGER_TOKEN = 'Logger'; // Already defined in AuthProviders, but good to have here too
|
||||
|
||||
// Use case tokens
|
||||
@@ -92,6 +101,22 @@ export const DriverProviders: Provider[] = [
|
||||
useFactory: (logger: Logger) => new InMemoryNotificationPreferenceRepository(logger),
|
||||
inject: [LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
provide: TEAM_REPOSITORY_TOKEN,
|
||||
useFactory: (logger: Logger) => new InMemoryTeamRepository(logger),
|
||||
inject: [LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
provide: TEAM_MEMBERSHIP_REPOSITORY_TOKEN,
|
||||
useFactory: (logger: Logger) => new InMemoryTeamMembershipRepository(logger),
|
||||
inject: [LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
provide: SOCIAL_GRAPH_REPOSITORY_TOKEN,
|
||||
useFactory: (logger: Logger) =>
|
||||
new InMemorySocialGraphRepository(logger, { drivers: [], friendships: [], feedEvents: [] }),
|
||||
inject: [LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
provide: LOGGER_TOKEN,
|
||||
useClass: ConsoleLogger,
|
||||
@@ -99,8 +124,13 @@ export const DriverProviders: Provider[] = [
|
||||
// Use cases
|
||||
{
|
||||
provide: GET_DRIVERS_LEADERBOARD_USE_CASE_TOKEN,
|
||||
useFactory: (driverRepo: IDriverRepository, rankingService: IRankingService, driverStatsService: IDriverStatsService, imageService: IImageServicePort, logger: Logger) =>
|
||||
new GetDriversLeaderboardUseCase(driverRepo, rankingService, driverStatsService, imageService, logger),
|
||||
useFactory: (
|
||||
driverRepo: IDriverRepository,
|
||||
rankingService: IRankingService,
|
||||
driverStatsService: IDriverStatsService,
|
||||
imageService: IImageServicePort,
|
||||
logger: Logger,
|
||||
) => new GetDriversLeaderboardUseCase(driverRepo, rankingService, driverStatsService, imageService, logger),
|
||||
inject: [DRIVER_REPOSITORY_TOKEN, RANKING_SERVICE_TOKEN, DRIVER_STATS_SERVICE_TOKEN, IMAGE_SERVICE_PORT_TOKEN, LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
@@ -115,7 +145,8 @@ export const DriverProviders: Provider[] = [
|
||||
},
|
||||
{
|
||||
provide: IS_DRIVER_REGISTERED_FOR_RACE_USE_CASE_TOKEN,
|
||||
useFactory: (registrationRepo: IRaceRegistrationRepository, logger: Logger) => new IsDriverRegisteredForRaceUseCase(registrationRepo, logger),
|
||||
useFactory: (registrationRepo: IRaceRegistrationRepository, logger: Logger) =>
|
||||
new IsDriverRegisteredForRaceUseCase(registrationRepo, logger),
|
||||
inject: [RACE_REGISTRATION_REPOSITORY_TOKEN, LOGGER_TOKEN],
|
||||
},
|
||||
{
|
||||
@@ -125,18 +156,59 @@ export const DriverProviders: Provider[] = [
|
||||
},
|
||||
{
|
||||
provide: GET_PROFILE_OVERVIEW_USE_CASE_TOKEN,
|
||||
useFactory: (driverRepo: IDriverRepository, imageService: IImageServicePort, driverExtendedProfileProvider: DriverExtendedProfileProvider, logger: Logger) =>
|
||||
useFactory: (
|
||||
driverRepo: IDriverRepository,
|
||||
teamRepository: ITeamRepository,
|
||||
teamMembershipRepository: ITeamMembershipRepository,
|
||||
socialRepository: ISocialGraphRepository,
|
||||
imageService: IImageServicePort,
|
||||
driverExtendedProfileProvider: DriverExtendedProfileProvider,
|
||||
driverStatsService: IDriverStatsService,
|
||||
rankingService: IRankingService,
|
||||
) =>
|
||||
new GetProfileOverviewUseCase(
|
||||
driverRepo,
|
||||
// TODO: Add teamRepository, teamMembershipRepository, socialRepository, etc.
|
||||
null as any, // teamRepository
|
||||
null as any, // teamMembershipRepository
|
||||
null as any, // socialRepository
|
||||
teamRepository,
|
||||
teamMembershipRepository,
|
||||
socialRepository,
|
||||
imageService,
|
||||
driverExtendedProfileProvider,
|
||||
() => null, // getDriverStats
|
||||
() => [], // getAllDriverRankings
|
||||
(driverId: string) => {
|
||||
const stats = driverStatsService.getDriverStats(driverId);
|
||||
if (!stats) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
rating: stats.rating,
|
||||
wins: stats.wins,
|
||||
podiums: stats.podiums,
|
||||
dnfs: 0,
|
||||
totalRaces: stats.totalRaces,
|
||||
avgFinish: null,
|
||||
bestFinish: null,
|
||||
worstFinish: null,
|
||||
overallRank: stats.overallRank,
|
||||
consistency: null,
|
||||
percentile: null,
|
||||
};
|
||||
},
|
||||
() =>
|
||||
rankingService.getAllDriverRankings().map(ranking => ({
|
||||
driverId: ranking.driverId,
|
||||
rating: ranking.rating,
|
||||
overallRank: ranking.overallRank,
|
||||
})),
|
||||
),
|
||||
inject: [DRIVER_REPOSITORY_TOKEN, IMAGE_SERVICE_PORT_TOKEN, DRIVER_EXTENDED_PROFILE_PROVIDER_TOKEN, LOGGER_TOKEN],
|
||||
inject: [
|
||||
DRIVER_REPOSITORY_TOKEN,
|
||||
TEAM_REPOSITORY_TOKEN,
|
||||
TEAM_MEMBERSHIP_REPOSITORY_TOKEN,
|
||||
SOCIAL_GRAPH_REPOSITORY_TOKEN,
|
||||
IMAGE_SERVICE_PORT_TOKEN,
|
||||
DRIVER_EXTENDED_PROFILE_PROVIDER_TOKEN,
|
||||
DRIVER_STATS_SERVICE_TOKEN,
|
||||
RANKING_SERVICE_TOKEN,
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
id: 'driver-1',
|
||||
name: 'Driver One',
|
||||
rating: 2500,
|
||||
skillLevel: 'Pro',
|
||||
skillLevel: 'advanced',
|
||||
nationality: 'US',
|
||||
racesCompleted: 50,
|
||||
wins: 10,
|
||||
@@ -64,7 +64,7 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
id: 'driver-2',
|
||||
name: 'Driver Two',
|
||||
rating: 2400,
|
||||
skillLevel: 'Pro',
|
||||
skillLevel: 'intermediate',
|
||||
nationality: 'DE',
|
||||
racesCompleted: 40,
|
||||
wins: 5,
|
||||
@@ -137,6 +137,45 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
expect(result.drivers[0].racesCompleted).toBe(0);
|
||||
expect(result.drivers[0].wins).toBe(0);
|
||||
expect(result.drivers[0].podiums).toBe(0);
|
||||
expect(result.drivers[0].isActive).toBe(false);
|
||||
});
|
||||
|
||||
it('should derive skill level from rating bands', () => {
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers: [
|
||||
{ id: 'd1', name: 'Beginner', country: 'US', iracingId: '1', joinedAt: new Date() },
|
||||
{ id: 'd2', name: 'Intermediate', country: 'US', iracingId: '2', joinedAt: new Date() },
|
||||
{ id: 'd3', name: 'Advanced', country: 'US', iracingId: '3', joinedAt: new Date() },
|
||||
{ id: 'd4', name: 'Pro', country: 'US', iracingId: '4', joinedAt: new Date() },
|
||||
],
|
||||
rankings: [
|
||||
{ driverId: 'd1', rating: 1700, overallRank: 4 },
|
||||
{ driverId: 'd2', rating: 2000, overallRank: 3 },
|
||||
{ driverId: 'd3', rating: 2600, overallRank: 2 },
|
||||
{ driverId: 'd4', rating: 3100, overallRank: 1 },
|
||||
],
|
||||
stats: {
|
||||
d1: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d2: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d3: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
d4: { racesCompleted: 5, wins: 0, podiums: 0 },
|
||||
},
|
||||
avatarUrls: {
|
||||
d1: 'avatar-1',
|
||||
d2: 'avatar-2',
|
||||
d3: 'avatar-3',
|
||||
d4: 'avatar-4',
|
||||
},
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
const result = presenter.viewModel;
|
||||
|
||||
const levels = result.drivers
|
||||
.sort((a, b) => a.rating - b.rating)
|
||||
.map(d => d.skillLevel);
|
||||
|
||||
expect(levels).toEqual(['beginner', 'intermediate', 'advanced', 'pro']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DriversLeaderboardDTO, DriverLeaderboardItemDTO } from '../dtos/DriversLeaderboardDTO';
|
||||
import { DriversLeaderboardDTO } from '../dtos/DriversLeaderboardDTO';
|
||||
import { DriverLeaderboardItemDTO } from '../dtos/DriverLeaderboardItemDTO';
|
||||
import type { IDriversLeaderboardPresenter, DriversLeaderboardResultDTO } from '../../../../../core/racing/application/presenters/IDriversLeaderboardPresenter';
|
||||
import { SkillLevelService } from '../../../../../core/racing/domain/services/SkillLevelService';
|
||||
|
||||
export class DriversLeaderboardPresenter implements IDriversLeaderboardPresenter {
|
||||
private result: DriversLeaderboardDTO | null = null;
|
||||
@@ -15,16 +16,21 @@ export class DriversLeaderboardPresenter implements IDriversLeaderboardPresenter
|
||||
const stats = dto.stats[driver.id];
|
||||
const avatarUrl = dto.avatarUrls[driver.id];
|
||||
|
||||
const rating = ranking?.rating ?? 0;
|
||||
const racesCompleted = stats?.racesCompleted ?? 0;
|
||||
|
||||
return {
|
||||
id: driver.id,
|
||||
name: driver.name,
|
||||
rating: ranking?.rating ?? 0,
|
||||
skillLevel: 'Pro', // TODO: map from domain
|
||||
rating,
|
||||
// Use core SkillLevelService to derive band from rating
|
||||
skillLevel: SkillLevelService.getSkillLevel(rating),
|
||||
nationality: driver.country,
|
||||
racesCompleted: stats?.racesCompleted ?? 0,
|
||||
racesCompleted,
|
||||
wins: stats?.wins ?? 0,
|
||||
podiums: stats?.podiums ?? 0,
|
||||
isActive: true, // TODO: determine from domain
|
||||
// Consider a driver active if they have completed at least one race
|
||||
isActive: racesCompleted > 0,
|
||||
rank: ranking?.overallRank ?? 0,
|
||||
avatarUrl,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user