Showing
10 changed files
with
222 additions
and
22 deletions
| 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource_wrapper.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/datasource/health/health_local_datasource.dart'; | ||
| 5 | +import 'package:doublefeel_flutter/data/datasource/health/health_remote_datasource.dart'; | ||
| 2 | import 'package:get/get.dart'; | 6 | import 'package:get/get.dart'; |
| 3 | 7 | ||
| 4 | import '../../report_common/controllers/report_period_logic.dart'; | 8 | import '../../report_common/controllers/report_period_logic.dart'; |
| @@ -14,7 +18,7 @@ class ActivityBurnReportLogic extends ReportPeriodLogic { | @@ -14,7 +18,7 @@ class ActivityBurnReportLogic extends ReportPeriodLogic { | ||
| 14 | }) : repository = repository ?? | 18 | }) : repository = repository ?? |
| 15 | ActivityBurnReportRepositoryImpl( | 19 | ActivityBurnReportRepositoryImpl( |
| 16 | dataSource: | 20 | dataSource: |
| 17 | - ApiActivityBurnReportDataSource(Get.find<HealthApi>()), | 21 | + ApiActivityBurnReportDataSource(_healthDataSource()), |
| 18 | ) { | 22 | ) { |
| 19 | targetUserId.value = initialTargetUserId; | 23 | targetUserId.value = initialTargetUserId; |
| 20 | } | 24 | } |
| @@ -23,6 +27,11 @@ class ActivityBurnReportLogic extends ReportPeriodLogic { | @@ -23,6 +27,11 @@ class ActivityBurnReportLogic extends ReportPeriodLogic { | ||
| 23 | 27 | ||
| 24 | final ActivityBurnReportRepository repository; | 28 | final ActivityBurnReportRepository repository; |
| 25 | 29 | ||
| 30 | + static HealthDataSource _healthDataSource() => HealthDataSourceWrapper( | ||
| 31 | + remoteDataSource: RemoteHealthDataSource(Get.find<HealthApi>()), | ||
| 32 | + localDataSource: const LocalHealthDataSource(), | ||
| 33 | + ); | ||
| 34 | + | ||
| 26 | final report = Rxn<ActivityBurnReport>(); | 35 | final report = Rxn<ActivityBurnReport>(); |
| 27 | final weeklyReport = Rxn<WeeklyActivityBurnReport>(); | 36 | final weeklyReport = Rxn<WeeklyActivityBurnReport>(); |
| 28 | final monthlyReport = Rxn<MonthlyActivityBurnReport>(); | 37 | final monthlyReport = Rxn<MonthlyActivityBurnReport>(); |
| 1 | -import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | ||
| 2 | import 'package:doublefeel_flutter/core/result/app_result.dart'; | 1 | import 'package:doublefeel_flutter/core/result/app_result.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; | 3 | import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; |
| 4 | 4 | ||
| 5 | import '../models/activity_burn_report_models.dart'; | 5 | import '../models/activity_burn_report_models.dart'; |
| @@ -22,13 +22,13 @@ abstract class ActivityBurnReportDataSource { | @@ -22,13 +22,13 @@ abstract class ActivityBurnReportDataSource { | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | 24 | class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { |
| 25 | - const ApiActivityBurnReportDataSource(this._healthApi); | 25 | + const ApiActivityBurnReportDataSource(this._healthDataSource); |
| 26 | 26 | ||
| 27 | static const _weekDateRangeType = 0; | 27 | static const _weekDateRangeType = 0; |
| 28 | static const _monthDateRangeType = 1; | 28 | static const _monthDateRangeType = 1; |
| 29 | static const _dayDateRangeType = 3; | 29 | static const _dayDateRangeType = 3; |
| 30 | 30 | ||
| 31 | - final HealthApi _healthApi; | 31 | + final HealthDataSource _healthDataSource; |
| 32 | 32 | ||
| 33 | @override | 33 | @override |
| 34 | Future<ActivityBurnReport> fetchDailyReport( | 34 | Future<ActivityBurnReport> fetchDailyReport( |
| @@ -36,7 +36,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | @@ -36,7 +36,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | ||
| 36 | int? targetUserId, | 36 | int? targetUserId, |
| 37 | }) async { | 37 | }) async { |
| 38 | final day = _normalizeDate(date); | 38 | final day = _normalizeDate(date); |
| 39 | - final result = await _healthApi.getActivityBurnStatistics( | 39 | + final result = await _healthDataSource.getActivityBurnStatistics( |
| 40 | _dayDateRangeType, | 40 | _dayDateRangeType, |
| 41 | _dateKey(day), | 41 | _dateKey(day), |
| 42 | queryUserId: targetUserId, | 42 | queryUserId: targetUserId, |
| @@ -53,7 +53,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | @@ -53,7 +53,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | ||
| 53 | int? targetUserId, | 53 | int? targetUserId, |
| 54 | }) async { | 54 | }) async { |
| 55 | final start = _normalizeDate(weekStart); | 55 | final start = _normalizeDate(weekStart); |
| 56 | - final result = await _healthApi.getActivityBurnStatistics( | 56 | + final result = await _healthDataSource.getActivityBurnStatistics( |
| 57 | _weekDateRangeType, | 57 | _weekDateRangeType, |
| 58 | _dateKey(start), | 58 | _dateKey(start), |
| 59 | queryUserId: targetUserId, | 59 | queryUserId: targetUserId, |
| @@ -81,7 +81,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | @@ -81,7 +81,7 @@ class ApiActivityBurnReportDataSource implements ActivityBurnReportDataSource { | ||
| 81 | }) async { | 81 | }) async { |
| 82 | final start = DateTime(monthStart.year, monthStart.month); | 82 | final start = DateTime(monthStart.year, monthStart.month); |
| 83 | final end = DateTime(start.year, start.month + 1, 0); | 83 | final end = DateTime(start.year, start.month + 1, 0); |
| 84 | - final result = await _healthApi.getActivityBurnStatistics( | 84 | + final result = await _healthDataSource.getActivityBurnStatistics( |
| 85 | _monthDateRangeType, | 85 | _monthDateRangeType, |
| 86 | _dateKey(start), | 86 | _dateKey(start), |
| 87 | queryUserId: targetUserId, | 87 | queryUserId: targetUserId, |
| @@ -317,4 +317,4 @@ class _SleepRange { | @@ -317,4 +317,4 @@ class _SleepRange { | ||
| 317 | 317 | ||
| 318 | final DateTime start; | 318 | final DateTime start; |
| 319 | final DateTime end; | 319 | final DateTime end; |
| 320 | -} | ||
| 320 | +} |
| 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource_wrapper.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/datasource/health/health_local_datasource.dart'; | ||
| 5 | +import 'package:doublefeel_flutter/data/datasource/health/health_remote_datasource.dart'; | ||
| 2 | import 'package:get/get.dart'; | 6 | import 'package:get/get.dart'; |
| 3 | 7 | ||
| 4 | import '../../report_common/controllers/report_period_logic.dart'; | 8 | import '../../report_common/controllers/report_period_logic.dart'; |
| @@ -13,7 +17,7 @@ class HrvReportLogic extends ReportPeriodLogic { | @@ -13,7 +17,7 @@ class HrvReportLogic extends ReportPeriodLogic { | ||
| 13 | HrvReportRepository? repository, | 17 | HrvReportRepository? repository, |
| 14 | }) : repository = repository ?? | 18 | }) : repository = repository ?? |
| 15 | HrvReportRepositoryImpl( | 19 | HrvReportRepositoryImpl( |
| 16 | - dataSource: ApiHrvReportDataSource(Get.find<HealthApi>()), | 20 | + dataSource: ApiHrvReportDataSource(_healthDataSource()), |
| 17 | ) { | 21 | ) { |
| 18 | targetUserId.value = initialTargetUserId; | 22 | targetUserId.value = initialTargetUserId; |
| 19 | selectedPeriod.value = ReportPeriod.week; | 23 | selectedPeriod.value = ReportPeriod.week; |
| @@ -25,6 +29,11 @@ class HrvReportLogic extends ReportPeriodLogic { | @@ -25,6 +29,11 @@ class HrvReportLogic extends ReportPeriodLogic { | ||
| 25 | final yearlyReport = Rxn<YearlyHrvReport>(); | 29 | final yearlyReport = Rxn<YearlyHrvReport>(); |
| 26 | final HrvReportRepository repository; | 30 | final HrvReportRepository repository; |
| 27 | 31 | ||
| 32 | + static HealthDataSource _healthDataSource() => HealthDataSourceWrapper( | ||
| 33 | + remoteDataSource: RemoteHealthDataSource(Get.find<HealthApi>()), | ||
| 34 | + localDataSource: const LocalHealthDataSource(), | ||
| 35 | + ); | ||
| 36 | + | ||
| 28 | @override | 37 | @override |
| 29 | List<ReportPeriod> get supportedPeriods => const [ | 38 | List<ReportPeriod> get supportedPeriods => const [ |
| 30 | ReportPeriod.week, | 39 | ReportPeriod.week, |
| 1 | -import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | ||
| 2 | import 'package:doublefeel_flutter/core/result/app_result.dart'; | 1 | import 'package:doublefeel_flutter/core/result/app_result.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; | 3 | import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; |
| 4 | 4 | ||
| 5 | import '../models/hrv_report_models.dart'; | 5 | import '../models/hrv_report_models.dart'; |
| @@ -22,13 +22,13 @@ abstract class HrvReportDataSource { | @@ -22,13 +22,13 @@ abstract class HrvReportDataSource { | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | class ApiHrvReportDataSource implements HrvReportDataSource { | 24 | class ApiHrvReportDataSource implements HrvReportDataSource { |
| 25 | - const ApiHrvReportDataSource(this._healthApi); | 25 | + const ApiHrvReportDataSource(this._healthDataSource); |
| 26 | 26 | ||
| 27 | static const _weekDateRangeType = 0; | 27 | static const _weekDateRangeType = 0; |
| 28 | static const _monthDateRangeType = 1; | 28 | static const _monthDateRangeType = 1; |
| 29 | static const _yearDateRangeType = 2; | 29 | static const _yearDateRangeType = 2; |
| 30 | 30 | ||
| 31 | - final HealthApi _healthApi; | 31 | + final HealthDataSource _healthDataSource; |
| 32 | 32 | ||
| 33 | @override | 33 | @override |
| 34 | Future<WeeklyHrvReport> fetchWeeklyReport( | 34 | Future<WeeklyHrvReport> fetchWeeklyReport( |
| @@ -36,7 +36,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | @@ -36,7 +36,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | ||
| 36 | int? targetUserId, | 36 | int? targetUserId, |
| 37 | }) async { | 37 | }) async { |
| 38 | final start = DateTime(weekStart.year, weekStart.month, weekStart.day); | 38 | final start = DateTime(weekStart.year, weekStart.month, weekStart.day); |
| 39 | - final result = await _healthApi.getHrvStatistics( | 39 | + final result = await _healthDataSource.getHrvStatistics( |
| 40 | _weekDateRangeType, | 40 | _weekDateRangeType, |
| 41 | _dateKey(start), | 41 | _dateKey(start), |
| 42 | queryUserId: targetUserId, | 42 | queryUserId: targetUserId, |
| @@ -53,7 +53,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | @@ -53,7 +53,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | ||
| 53 | int? targetUserId, | 53 | int? targetUserId, |
| 54 | }) async { | 54 | }) async { |
| 55 | final start = DateTime(monthStart.year, monthStart.month); | 55 | final start = DateTime(monthStart.year, monthStart.month); |
| 56 | - final result = await _healthApi.getHrvStatistics( | 56 | + final result = await _healthDataSource.getHrvStatistics( |
| 57 | _monthDateRangeType, | 57 | _monthDateRangeType, |
| 58 | _dateKey(start), | 58 | _dateKey(start), |
| 59 | queryUserId: targetUserId, | 59 | queryUserId: targetUserId, |
| @@ -70,7 +70,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | @@ -70,7 +70,7 @@ class ApiHrvReportDataSource implements HrvReportDataSource { | ||
| 70 | int? targetUserId, | 70 | int? targetUserId, |
| 71 | }) async { | 71 | }) async { |
| 72 | final start = DateTime(year); | 72 | final start = DateTime(year); |
| 73 | - final result = await _healthApi.getHrvStatistics( | 73 | + final result = await _healthDataSource.getHrvStatistics( |
| 74 | _yearDateRangeType, | 74 | _yearDateRangeType, |
| 75 | _dateKey(start), | 75 | _dateKey(start), |
| 76 | queryUserId: targetUserId, | 76 | queryUserId: targetUserId, |
| 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | 1 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource_wrapper.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/datasource/health/health_local_datasource.dart'; | ||
| 5 | +import 'package:doublefeel_flutter/data/datasource/health/health_remote_datasource.dart'; | ||
| 2 | import 'package:get/get.dart'; | 6 | import 'package:get/get.dart'; |
| 3 | 7 | ||
| 4 | import '../../report_common/controllers/report_period_logic.dart'; | 8 | import '../../report_common/controllers/report_period_logic.dart'; |
| @@ -13,7 +17,7 @@ class SleepReportLogic extends ReportPeriodLogic { | @@ -13,7 +17,7 @@ class SleepReportLogic extends ReportPeriodLogic { | ||
| 13 | SleepReportRepository? repository, | 17 | SleepReportRepository? repository, |
| 14 | }) : repository = repository ?? | 18 | }) : repository = repository ?? |
| 15 | SleepReportRepositoryImpl( | 19 | SleepReportRepositoryImpl( |
| 16 | - dataSource: ApiSleepReportDataSource(Get.find<HealthApi>()), | 20 | + dataSource: ApiSleepReportDataSource(_healthDataSource()), |
| 17 | ) { | 21 | ) { |
| 18 | targetUserId.value = initialTargetUserId; | 22 | targetUserId.value = initialTargetUserId; |
| 19 | } | 23 | } |
| @@ -22,6 +26,11 @@ class SleepReportLogic extends ReportPeriodLogic { | @@ -22,6 +26,11 @@ class SleepReportLogic extends ReportPeriodLogic { | ||
| 22 | 26 | ||
| 23 | final SleepReportRepository repository; | 27 | final SleepReportRepository repository; |
| 24 | 28 | ||
| 29 | + static HealthDataSource _healthDataSource() => HealthDataSourceWrapper( | ||
| 30 | + remoteDataSource: RemoteHealthDataSource(Get.find<HealthApi>()), | ||
| 31 | + localDataSource: const LocalHealthDataSource(), | ||
| 32 | + ); | ||
| 33 | + | ||
| 25 | final report = Rxn<SleepReport>(); | 34 | final report = Rxn<SleepReport>(); |
| 26 | final weeklyReport = Rxn<WeeklySleepReport>(); | 35 | final weeklyReport = Rxn<WeeklySleepReport>(); |
| 27 | final monthlyReport = Rxn<MonthlySleepReport>(); | 36 | final monthlyReport = Rxn<MonthlySleepReport>(); |
| 1 | -import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | ||
| 2 | import 'package:doublefeel_flutter/core/result/app_result.dart'; | 1 | import 'package:doublefeel_flutter/core/result/app_result.dart'; |
| 2 | +import 'package:doublefeel_flutter/data/datasource/health/health_datasource.dart'; | ||
| 3 | import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; | 3 | import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; |
| 4 | 4 | ||
| 5 | import '../models/sleep_report_models.dart'; | 5 | import '../models/sleep_report_models.dart'; |
| @@ -22,13 +22,13 @@ abstract class SleepReportDataSource { | @@ -22,13 +22,13 @@ abstract class SleepReportDataSource { | ||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | class ApiSleepReportDataSource implements SleepReportDataSource { | 24 | class ApiSleepReportDataSource implements SleepReportDataSource { |
| 25 | - const ApiSleepReportDataSource(this._healthApi); | 25 | + const ApiSleepReportDataSource(this._healthDataSource); |
| 26 | 26 | ||
| 27 | static const _weekDateRangeType = 0; | 27 | static const _weekDateRangeType = 0; |
| 28 | static const _monthDateRangeType = 1; | 28 | static const _monthDateRangeType = 1; |
| 29 | static const _dayDateRangeType = 3; | 29 | static const _dayDateRangeType = 3; |
| 30 | 30 | ||
| 31 | - final HealthApi _healthApi; | 31 | + final HealthDataSource _healthDataSource; |
| 32 | 32 | ||
| 33 | @override | 33 | @override |
| 34 | Future<SleepReport> fetchDailyReport( | 34 | Future<SleepReport> fetchDailyReport( |
| @@ -36,7 +36,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | @@ -36,7 +36,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | ||
| 36 | int? targetUserId, | 36 | int? targetUserId, |
| 37 | }) async { | 37 | }) async { |
| 38 | final day = _normalizeDate(date); | 38 | final day = _normalizeDate(date); |
| 39 | - final result = await _healthApi.getSleepStatistics( | 39 | + final result = await _healthDataSource.getSleepStatistics( |
| 40 | _dayDateRangeType, | 40 | _dayDateRangeType, |
| 41 | _dateKey(day), | 41 | _dateKey(day), |
| 42 | queryUserId: targetUserId, | 42 | queryUserId: targetUserId, |
| @@ -53,7 +53,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | @@ -53,7 +53,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | ||
| 53 | int? targetUserId, | 53 | int? targetUserId, |
| 54 | }) async { | 54 | }) async { |
| 55 | final start = _normalizeDate(weekStart); | 55 | final start = _normalizeDate(weekStart); |
| 56 | - final result = await _healthApi.getSleepStatistics( | 56 | + final result = await _healthDataSource.getSleepStatistics( |
| 57 | _weekDateRangeType, | 57 | _weekDateRangeType, |
| 58 | _dateKey(start), | 58 | _dateKey(start), |
| 59 | queryUserId: targetUserId, | 59 | queryUserId: targetUserId, |
| @@ -70,7 +70,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | @@ -70,7 +70,7 @@ class ApiSleepReportDataSource implements SleepReportDataSource { | ||
| 70 | int? targetUserId, | 70 | int? targetUserId, |
| 71 | }) async { | 71 | }) async { |
| 72 | final start = DateTime(monthStart.year, monthStart.month); | 72 | final start = DateTime(monthStart.year, monthStart.month); |
| 73 | - final result = await _healthApi.getSleepStatistics( | 73 | + final result = await _healthDataSource.getSleepStatistics( |
| 74 | _monthDateRangeType, | 74 | _monthDateRangeType, |
| 75 | _dateKey(start), | 75 | _dateKey(start), |
| 76 | queryUserId: targetUserId, | 76 | queryUserId: targetUserId, |
| 1 | +import 'package:doublefeel_flutter/core/result/app_result.dart'; | ||
| 2 | +import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; | ||
| 5 | + | ||
| 6 | +/// Data access contract shared by health features. | ||
| 7 | +abstract interface class HealthDataSource { | ||
| 8 | + Future<AppResult<SleepStatisticsData>> getSleepStatistics( | ||
| 9 | + int dateRangeType, | ||
| 10 | + int startDate, { | ||
| 11 | + int? queryUserId, | ||
| 12 | + }); | ||
| 13 | + | ||
| 14 | + Future<AppResult<ActivityBurnStatisticsDataV2>> getActivityBurnStatistics( | ||
| 15 | + int dateRangeType, | ||
| 16 | + int startDate, { | ||
| 17 | + int? queryUserId, | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + Future<AppResult<HrvStatisticsDataV2>> getHrvStatistics( | ||
| 21 | + int dateRangeType, | ||
| 22 | + int startDate, { | ||
| 23 | + int? queryUserId, | ||
| 24 | + }); | ||
| 25 | +} |
| 1 | +import 'package:doublefeel_flutter/core/result/app_result.dart'; | ||
| 2 | +import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; | ||
| 5 | + | ||
| 6 | +import 'health_datasource.dart'; | ||
| 7 | + | ||
| 8 | +/// Routes each report type to its current source of truth. | ||
| 9 | +class HealthDataSourceWrapper implements HealthDataSource { | ||
| 10 | + const HealthDataSourceWrapper({ | ||
| 11 | + required this.remoteDataSource, | ||
| 12 | + required this.localDataSource, | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + final HealthDataSource remoteDataSource; | ||
| 16 | + final HealthDataSource localDataSource; | ||
| 17 | + | ||
| 18 | + @override | ||
| 19 | + Future<AppResult<SleepStatisticsData>> getSleepStatistics( | ||
| 20 | + int dateRangeType, | ||
| 21 | + int startDate, { | ||
| 22 | + int? queryUserId, | ||
| 23 | + }) { | ||
| 24 | + return remoteDataSource.getSleepStatistics( | ||
| 25 | + dateRangeType, | ||
| 26 | + startDate, | ||
| 27 | + queryUserId: queryUserId, | ||
| 28 | + ); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @override | ||
| 32 | + Future<AppResult<ActivityBurnStatisticsDataV2>> getActivityBurnStatistics( | ||
| 33 | + int dateRangeType, | ||
| 34 | + int startDate, { | ||
| 35 | + int? queryUserId, | ||
| 36 | + }) { | ||
| 37 | + return localDataSource.getActivityBurnStatistics( | ||
| 38 | + dateRangeType, | ||
| 39 | + startDate, | ||
| 40 | + queryUserId: queryUserId, | ||
| 41 | + ); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @override | ||
| 45 | + Future<AppResult<HrvStatisticsDataV2>> getHrvStatistics( | ||
| 46 | + int dateRangeType, | ||
| 47 | + int startDate, { | ||
| 48 | + int? queryUserId, | ||
| 49 | + }) { | ||
| 50 | + return localDataSource.getHrvStatistics( | ||
| 51 | + dateRangeType, | ||
| 52 | + startDate, | ||
| 53 | + queryUserId: queryUserId, | ||
| 54 | + ); | ||
| 55 | + } | ||
| 56 | +} |
| 1 | +import 'package:doublefeel_flutter/core/result/app_result.dart'; | ||
| 2 | +import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; | ||
| 5 | + | ||
| 6 | +import 'health_datasource.dart'; | ||
| 7 | + | ||
| 8 | +/// Placeholder for the local health-data store. | ||
| 9 | +class LocalHealthDataSource implements HealthDataSource { | ||
| 10 | + const LocalHealthDataSource(); | ||
| 11 | + | ||
| 12 | + Never _notImplemented() => throw UnimplementedError( | ||
| 13 | + 'Local health data source has not been implemented.', | ||
| 14 | + ); | ||
| 15 | + | ||
| 16 | + @override | ||
| 17 | + Future<AppResult<SleepStatisticsData>> getSleepStatistics( | ||
| 18 | + int dateRangeType, | ||
| 19 | + int startDate, { | ||
| 20 | + int? queryUserId, | ||
| 21 | + }) => | ||
| 22 | + _notImplemented(); | ||
| 23 | + | ||
| 24 | + @override | ||
| 25 | + Future<AppResult<ActivityBurnStatisticsDataV2>> getActivityBurnStatistics( | ||
| 26 | + int dateRangeType, | ||
| 27 | + int startDate, { | ||
| 28 | + int? queryUserId, | ||
| 29 | + }) => | ||
| 30 | + _notImplemented(); | ||
| 31 | + | ||
| 32 | + @override | ||
| 33 | + Future<AppResult<HrvStatisticsDataV2>> getHrvStatistics( | ||
| 34 | + int dateRangeType, | ||
| 35 | + int startDate, { | ||
| 36 | + int? queryUserId, | ||
| 37 | + }) => | ||
| 38 | + _notImplemented(); | ||
| 39 | +} |
| 1 | +import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | ||
| 2 | +import 'package:doublefeel_flutter/core/result/app_result.dart'; | ||
| 3 | +import 'package:doublefeel_flutter/data/models/health/activity/activity_burn_statistics_data_v2.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/data/models/health/hrv/hrv_statistics_data.dart'; | ||
| 5 | +import 'package:doublefeel_flutter/data/models/health/sleep/sleep_statistics_data.dart'; | ||
| 6 | + | ||
| 7 | +import 'health_datasource.dart'; | ||
| 8 | + | ||
| 9 | +/// Remote implementation backed by the health API. | ||
| 10 | +class RemoteHealthDataSource implements HealthDataSource { | ||
| 11 | + const RemoteHealthDataSource(this._healthApi); | ||
| 12 | + | ||
| 13 | + final HealthApi _healthApi; | ||
| 14 | + | ||
| 15 | + @override | ||
| 16 | + Future<AppResult<SleepStatisticsData>> getSleepStatistics( | ||
| 17 | + int dateRangeType, | ||
| 18 | + int startDate, { | ||
| 19 | + int? queryUserId, | ||
| 20 | + }) { | ||
| 21 | + return _healthApi.getSleepStatistics( | ||
| 22 | + dateRangeType, | ||
| 23 | + startDate, | ||
| 24 | + queryUserId: queryUserId, | ||
| 25 | + ); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @override | ||
| 29 | + Future<AppResult<ActivityBurnStatisticsDataV2>> getActivityBurnStatistics( | ||
| 30 | + int dateRangeType, | ||
| 31 | + int startDate, { | ||
| 32 | + int? queryUserId, | ||
| 33 | + }) { | ||
| 34 | + return _healthApi.getActivityBurnStatistics( | ||
| 35 | + dateRangeType, | ||
| 36 | + startDate, | ||
| 37 | + queryUserId: queryUserId, | ||
| 38 | + ); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @override | ||
| 42 | + Future<AppResult<HrvStatisticsDataV2>> getHrvStatistics( | ||
| 43 | + int dateRangeType, | ||
| 44 | + int startDate, { | ||
| 45 | + int? queryUserId, | ||
| 46 | + }) { | ||
| 47 | + return _healthApi.getHrvStatistics( | ||
| 48 | + dateRangeType, | ||
| 49 | + startDate, | ||
| 50 | + queryUserId: queryUserId, | ||
| 51 | + ); | ||
| 52 | + } | ||
| 53 | +} |
-
Please register or login to post a comment