Skip to content

Commit cccd890

Browse files
committed
lint: misc
1 parent 68a2fb5 commit cccd890

File tree

5 files changed

+40
-58
lines changed

5 files changed

+40
-58
lines changed

lib/src/config/server.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import 'dart:io';
1+
import 'dart:io';
22

33
import 'package:dart_frog/dart_frog.dart';
44
import 'package:ht_api/src/config/environment_config.dart';
55
import 'package:ht_api/src/rbac/permission_service.dart';
66
import 'package:ht_api/src/services/auth_service.dart';
77
import 'package:ht_api/src/services/auth_token_service.dart';
88
import 'package:ht_api/src/services/dashboard_summary_service.dart';
9+
import 'package:ht_api/src/services/database_seeding_service.dart';
910
import 'package:ht_api/src/services/default_user_preference_limit_service.dart';
1011
import 'package:ht_api/src/services/jwt_auth_token_service.dart';
11-
import 'package:ht_api/src/services/database_seeding_service.dart';
1212
import 'package:ht_api/src/services/token_blacklist_service.dart';
1313
import 'package:ht_api/src/services/user_preference_limit_service.dart';
1414
import 'package:ht_api/src/services/verification_code_storage_service.dart';
@@ -23,20 +23,20 @@ import 'package:postgres/postgres.dart';
2323
import 'package:uuid/uuid.dart';
2424

2525
/// Global logger instance.
26-
final _log = Logger('ht_api');
26+
final _log = Logger('ht_api');
2727

2828
/// Global PostgreSQL connection instance.
29-
late final Connection _connection;
29+
late final Connection _connection;
3030

3131
/// Creates a data repository for a given type [T].
3232
///
3333
/// This helper function centralizes the creation of repositories,
3434
/// ensuring they all use the same database connection and logger.
35-
HtDataRepository<T> _createRepository<T>({
35+
HtDataRepository<T> _createRepository<T>({
3636
required String tableName,
3737
required FromJson<T> fromJson,
3838
required ToJson<T> toJson,
39-
}) {
39+
}) {
4040
return HtDataRepository<T>(
4141
dataClient: HtDataPostgresClient<T>(
4242
connection: _connection,
@@ -46,7 +46,7 @@ import 'package:uuid/uuid.dart';
4646
log: _log,
4747
),
4848
);
49-
}
49+
}
5050

5151
/// The main entry point for the server.
5252
///
@@ -98,7 +98,10 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
9898
// `ON CONFLICT DO NOTHING`), so it's safe to run every time. This ensures
9999
// the database is always in a valid state, especially for first-time setup
100100
// in any environment.
101-
final seedingService = DatabaseSeedingService(connection: _connection, log: _log);
101+
final seedingService = DatabaseSeedingService(
102+
connection: _connection,
103+
log: _log,
104+
);
102105
await seedingService.createTables();
103106
await seedingService.seedGlobalFixtureData();
104107
await seedingService.seedInitialAdminAndConfig();
@@ -136,10 +139,10 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
136139
);
137140
final userContentPreferencesRepository =
138141
_createRepository<UserContentPreferences>(
139-
tableName: 'user_content_preferences',
140-
fromJson: UserContentPreferences.fromJson,
141-
toJson: (p) => p.toJson(),
142-
);
142+
tableName: 'user_content_preferences',
143+
fromJson: UserContentPreferences.fromJson,
144+
toJson: (p) => p.toJson(),
145+
);
143146
final appConfigRepository = _createRepository<AppConfig>(
144147
tableName: 'app_config',
145148
fromJson: AppConfig.fromJson,
@@ -212,17 +215,11 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
212215
.use(provider<DashboardSummaryService>((_) => dashboardSummaryService))
213216
.use(provider<PermissionService>((_) => permissionService))
214217
.use(
215-
provider<UserPreferenceLimitService>(
216-
(_) => userPreferenceLimitService,
217-
),
218+
provider<UserPreferenceLimitService>((_) => userPreferenceLimitService),
218219
);
219220

220221
// 7. Start the server
221-
final server = await serve(
222-
finalHandler,
223-
ip,
224-
port,
225-
);
222+
final server = await serve(finalHandler, ip, port);
226223
_log.info('Server listening on port ${server.port}');
227224

228225
// 8. Handle graceful shutdown
@@ -236,4 +233,4 @@ Future<HttpServer> run(Handler handler, InternetAddress ip, int port) async {
236233
});
237234

238235
return server;
239-
}
236+
}

lib/src/registry/model_registry.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: comment_references
2+
13
import 'package:dart_frog/dart_frog.dart';
24
import 'package:ht_api/src/rbac/permissions.dart';
35
import 'package:ht_data_client/ht_data_client.dart';

