Skip to content

Commit 228396e

Browse files
committed
style: format
1 parent 471c9ed commit 228396e

9 files changed

+204
-149
lines changed

lib/src/config/app_dependencies.dart

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,51 @@ class AppDependencies {
4040
// --- Repositories ---
4141
/// A repository for managing [Headline] data.
4242
late final HtDataRepository<Headline> headlineRepository;
43+
4344
/// A repository for managing [Topic] data.
4445
late final HtDataRepository<Topic> topicRepository;
46+
4547
/// A repository for managing [Source] data.
4648
late final HtDataRepository<Source> sourceRepository;
49+
4750
/// A repository for managing [Country] data.
4851
late final HtDataRepository<Country> countryRepository;
52+
4953
/// A repository for managing [User] data.
5054
late final HtDataRepository<User> userRepository;
55+
5156
/// A repository for managing [UserAppSettings] data.
5257
late final HtDataRepository<UserAppSettings> userAppSettingsRepository;
58+
5359
/// A repository for managing [UserContentPreferences] data.
5460
late final HtDataRepository<UserContentPreferences>
55-
userContentPreferencesRepository;
61+
userContentPreferencesRepository;
62+
5663
/// A repository for managing the global [RemoteConfig] data.
5764
late final HtDataRepository<RemoteConfig> remoteConfigRepository;
5865

5966
// --- Services ---
6067
/// A service for sending emails.
6168
late final HtEmailRepository emailRepository;
69+
6270
/// A service for managing a blacklist of invalidated authentication tokens.
6371
late final TokenBlacklistService tokenBlacklistService;
72+
6473
/// A service for generating and validating authentication tokens.
6574
late final AuthTokenService authTokenService;
75+
6676
/// A service for storing and validating one-time verification codes.
6777
late final VerificationCodeStorageService verificationCodeStorageService;
78+
6879
/// A service that orchestrates authentication logic.
6980
late final AuthService authService;
81+
7082
/// A service for calculating and providing a summary for the dashboard.
7183
late final DashboardSummaryService dashboardSummaryService;
84+
7285
/// A service for checking user permissions.
7386
late final PermissionService permissionService;
87+
7488
/// A service for enforcing limits on user content preferences.
7589
late final UserPreferenceLimitService userPreferenceLimitService;
7690

@@ -195,11 +209,13 @@ class AppDependencies {
195209
(config) {
196210
final json = config.toJson();
197211
// All nested config objects must be JSON encoded for JSONB columns.
198-
json['user_preference_limits'] =
199-
jsonEncode(json['user_preference_limits']);
212+
json['user_preference_limits'] = jsonEncode(
213+
json['user_preference_limits'],
214+
);
200215
json['ad_config'] = jsonEncode(json['ad_config']);
201-
json['account_action_config'] =
202-
jsonEncode(json['account_action_config']);
216+
json['account_action_config'] = jsonEncode(
217+
json['account_action_config'],
218+
);
203219
json['app_status'] = jsonEncode(json['app_status']);
204220
return json;
205221
},
@@ -209,9 +225,7 @@ class AppDependencies {
209225
emailRepository = const HtEmailRepository(
210226
emailClient: HtEmailInMemoryClient(),
211227
);
212-
tokenBlacklistService = InMemoryTokenBlacklistService(
213-
log: _log,
214-
);
228+
tokenBlacklistService = InMemoryTokenBlacklistService(log: _log);
215229
authTokenService = JwtAuthTokenService(
216230
userRepository: userRepository,
217231
blacklistService: tokenBlacklistService,
@@ -235,8 +249,10 @@ class AppDependencies {
235249
sourceRepository: sourceRepository,
236250
);
237251
permissionService = const PermissionService();
238-
userPreferenceLimitService =
239-
DefaultUserPreferenceLimitService(remoteConfigRepository: remoteConfigRepository, log: _log,);
252+
userPreferenceLimitService = DefaultUserPreferenceLimitService(
253+
remoteConfigRepository: remoteConfigRepository,
254+
log: _log,
255+
);
240256
}
241257

242258
HtDataRepository<T> _createRepository<T>(

lib/src/services/auth_service.dart

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class AuthService {
7777
);
7878
}
7979

80-
final hasRequiredRole = user.dashboardRole == DashboardUserRole.admin ||
80+
final hasRequiredRole =
81+
user.dashboardRole == DashboardUserRole.admin ||
8182
user.dashboardRole == DashboardUserRole.publisher;
8283

8384
if (!hasRequiredRole) {
@@ -188,9 +189,7 @@ class AuthService {
188189
),
189190
);
190191
user = await _userRepository.create(item: user);
191-
_log.info(
192-
'Created new user: ${user.id} with appRole: ${user.appRole}',
193-
);
192+
_log.info('Created new user: ${user.id} with appRole: ${user.appRole}');
194193

195194
// Create default UserAppSettings for the new user
196195
final defaultAppSettings = UserAppSettings(
@@ -228,15 +227,19 @@ class AuthService {
228227
item: defaultUserPreferences,
229228
userId: user.id,
230229
);
231-
_log.info('Created default UserContentPreferences for user: ${user.id}');
230+
_log.info(
231+
'Created default UserContentPreferences for user: ${user.id}',
232+
);
232233
}
233234
} on HtHttpException catch (e) {
234235
_log.severe('Error finding/creating user for $email: $e');
235236
throw const OperationFailedException(
236237
'Failed to find or create user account.',
237238
);
238239
} catch (e) {
239-
_log.severe('Unexpected error during user lookup/creation for $email: $e');
240+
_log.severe(
241+
'Unexpected error during user lookup/creation for $email: $e',
242+
);
240243
throw const OperationFailedException('Failed to process user account.');
241244
}
242245

@@ -272,10 +275,8 @@ class AuthService {
272275
createdAt: DateTime.now(),
273276
feedActionStatus: Map.fromEntries(
274277
FeedActionType.values.map(
275-
(type) => MapEntry(
276-
type,
277-
const UserFeedActionStatus(isCompleted: false),
278-
),
278+
(type) =>
279+
MapEntry(type, const UserFeedActionStatus(isCompleted: false)),
279280
),
280281
),
281282
);
@@ -375,25 +376,19 @@ class AuthService {
375376
try {
376377
// Invalidate the token using the AuthTokenService
377378
await _authTokenService.invalidateToken(token);
378-
_log.info(
379-
'Token invalidation logic executed for user $userId.',
380-
);
379+
_log.info('Token invalidation logic executed for user $userId.');
381380
} on HtHttpException catch (_) {
382381
// Propagate known exceptions from the token service
383382
rethrow;
384383
} catch (e) {
385384
// Catch unexpected errors during token invalidation
386-
_log.severe(
387-
'Error during token invalidation for user $userId: $e',
388-
);
385+
_log.severe('Error during token invalidation for user $userId: $e');
389386
throw const OperationFailedException(
390387
'Failed server-side sign-out: Token invalidation failed.',
391388
);
392389
}
393390

394-
_log.info(
395-
'Server-side sign-out actions complete for user $userId.',
396-
);
391+
_log.info('Server-side sign-out actions complete for user $userId.');
397392
}
398393

399394
/// Initiates the process of linking an [emailToLink] to an existing
@@ -589,19 +584,15 @@ class AuthService {
589584
await _verificationCodeStorageService.clearSignInCode(
590585
userToDelete.email,
591586
);
592-
_log.info(
593-
'Cleared sign-in code for email ${userToDelete.email}.',
594-
);
587+
_log.info('Cleared sign-in code for email ${userToDelete.email}.');
595588
} catch (e) {
596589
_log.warning(
597590
'Warning: Failed to clear sign-in code for email ${userToDelete.email}: $e',
598591
);
599592
}
600593
}
601594

602-
_log.info(
603-
'Account deletion process completed for user $userId.',
604-
);
595+
_log.info('Account deletion process completed for user $userId.');
605596
} on NotFoundException {
606597
// Propagate NotFoundException if user doesn't exist
607598
rethrow;

lib/src/services/database_seeding_service.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,13 @@ class DatabaseSeedingService {
305305
),
306306
parameters: {
307307
'id': remoteConfig.id,
308-
'user_preference_config':
309-
jsonEncode(remoteConfig.userPreferenceConfig.toJson()),
308+
'user_preference_config': jsonEncode(
309+
remoteConfig.userPreferenceConfig.toJson(),
310+
),
310311
'ad_config': jsonEncode(remoteConfig.adConfig.toJson()),
311-
'account_action_config':
312-
jsonEncode(remoteConfig.accountActionConfig.toJson()),
312+
'account_action_config': jsonEncode(
313+
remoteConfig.accountActionConfig.toJson(),
314+
),
313315
'app_status': jsonEncode(remoteConfig.appStatus.toJson()),
314316
},
315317
);
@@ -332,8 +334,9 @@ class DatabaseSeedingService {
332334
),
333335
parameters: () {
334336
final params = adminUser.toJson();
335-
params['feed_action_status'] =
336-
jsonEncode(params['feed_action_status']);
337+
params['feed_action_status'] = jsonEncode(
338+
params['feed_action_status'],
339+
);
337340
return params;
338341
}(),
339342
);
@@ -375,7 +378,9 @@ class DatabaseSeedingService {
375378
params['user_id'] = adminUser.id;
376379
params['followed_topics'] = jsonEncode(params['followed_topics']);
377380
params['followed_sources'] = jsonEncode(params['followed_sources']);
378-
params['followed_countries'] = jsonEncode(params['followed_countries']);
381+
params['followed_countries'] = jsonEncode(
382+
params['followed_countries'],
383+
);
379384
params['saved_headlines'] = jsonEncode(params['saved_headlines']);
380385
return params;
381386
}(),

