HydroNutrify_Ari_e41221567/lib/logic/controllers/flow_controller.dart

66 lines
2.4 KiB
Dart

import 'package:mobile_monitoring/data/models/service_result.dart';
import 'package:mobile_monitoring/data/services/auth_service.dart';
import 'package:mobile_monitoring/data/services/flow_service.dart';
import 'package:mobile_monitoring/data/services/hidroponik_data_service.dart';
import 'package:mobile_monitoring/data/services/planting_cycles_service.dart';
import 'package:mobile_monitoring/logic/controllers/base_controller.dart';
class FlowController extends BaseController {
FlowController({
FlowService? flowService,
AuthService? authService,
HidroponikDataService? hidroponikDataService,
PlantingCyclesService? plantingCyclesService,
}) : _flowService = flowService ?? FlowService(),
_authService = authService ?? AuthService(),
_hidroponikDataService = hidroponikDataService ?? HidroponikDataService(),
_plantingCyclesService = plantingCyclesService ?? PlantingCyclesService();
final FlowService _flowService;
final AuthService _authService;
final HidroponikDataService _hidroponikDataService;
final PlantingCyclesService _plantingCyclesService;
String? resolveUserId(String? pageUserId) {
return pageUserId ?? _authService.currentUser?.uid;
}
ServiceResult<FlowMonitoringData> parseMonitoringData(Map<String, dynamic> data) {
return _flowService.parseMonitoringDataResult(data);
}
ServiceResult<FlowDataError> mapError(Object error) {
return _flowService.getErrorInfoResult(error);
}
ServiceResult<bool> hasActiveCycle(Map<String, dynamic>? cycleData) {
return _flowService.hasActiveCycleResult(cycleData);
}
ServiceResult<DateTime?> extractStartDate(Map<String, dynamic>? cycleData) {
return _flowService.extractStartDateResult(cycleData);
}
ServiceResult<List<RecapRow>> generateRecapRows(
List<Map<String, dynamic>> docs,
DateTime? startDate,
) {
return _flowService.generateRecapRowsResult(docs, startDate);
}
Stream<Map<String, dynamic>?> latestDataStream(String? userId) {
return _hidroponikDataService.latestDataStream(userId: userId);
}
Stream<Map<String, dynamic>?> activeCycleStream(String userId) {
return _plantingCyclesService.getActiveCycleStream(userId: userId);
}
Stream<List<Map<String, dynamic>>> historyStream({
required int limit,
required String? userId,
}) {
return _hidroponikDataService.historyStream(limit: limit, userId: userId);
}
}