11import 'package:core/core.dart' ;
22import 'package:data_repository/data_repository.dart' ;
3+ import 'package:logging/logging.dart' ; // Import Logger
34
45/// {@template demo_data_migration_service}
56/// A service responsible for migrating user data (settings and preferences)
@@ -11,16 +12,18 @@ import 'package:data_repository/data_repository.dart';
1112/// {@endtemplate}
1213class DemoDataMigrationService {
1314 /// {@macro demo_data_migration_service}
14- const DemoDataMigrationService ({
15+ DemoDataMigrationService ({
1516 required DataRepository <UserAppSettings > userAppSettingsRepository,
1617 required DataRepository <UserContentPreferences >
1718 userContentPreferencesRepository,
1819 }) : _userAppSettingsRepository = userAppSettingsRepository,
19- _userContentPreferencesRepository = userContentPreferencesRepository;
20+ _userContentPreferencesRepository = userContentPreferencesRepository,
21+ _logger = Logger ('DemoDataMigrationService' );
2022
2123 final DataRepository <UserAppSettings > _userAppSettingsRepository;
2224 final DataRepository <UserContentPreferences >
2325 _userContentPreferencesRepository;
26+ final Logger _logger;
2427
2528 /// Migrates user settings and content preferences from an old anonymous
2629 /// user ID to a new authenticated user ID.
@@ -31,7 +34,7 @@ class DemoDataMigrationService {
3134 required String oldUserId,
3235 required String newUserId,
3336 }) async {
34- print (
37+ _logger. info (
3538 '[DemoDataMigrationService] Attempting to migrate data from '
3639 'anonymous user ID: $oldUserId to authenticated user ID: $newUserId ' ,
3740 );
@@ -70,19 +73,21 @@ class DemoDataMigrationService {
7073 }
7174
7275 await _userAppSettingsRepository.delete (id: oldUserId, userId: oldUserId);
73- print (
76+ _logger. info (
7477 '[DemoDataMigrationService] UserAppSettings migrated successfully '
7578 'from $oldUserId to $newUserId .' ,
7679 );
7780 } on NotFoundException {
78- print (
81+ _logger. info (
7982 '[DemoDataMigrationService] No UserAppSettings found for old user ID: '
8083 '$oldUserId . Skipping migration for settings.' ,
8184 );
8285 } catch (e, s) {
83- print (
86+ _logger. severe (
8487 '[DemoDataMigrationService] Error migrating UserAppSettings from '
85- '$oldUserId to $newUserId : $e \n $s ' ,
88+ '$oldUserId to $newUserId : $e ' ,
89+ e,
90+ s,
8691 );
8792 }
8893
@@ -123,19 +128,21 @@ class DemoDataMigrationService {
123128 id: oldUserId,
124129 userId: oldUserId,
125130 );
126- print (
131+ _logger. info (
127132 '[DemoDataMigrationService] UserContentPreferences migrated '
128133 'successfully from $oldUserId to $newUserId .' ,
129134 );
130135 } on NotFoundException {
131- print (
136+ _logger. info (
132137 '[DemoDataMigrationService] No UserContentPreferences found for old '
133138 'user ID: $oldUserId . Skipping migration for preferences.' ,
134139 );
135140 } catch (e, s) {
136- print (
141+ _logger. severe (
137142 '[DemoDataMigrationService] Error migrating UserContentPreferences '
138- 'from $oldUserId to $newUserId : $e \n $s ' ,
143+ 'from $oldUserId to $newUserId : $e ' ,
144+ e,
145+ s,
139146 );
140147 }
141148 }
0 commit comments