47 lines
1.8 KiB
Dart
47 lines
1.8 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../../core/network/dio_client.dart';
|
|
import '../../data/datasources/dashboard_datasource.dart';
|
|
import '../../data/repositories/dashboard_repository_impl.dart';
|
|
import '../../domain/entities/dashboard_summary.dart';
|
|
import '../../domain/entities/recent_operation.dart';
|
|
import '../../domain/entities/server_status.dart';
|
|
import '../../domain/repositories/dashboard_repository.dart';
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Dependency providers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
final dashboardDatasourceProvider = Provider<DashboardDatasource>((ref) {
|
|
final dio = ref.watch(dioClientProvider);
|
|
return DashboardDatasource(dio);
|
|
});
|
|
|
|
final dashboardRepositoryProvider = Provider<DashboardRepository>((ref) {
|
|
final datasource = ref.watch(dashboardDatasourceProvider);
|
|
return DashboardRepositoryImpl(datasource);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Data providers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/// Provides the aggregated dashboard summary.
|
|
final dashboardSummaryProvider = FutureProvider<DashboardSummary>((ref) async {
|
|
final repository = ref.watch(dashboardRepositoryProvider);
|
|
return repository.getSummary();
|
|
});
|
|
|
|
/// Provides the list of recent operations.
|
|
final recentOperationsProvider =
|
|
FutureProvider<List<RecentOperation>>((ref) async {
|
|
final repository = ref.watch(dashboardRepositoryProvider);
|
|
return repository.getRecentOperations();
|
|
});
|
|
|
|
/// Provides the status of all servers.
|
|
final serverStatusesProvider =
|
|
FutureProvider<List<ServerStatus>>((ref) async {
|
|
final repository = ref.watch(dashboardRepositoryProvider);
|
|
return repository.getServerStatuses();
|
|
});
|