view models
This commit is contained in:
@@ -1,50 +1,30 @@
|
||||
import { AnalyticsApiClient } from '../../api/analytics/AnalyticsApiClient';
|
||||
import { AnalyticsDashboardPresenter } from '../../presenters/AnalyticsDashboardPresenter';
|
||||
import { AnalyticsMetricsPresenter } from '../../presenters/AnalyticsMetricsPresenter';
|
||||
import type { AnalyticsDashboardViewModel, AnalyticsMetricsViewModel } from '../../view-models';
|
||||
import { AnalyticsDashboardViewModel, AnalyticsMetricsViewModel } from '../../view-models';
|
||||
|
||||
/**
|
||||
* Dashboard Service
|
||||
*
|
||||
* Orchestrates dashboard operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates dashboard operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class DashboardService {
|
||||
constructor(
|
||||
private readonly apiClient: AnalyticsApiClient,
|
||||
private readonly analyticsDashboardPresenter: AnalyticsDashboardPresenter,
|
||||
private readonly analyticsMetricsPresenter: AnalyticsMetricsPresenter
|
||||
private readonly apiClient: AnalyticsApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get dashboard data with presentation transformation
|
||||
* Get dashboard data with view model transformation
|
||||
*/
|
||||
async getDashboardData(): Promise<AnalyticsDashboardViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.getDashboardData();
|
||||
return this.analyticsDashboardPresenter.present(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
const dto = await this.apiClient.getDashboardData();
|
||||
return new AnalyticsDashboardViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get analytics metrics with presentation transformation
|
||||
* Get analytics metrics with view model transformation
|
||||
*/
|
||||
async getAnalyticsMetrics(): Promise<AnalyticsMetricsViewModel> {
|
||||
try {
|
||||
const dto = await this.apiClient.getAnalyticsMetrics();
|
||||
return this.analyticsMetricsPresenter.present(dto);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dashboard overview (legacy method for backward compatibility)
|
||||
* TODO: Remove when no longer needed
|
||||
*/
|
||||
async getDashboardOverview(): Promise<AnalyticsDashboardViewModel> {
|
||||
return this.getDashboardData();
|
||||
const dto = await this.apiClient.getAnalyticsMetrics();
|
||||
return new AnalyticsMetricsViewModel(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user