Skip to content

Commit d0a78ff

Browse files
committed
style: misc
1 parent 6dd0eb8 commit d0a78ff

11 files changed

+35
-44
lines changed

lib/src/fixtures/headlines.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"title": "Dart Frog 1.0 Released!",
55
"description": "The minimalist backend framework for Dart reaches a major milestone.",
66
"url": "https://dartfrog.vgv.dev/docs/overview",
7-
"imageUrl": null,
8-
"publishedAt": "2025-04-20T10:00:00Z",
7+
"image_url": null,
8+
"published_at": "2025-04-20T10:00:00Z",
99
"source": {
1010
"id": "s1a2b3c4-d5e6-f789-0123-456789abcdef",
1111
"name": "Very Good Ventures Blog",
@@ -23,8 +23,8 @@
2323
"title": "Flutter Adaptive UI Best Practices",
2424
"description": "Building responsive and adaptive user interfaces in Flutter.",
2525
"url": "https://docs.flutter.dev/ui/layout/adaptive",
26-
"imageUrl": null,
27-
"publishedAt": "2025-04-22T14:30:00Z",
26+
"image_url": null,
27+
"published_at": "2025-04-22T14:30:00Z",
2828
"source": {
2929
"id": "s2b3c4d5-e6f7-a890-1234-567890abcdef",
3030
"name": "Flutter Dev",

lib/src/middlewares/authentication_middleware.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:dart_frog/dart_frog.dart';
2-
// Import the interface type
32
import 'package:ht_api/src/services/auth_token_service.dart';
43
import 'package:ht_shared/ht_shared.dart';
54

@@ -18,50 +17,50 @@ import 'package:ht_shared/ht_shared.dart';
1817
Middleware authenticationProvider() {
1918
return (handler) {
2019
return (context) async {
21-
print('[AuthMiddleware] Entered.'); // Log 1: Entry
20+
print('[AuthMiddleware] Entered.');
2221
// Read the interface type
2322
AuthTokenService tokenService;
2423
try {
2524
print(
2625
'[AuthMiddleware] Attempting to read AuthTokenService...',
27-
); // Log 2: Before read
26+
);
2827
tokenService = context.read<AuthTokenService>();
2928
print(
3029
'[AuthMiddleware] Successfully read AuthTokenService.',
31-
); // Log 3: After read
30+
);
3231
} catch (e, s) {
3332
print(
3433
'[AuthMiddleware] FAILED to read AuthTokenService: $e\n$s',
35-
); // Log Error
34+
);
3635
// Re-throw the error to be caught by the main error handler
3736
rethrow;
3837
}
39-
User? user; // Initialize user as null
38+
User? user;
4039

4140
// Extract the Authorization header
4241
print(
4342
'[AuthMiddleware] Attempting to read Authorization header...',
44-
); // Log 4: Before header read
43+
);
4544
final authHeader = context.request.headers['Authorization'];
4645
print(
4746
'[AuthMiddleware] Authorization header value: $authHeader',
48-
); // Log 5: Header value
47+
);
4948

5049
if (authHeader != null && authHeader.startsWith('Bearer ')) {
5150
// Extract the token string
5251
final token = authHeader.substring(7); // Length of 'Bearer '
5352
print(
5453
'[AuthMiddleware] Extracted Bearer token.',
55-
); // Log 6: Token extracted
54+
);
5655
try {
5756
print(
5857
'[AuthMiddleware] Attempting to validate token...',
59-
); // Log 7: Before validate
58+
);
6059
// Validate the token using the service
6160
user = await tokenService.validateToken(token);
6261
print(
6362
'[AuthMiddleware] Token validation returned: ${user?.id ?? 'null'}',
64-
); // Log 8: After validate
63+
);
6564
if (user != null) {
6665
print(
6766
'[AuthMiddleware] Authentication successful for user: ${user.id}',
@@ -95,7 +94,7 @@ Middleware authenticationProvider() {
9594
// This makes `context.read<User?>()` available downstream.
9695
print(
9796
'[AuthMiddleware] Providing User (${user?.id ?? 'null'}) to context.',
98-
); // Log 9: Before provide
97+
);
9998
return handler(context.provide<User?>(() => user));
10099
};
101100
};
@@ -121,7 +120,7 @@ Middleware requireAuthentication() {
121120
print('Authentication check passed for user: ${user.id}');
122121
return handler(
123122
context.provide<User>(() => user),
124-
); // Provide non-nullable User
123+
);
125124
};
126125
};
127126
}

lib/src/middlewares/authorization_middleware.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:dart_frog/dart_frog.dart';
22
import 'package:ht_api/src/rbac/permission_service.dart';
33
import 'package:ht_api/src/registry/model_registry.dart';
4-
import 'package:ht_shared/ht_shared.dart'; // For User, ForbiddenException
4+
import 'package:ht_shared/ht_shared.dart';
55

66
/// {@template authorization_middleware}
77
/// Middleware to enforce role-based permissions and model-specific access rules.