lib/src/services/default_user_preference_limit_service.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class DefaultUserPreferenceLimitService implements UserPreferenceLimitService {
1212
const DefaultUserPreferenceLimitService({
1313
required HtDataRepository<RemoteConfig> remoteConfigRepository,
1414
required Logger log,
15-
}) : _remoteConfigRepository = remoteConfigRepository,
16-
_log = log;
15+
}) : _remoteConfigRepository = remoteConfigRepository,
16+
_log = log;
1717

1818
final HtDataRepository<RemoteConfig> _remoteConfigRepository;
1919
final Logger _log;
@@ -29,7 +29,9 @@ class DefaultUserPreferenceLimitService implements UserPreferenceLimitService {
2929
) async {
3030
try {
3131
// 1. Fetch the remote configuration to get limits
32-
final remoteConfig = await _remoteConfigRepository.read(id: _remoteConfigId);
32+
final remoteConfig = await _remoteConfigRepository.read(
33+
id: _remoteConfigId,
34+
);
3335
final limits = remoteConfig.userPreferenceConfig;
3436

3537
// Admins have no limits.
@@ -87,7 +89,9 @@ class DefaultUserPreferenceLimitService implements UserPreferenceLimitService {
8789
) async {
8890
try {
8991
// 1. Fetch the remote configuration to get limits
90-
final remoteConfig = await _remoteConfigRepository.read(id: _remoteConfigId);
92+
final remoteConfig = await _remoteConfigRepository.read(
93+
id: _remoteConfigId,
94+
);
9195
final limits = remoteConfig.userPreferenceConfig;
9296

9397
// Admins have no limits.

lib/src/services/jwt_auth_token_service.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ class JwtAuthTokenService implements AuthTokenService {
165165
// Fetch the full user object from the repository
166166
// This ensures the user still exists and is valid
167167
final user = await _userRepository.read(id: userId);
168-
_log..finer('[validateToken] User repository read successful for ID: $userId')
169-
..info('[validateToken] Token validated successfully for user ${user.id}');
168+
_log
169+
..finer(
170+
'[validateToken] User repository read successful for ID: $userId',
171+
)
172+
..info(
173+
'[validateToken] Token validated successfully for user ${user.id}',
174+
);
170175
return user;
171176
} on JWTExpiredException catch (e, s) {
172177
_log.warning('[validateToken] Token expired.', e, s);
@@ -234,7 +239,9 @@ class JwtAuthTokenService implements AuthTokenService {
234239
// 3. Extract Expiry Time (exp)
235240
final expClaim = jwt.payload['exp'];
236241
if (expClaim == null || expClaim is! int) {
237-
_log.warning('[invalidateToken] Failed: Missing or invalid "exp" claim.');
242+
_log.warning(
243+
'[invalidateToken] Failed: Missing or invalid "exp" claim.',
244+
);
238245
throw const InvalidInputException(
239246
'Cannot invalidate token: Missing or invalid expiry (exp) claim.',
240247
);
@@ -243,12 +250,14 @@ class JwtAuthTokenService implements AuthTokenService {
243250
expClaim * 1000,
244251
isUtc: true,
245252
);
246-
_log..finer('[invalidateToken] Extracted expiry: $expiryDateTime')
247-
248-
// 4. Add JTI to the blacklist
249-
..finer('[invalidateToken] Adding jti $jti to blacklist...');
253+
_log
254+
..finer('[invalidateToken] Extracted expiry: $expiryDateTime')
255+
// 4. Add JTI to the blacklist
256+
..finer('[invalidateToken] Adding jti $jti to blacklist...');
250257
await _blacklistService.blacklist(jti, expiryDateTime);
251-
_log.info('[invalidateToken] Token (jti: $jti) successfully blacklisted.');
258+
_log.info(
259+
'[invalidateToken] Token (jti: $jti) successfully blacklisted.',
260+
);
252261
} on JWTException catch (e, s) {
253262
// Catch errors during the initial verification (e.g., bad signature)
254263
_log.warning(

lib/src/services/simple_auth_token_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class SimpleAuthTokenService implements AuthTokenService {
1414
const SimpleAuthTokenService({
1515
required HtDataRepository<User> userRepository,
1616
required Logger log,
17-
}) : _userRepository = userRepository,
18-
_log = log;
17+
}) : _userRepository = userRepository,
18+
_log = log;
1919

2020
final HtDataRepository<User> _userRepository;
2121
final Logger _log;

0 commit comments

Comments
 (0)