lib/src/services/auth_service.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ class AuthService {
171171
// Admin users must be provisioned out-of-band (e.g., via fixtures).
172172
final roles = [UserRoles.standardUser];
173173

174-
user = User(
175-
id: _uuid.v4(),
176-
email: email,
177-
roles: roles,
178-
);
174+
user = User(id: _uuid.v4(), email: email, roles: roles);
179175
user = await _userRepository.create(item: user);
180176
print('Created new user: ${user.id} with roles: ${user.roles}');
181177

@@ -197,7 +193,9 @@ class AuthService {
197193
}
198194
} on HtHttpException catch (e) {
199195
print('Error finding/creating user for $email: $e');
200-
throw const OperationFailedException('Failed to find or create user account.');
196+
throw const OperationFailedException(
197+
'Failed to find or create user account.',
198+
);
201199
} catch (e) {
202200
print('Unexpected error during user lookup/creation for $email: $e');
203201
throw const OperationFailedException('Failed to process user account.');
@@ -213,7 +211,7 @@ class AuthService {
213211
throw const OperationFailedException(
214212
'Failed to generate authentication token.',
215213
);
216-
}
214+
}
217215
}
218216

219217
/// Performs anonymous sign-in.
@@ -227,7 +225,7 @@ class AuthService {
227225
try {
228226
user = User(
229227
id: _uuid.v4(), // Generate new ID
230-
roles: [UserRoles.guestUser], // Anonymous users are guest users
228+
roles: const [UserRoles.guestUser], // Anonymous users are guest users
231229
email: null, // Anonymous users don't have an email initially
232230
);
233231
user = await _userRepository.create(item: user);
@@ -426,7 +424,7 @@ class AuthService {
426424
final updatedUser = User(
427425
id: anonymousUser.id, // Preserve original ID
428426
email: linkedEmail,
429-
roles: [UserRoles.standardUser], // Now a permanent standard user
427+
roles: const [UserRoles.standardUser], // Now a permanent standard user
430428
);
431429
final permanentUser = await _userRepository.update(
432430
id: updatedUser.id,

lib/src/services/database_seeding_service.dart

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import 'package:ht_shared/ht_shared.dart';
12
import 'package:logging/logging.dart';
23
import 'package:postgres/postgres.dart';
3-
import 'package:ht_shared/ht_shared.dart';
44

55
/// {@template database_seeding_service}
66
/// A service responsible for initializing the database schema and seeding it
@@ -137,11 +137,7 @@ class DatabaseSeedingService {
137137
}
138138
_log.info('Database schema creation completed successfully.');
139139
} on Object catch (e, st) {
140-
_log.severe(
141-
'An error occurred during database schema creation.',
142-
e,
143-
st,
144-
);
140+
_log.severe('An error occurred during database schema creation.', e, st);
145141
// Propagate as a standard exception for the server to handle.
146142
throw OperationFailedException(
147143
'Failed to initialize database schema: $e',
@@ -225,9 +221,7 @@ class DatabaseSeedingService {
225221
e,
226222
st,
227223
);
228-
throw OperationFailedException(
229-
'Failed to seed global fixture data: $e',
230-
);
224+
throw OperationFailedException('Failed to seed global fixture data: $e');
231225
}
232226
}
233227

@@ -279,10 +273,7 @@ class DatabaseSeedingService {
279273
'VALUES (@id, @user_id, @display_settings, @language) '
280274
'ON CONFLICT (id) DO NOTHING',
281275
),
282-
parameters: {
283-
...adminSettings.toJson(),
284-
'user_id': adminUser.id,
285-
},
276+
parameters: {...adminSettings.toJson(), 'user_id': adminUser.id},
286277
);
287278

288279
await _connection.execute(
@@ -293,10 +284,7 @@ class DatabaseSeedingService {
293284
'@followed_sources, @followed_countries, @saved_headlines) '
294285
'ON CONFLICT (id) DO NOTHING',
295286
),
296-
parameters: {
297-
...adminPreferences.toJson(),
298-
'user_id': adminUser.id,
299-
},
287+
parameters: {...adminPreferences.toJson(), 'user_id': adminUser.id},
300288
);
301289

302290
await _connection.execute('COMMIT');

routes/_middleware.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:dart_frog/dart_frog.dart';
22
import 'package:ht_api/src/middlewares/error_handler.dart';
3-
import 'package:ht_api/src/middlewares/request_logger.dart';
43
import 'package:uuid/uuid.dart';
54

65
// --- Request ID Wrapper ---
@@ -54,16 +53,14 @@ Handler middleware(Handler handler) {
5453
// 3. Error Handler: Catches all errors and formats them into a standard
5554
// JSON response.
5655
return handler
57-
.use(
58-
(innerHandler) {
59-
return (context) {
60-
// Read the singleton Uuid instance provided from server.dart.
61-
final uuid = context.read<Uuid>();
62-
final requestId = RequestId(uuid.v4());
63-
return innerHandler(context.provide<RequestId>(() => requestId));
64-
};
65-
},
66-
)
56+
.use((innerHandler) {
57+
return (context) {
58+
// Read the singleton Uuid instance provided from server.dart.
59+
final uuid = context.read<Uuid>();
60+
final requestId = RequestId(uuid.v4());
61+
return innerHandler(context.provide<RequestId>(() => requestId));
62+
};
63+
})
6764
.use(requestLogger())
6865
.use(errorHandler());
6966
}

0 commit comments

Comments
 (0)