lib/src/middlewares/error_handler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ String _mapExceptionToCodeString(HtHttpException exception) {
9090
ServerException() => 'SERVER_ERROR',
9191
OperationFailedException() => 'OPERATION_FAILED',
9292
NetworkException() => 'NETWORK_ERROR',
93-
ConflictException() => 'CONFLICT', // Added for 409
93+
ConflictException() => 'CONFLICT',
9494
UnknownException() => 'UNKNOWN_ERROR',
9595
_ => 'UNKNOWN_ERROR', // Default
9696
};

lib/src/rbac/role_permissions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ final Set<String> _adminPermissions = {
6060
final Map<UserRole, Set<String>> rolePermissions = {
6161
UserRole.guestUser: _guestUserPermissions,
6262
UserRole.standardUser: _standardUserPermissions,
63-
UserRole.premiumUser: _premiumUserPermissions, // Added premium user
63+
UserRole.premiumUser: _premiumUserPermissions,
6464
UserRole.admin: _adminPermissions,
6565
};

lib/src/registry/model_registry.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
//
2-
// ignore_for_file: strict_raw_type, lines_longer_than_80_chars
3-
41
import 'package:dart_frog/dart_frog.dart';
5-
import 'package:ht_api/src/rbac/permissions.dart'; // Import permissions
2+
import 'package:ht_api/src/rbac/permissions.dart';
63
import 'package:ht_data_client/ht_data_client.dart';
74
import 'package:ht_shared/ht_shared.dart';
85

@@ -68,8 +65,8 @@ class ModelConfig<T> {
6865
const ModelConfig({
6966
required this.fromJson,
7067
required this.getId,
71-
required this.getCollectionPermission, // New field for GET collection
72-
required this.getItemPermission, // New field for GET item
68+
required this.getCollectionPermission,
69+
required this.getItemPermission,
7370
required this.postPermission,
7471
required this.putPermission,
7572
required this.deletePermission,
@@ -188,7 +185,7 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
188185
),
189186
'country': ModelConfig<Country>(
190187
fromJson: Country.fromJson,
191-
getId: (c) => c.id, // Assuming Country has an 'id' field
188+
getId: (c) => c.id,
192189
// Countries: Admin-owned, read allowed by standard/guest users
193190
getCollectionPermission: const ModelActionPermission(
194191
type: RequiredPermissionType.specificPermission,
@@ -327,4 +324,4 @@ typedef ModelRegistryMap = Map<String, ModelConfig<dynamic>>;
327324
/// used by the middleware in `routes/api/v1/data/_middleware.dart`.
328325
final modelRegistryProvider = provider<ModelRegistryMap>(
329326
(_) => modelRegistry,
330-
); // Use lowercase provider function for setup
327+
);

lib/src/services/jwt_auth_token_service.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
// For potential base64 decoding if needed
2-
31
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
42
import 'package:ht_api/src/services/auth_token_service.dart';
5-
// Import the blacklist service
63
import 'package:ht_api/src/services/token_blacklist_service.dart';
74
import 'package:ht_data_repository/ht_data_repository.dart';
85
import 'package:ht_shared/ht_shared.dart';
@@ -14,7 +11,7 @@ String _userRoleToString(UserRole role) {
1411
UserRole.admin => 'admin',
1512
UserRole.standardUser => 'standard_user',
1613
UserRole.guestUser => 'guest_user',
17-
UserRole.premiumUser => 'premium_user', // Added premium user
14+
UserRole.premiumUser => 'premium_user',
1815
};
1916
}
2017

lib/src/services/token_blacklist_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:async';
22

3-
import 'package:ht_shared/ht_shared.dart'; // Added for OperationFailedException
3+
import 'package:ht_shared/ht_shared.dart';
44
import 'package:meta/meta.dart';
55

66
/// {@template token_blacklist_service}

lib/src/services/verification_code_storage_service.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
//
21
// ignore_for_file: library_private_types_in_public_api
32

43
import 'dart:async';
54
import 'dart:math';
65

7-
import 'package:ht_shared/ht_shared.dart'; // For HtHttpException, ConflictException
6+
import 'package:ht_shared/ht_shared.dart';
87
import 'package:meta/meta.dart';
98

109
// Default duration for code expiry (e.g., 15 minutes)

routes/_middleware.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,14 @@ Handler middleware(Handler handler) {
309309

310310
// --- Feed Enhancement Dependencies ---
311311
const adDecorator = AdDecorator(uuidGenerator: uuid);
312-
const engagementDecorator = EngagementDecorator(uuidGenerator: uuid);
313-
const suggestedContentDecorator =
314-
SuggestedContentDecorator(uuidGenerator: uuid);
312+
// const engagementDecorator = EngagementDecorator(uuidGenerator: uuid);
313+
// const suggestedContentDecorator = SuggestedContentDecorator(uuidGenerator: uuid);
315314

316315
const feedEnhancementService = FeedEnhancementService(
317316
decorators: [
318317
adDecorator,
319-
engagementDecorator,
320-
suggestedContentDecorator,
318+
// engagementDecorator,
319+
// suggestedContentDecorator,
321320
],
322321
);
323322
print('[MiddlewareSetup] FeedEnhancementService instantiated.');

0 commit comments

Comments
 (0)