refactor driver module (wip)

This commit is contained in:
2025-12-22 01:43:34 +01:00
parent b445d6dd37
commit e7dbec4a85
31 changed files with 379 additions and 395 deletions

View File

@@ -1,4 +1,4 @@
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
import type { Logger, UseCase } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Driver } from '../../domain/entities/Driver';
@@ -42,21 +42,20 @@ export type GetDriversLeaderboardErrorCode =
* Use Case for retrieving driver leaderboard data.
* Returns a Result containing the domain leaderboard model.
*/
export class GetDriversLeaderboardUseCase {
export class GetDriversLeaderboardUseCase implements UseCase<GetDriversLeaderboardInput, GetDriversLeaderboardResult, GetDriversLeaderboardErrorCode> {
constructor(
private readonly driverRepository: IDriverRepository,
private readonly rankingService: IRankingService,
private readonly driverStatsService: IDriverStatsService,
private readonly getDriverAvatar: (driverId: string) => Promise<string | undefined>,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<GetDriversLeaderboardResult>,
) {}
async execute(
input: GetDriversLeaderboardInput,
): Promise<
Result<
void,
GetDriversLeaderboardResult,
ApplicationErrorCode<GetDriversLeaderboardErrorCode, { message: string }>
>
> {
@@ -108,9 +107,7 @@ export class GetDriversLeaderboardUseCase {
this.logger.debug('Successfully computed drivers leaderboard');
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));