presenter refactoring

This commit is contained in:
2025-12-20 17:06:11 +01:00
parent 92be9d2e1b
commit e9d6f90bb2
109 changed files with 4159 additions and 1283 deletions

View File

@@ -25,14 +25,16 @@ export class DriverController {
@ApiOperation({ summary: 'Get drivers leaderboard' })
@ApiResponse({ status: 200, description: 'List of drivers for the leaderboard', type: DriversLeaderboardDTO })
async getDriversLeaderboard(): Promise<DriversLeaderboardDTO> {
return this.driverService.getDriversLeaderboard();
const presenter = await this.driverService.getDriversLeaderboard();
return presenter.viewModel;
}
@Get('total-drivers')
@ApiOperation({ summary: 'Get the total number of drivers' })
@ApiResponse({ status: 200, description: 'Total number of drivers', type: DriverStatsDTO })
async getTotalDrivers(): Promise<DriverStatsDTO> {
return this.driverService.getTotalDrivers();
const presenter = await this.driverService.getTotalDrivers();
return presenter.viewModel;
}
@Get('current')
@@ -40,12 +42,13 @@ export class DriverController {
@ApiResponse({ status: 200, description: 'Current driver data', type: GetDriverOutputDTO })
@ApiResponse({ status: 404, description: 'Driver not found' })
async getCurrentDriver(@Req() req: AuthenticatedRequest): Promise<GetDriverOutputDTO | null> {
// Assuming userId is available from the request (e.g., via auth middleware)
const userId = req.user?.userId;
if (!userId) {
return null;
}
return this.driverService.getCurrentDriver(userId);
const presenter = await this.driverService.getCurrentDriver(userId);
return presenter.viewModel;
}
@Post('complete-onboarding')
@@ -55,9 +58,9 @@ export class DriverController {
@Body() input: CompleteOnboardingInputDTO,
@Req() req: AuthenticatedRequest,
): Promise<CompleteOnboardingOutputDTO> {
// Assuming userId is available from the request (e.g., via auth middleware)
const userId = req.user!.userId; // Placeholder for actual user extraction
return this.driverService.completeOnboarding(userId, input);
const userId = req.user!.userId;
const presenter = await this.driverService.completeOnboarding(userId, input);
return presenter.viewModel;
}
@Get(':driverId/races/:raceId/registration-status')
@@ -67,7 +70,8 @@ export class DriverController {
@Param('driverId') driverId: string,
@Param('raceId') raceId: string,
): Promise<DriverRegistrationStatusDTO> {
return this.driverService.getDriverRegistrationStatus({ driverId, raceId });
const presenter = await this.driverService.getDriverRegistrationStatus({ driverId, raceId });
return presenter.viewModel;
}
@Get(':driverId')
@@ -75,7 +79,8 @@ export class DriverController {
@ApiResponse({ status: 200, description: 'Driver data', type: GetDriverOutputDTO })
@ApiResponse({ status: 404, description: 'Driver not found' })
async getDriver(@Param('driverId') driverId: string): Promise<GetDriverOutputDTO | null> {
return this.driverService.getDriver(driverId);
const presenter = await this.driverService.getDriver(driverId);
return presenter.viewModel;
}
@Get(':driverId/profile')
@@ -83,7 +88,8 @@ export class DriverController {
@ApiResponse({ status: 200, description: 'Driver profile data', type: GetDriverProfileOutputDTO })
@ApiResponse({ status: 404, description: 'Driver not found' })
async getDriverProfile(@Param('driverId') driverId: string): Promise<GetDriverProfileOutputDTO> {
return this.driverService.getDriverProfile(driverId);
const presenter = await this.driverService.getDriverProfile(driverId);
return presenter.viewModel;
}
@Put(':driverId/profile')
@@ -93,7 +99,8 @@ export class DriverController {
@Param('driverId') driverId: string,
@Body() body: { bio?: string; country?: string },
): Promise<GetDriverOutputDTO | null> {
return this.driverService.updateDriverProfile(driverId, body.bio, body.country);
const presenter = await this.driverService.updateDriverProfile(driverId, body.bio, body.country);
return presenter.viewModel;
}
// Add other Driver endpoints here based on other presenters