Skip to content

Commit bb4340b

Browse files
committed
refactor: remove unused comments and imports
- Removed unused imports - Removed commented out code - Improved code readability
1 parent 9199b62 commit bb4340b

File tree

9 files changed

+36
-111
lines changed

9 files changed

+36
-111
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ analyzer:
77
avoid_catches_without_on_clauses: ignore
88
lines_longer_than_80_chars: ignore
99
avoid_dynamic_calls: ignore
10+
avoid_catching_errors: ignore
1011
exclude:
1112
- build/**
1213
linter:

routes/_middleware.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// routes/_middleware.dart
2-
//
3-
// ignore_for_file: avoid_slow_async_io, avoid_catches_without_on_clauses
4-
51
import 'dart:convert';
62
import 'dart:io';
73

@@ -10,19 +6,17 @@ import 'package:ht_api/src/middlewares/error_handler.dart';
106
import 'package:ht_api/src/registry/model_registry.dart';
117
import 'package:ht_api/src/services/auth_service.dart';
128
import 'package:ht_api/src/services/auth_token_service.dart';
13-
// Import the JWT service and blacklist service
149
import 'package:ht_api/src/services/jwt_auth_token_service.dart';
1510
import 'package:ht_api/src/services/token_blacklist_service.dart';
1611
import 'package:ht_api/src/services/verification_code_storage_service.dart';
17-
// Import HtAppSettingsClient interface
1812
import 'package:ht_app_settings_client/ht_app_settings_client.dart';
1913
import 'package:ht_app_settings_inmemory/ht_app_settings_inmemory.dart';
2014
import 'package:ht_data_inmemory/ht_data_inmemory.dart';
2115
import 'package:ht_data_repository/ht_data_repository.dart';
2216
import 'package:ht_email_inmemory/ht_email_inmemory.dart';
2317
import 'package:ht_email_repository/ht_email_repository.dart';
2418
import 'package:ht_shared/ht_shared.dart';
25-
import 'package:uuid/uuid.dart'; // Import the uuid package
19+
import 'package:uuid/uuid.dart';
2620

2721
// --- Request ID Wrapper ---
2822

@@ -68,14 +62,13 @@ class RequestId {
6862

6963
// --- Helper Function to Load Fixtures ---
7064
// Note:
71-
// Error handling here is basic. In a real app,
72-
// consider more robust file checks.
65+
// Error handling here is basic, consider more robust file checks.
7366
// ignore: unused_element
7467
Future<List<Map<String, dynamic>>> _loadFixture(String fileName) async {
7568
final path = 'lib/src/fixtures/$fileName';
7669
try {
7770
final file = File(path);
78-
if (!await file.exists()) {
71+
if (!file.existsSync()) {
7972
print('Warning: Fixture file not found at $path. Returning empty list.');
8073
return [];
8174
}
@@ -168,7 +161,7 @@ Handler middleware(Handler handler) {
168161
final categoryRepository = _createCategoryRepository();
169162
final sourceRepository = _createSourceRepository();
170163
final countryRepository = _createCountryRepository();
171-
final settingsClientImpl = HtAppSettingsInMemory(); // Using in-memory for now
164+
final settingsClientImpl = HtAppSettingsInMemory();
172165
const uuid = Uuid();
173166

174167
// --- Auth Dependencies ---

routes/api/v1/auth/anonymous.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:io';
22

33
import 'package:dart_frog/dart_frog.dart';
44
import 'package:ht_api/src/services/auth_service.dart';
5-
// Import exceptions, User, SuccessApiResponse, AND AuthSuccessResponse
65
import 'package:ht_shared/ht_shared.dart';
76

87
/// Handles POST requests to `/api/v1/auth/anonymous`.

routes/api/v1/data/[id].dart

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars, no_default_cases, avoid_catches_without_on_clauses, avoid_catching_errors
3-
41
import 'dart:io';
52

6-
// --- Error Handling Strategy ---
7-
// Route-specific handlers (_handleGet, _handlePut, _handleDelete, etc.) should
8-
// generally allow HtHttpExceptions (like NotFoundException, BadRequestException)
9-
// and FormatExceptions thrown by lower layers (Repositories, Clients, JSON parsing)
10-
// to propagate upwards.
11-
//
12-
// These specific exceptions are caught and re-thrown by the main `onRequest`
13-
// handler in this file.
14-
//
15-
// The centralized `errorHandler` middleware (defined in lib/src/middlewares/)
16-
// is responsible for catching these re-thrown exceptions and mapping them to
17-
// appropriate, standardized JSON error responses (e.g., 400, 404, 500).
18-
//
19-
// Local try-catch blocks within specific _handle* methods should be reserved
20-
// for handling errors that require immediate, localized responses (like the
21-
// TypeError during deserialization in _handlePut) or for logging specific
22-
// context before allowing propagation.
23-
243
import 'package:dart_frog/dart_frog.dart';
25-
// Import RequestId from the middleware file where it's defined
264
import 'package:ht_api/src/registry/model_registry.dart';
275
import 'package:ht_data_repository/ht_data_repository.dart';
28-
// Import exceptions
29-
// Import models, SuccessApiResponse, ResponseMetadata
306
import 'package:ht_shared/ht_shared.dart';
317

328
import '../../../_middleware.dart';
@@ -48,7 +24,7 @@ Future<Response> onRequest(RequestContext context, String id) async {
4824
context,
4925
id,
5026
modelName,
51-
modelConfig, // Pass modelConfig
27+
modelConfig,
5228
authenticatedUser,
5329
requestId,
5430
);
@@ -66,11 +42,10 @@ Future<Response> onRequest(RequestContext context, String id) async {
6642
context,
6743
id,
6844
modelName,
69-
modelConfig, // Pass modelConfig
45+
modelConfig,
7046
authenticatedUser,
7147
requestId,
7248
);
73-
// Add cases for other methods if needed in the future
7449
default:
7550
// Methods not allowed on the item endpoint
7651
return Response(statusCode: HttpStatus.methodNotAllowed);
@@ -101,11 +76,11 @@ Future<Response> _handleGet(
10176
RequestContext context,
10277
String id,
10378
String modelName,
104-
ModelConfig<dynamic> modelConfig, // Receive modelConfig
105-
User authenticatedUser, // Receive authenticatedUser
79+
ModelConfig<dynamic> modelConfig,
80+
User authenticatedUser,
10681
String requestId,
10782
) async {
108-
dynamic item; // Use dynamic
83+
dynamic item;
10984

11085
String? userIdForRepoCall;
11186
if (modelConfig.ownership == ModelOwnership.userOwned) {
@@ -179,7 +154,7 @@ Future<Response> _handlePut(
179154
String id,
180155
String modelName,
181156
ModelConfig<dynamic> modelConfig,
182-
User authenticatedUser, // Receive authenticatedUser
157+
User authenticatedUser,
183158
String requestId,
184159
) async {
185160
final requestBody = await context.request.json() as Map<String, dynamic>?;
@@ -191,7 +166,7 @@ Future<Response> _handlePut(
191166
}
192167

193168
// Deserialize using ModelConfig's fromJson, catching TypeErrors locally
194-
dynamic itemToUpdate; // Use dynamic initially
169+
dynamic itemToUpdate;
195170
try {
196171
itemToUpdate = modelConfig.fromJson(requestBody);
197172
} on TypeError catch (e) {
@@ -213,14 +188,14 @@ Future<Response> _handlePut(
213188
);
214189
}
215190

216-
dynamic updatedItem; // Use dynamic
191+
dynamic updatedItem;
217192

218193
String? userIdForRepoCall;
219194
if (modelConfig.ownership == ModelOwnership.userOwned) {
220195
userIdForRepoCall = authenticatedUser.id;
221196
} else {
222-
// For global models, update might imply admin rights.
223-
// For now, pass null, assuming repo handles global updates or has other checks.
197+
// TODO(fulleni): For global models, update might imply admin rights.
198+
// For now, pass null, consider adding an admin user check.
224199
userIdForRepoCall = null;
225200
}
226201

@@ -326,7 +301,7 @@ Future<Response> _handlePut(
326301
// Wrap the updated item in SuccessApiResponse with metadata
327302
final successResponse = SuccessApiResponse<dynamic>(
328303
data: updatedItem,
329-
metadata: metadata, // Include the created metadata
304+
metadata: metadata,
330305
);
331306

332307
// Provide the correct toJsonT for the specific model type
@@ -344,16 +319,16 @@ Future<Response> _handleDelete(
344319
RequestContext context,
345320
String id,
346321
String modelName,
347-
ModelConfig<dynamic> modelConfig, // Receive modelConfig
348-
User authenticatedUser, // Receive authenticatedUser
322+
ModelConfig<dynamic> modelConfig,
323+
User authenticatedUser,
349324
String requestId,
350325
) async {
351326
String? userIdForRepoCall;
352327
if (modelConfig.ownership == ModelOwnership.userOwned) {
353328
userIdForRepoCall = authenticatedUser.id;
354329
} else {
355-
// For global models, delete might imply admin rights.
356-
// For now, pass null.
330+
// TODO(fulleni): For global models, update might imply admin rights.
331+
// For now, pass null, consider adding an admin user check.
357332
userIdForRepoCall = null;
358333
}
359334

routes/api/v1/data/_middleware.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars
3-
41
import 'package:dart_frog/dart_frog.dart';
52
import 'package:ht_api/src/middlewares/authentication_middleware.dart';
63
import 'package:ht_api/src/registry/model_registry.dart';

routes/api/v1/data/index.dart

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars, no_default_cases, avoid_catches_without_on_clauses, avoid_catching_errors
3-
41
import 'dart:io';
52

6-
// --- Error Handling Strategy ---
7-
// Route-specific handlers (_handleGet, _handlePost, etc.) should generally
8-
// allow HtHttpExceptions (like NotFoundException, BadRequestException)
9-
// and FormatExceptions thrown by lower layers (Repositories, Clients, JSON parsing)
10-
// to propagate upwards.
11-
//
12-
// These specific exceptions are caught and re-thrown by the main `onRequest`
13-
// handler in this file.
14-
//
15-
// The centralized `errorHandler` middleware (defined in lib/src/middlewares/)
16-
// is responsible for catching these re-thrown exceptions and mapping them to
17-
// appropriate, standardized JSON error responses (e.g., 400, 404, 500).
18-
//
19-
// Local try-catch blocks within specific _handle* methods should be reserved
20-
// for handling errors that require immediate, localized responses (like the
21-
// TypeError during deserialization in _handlePost) or for logging specific
22-
// context before allowing propagation.
23-
243
import 'package:dart_frog/dart_frog.dart';
25-
// Import RequestId from the middleware file where it's defined
264
import 'package:ht_api/src/registry/model_registry.dart';
275
import 'package:ht_data_repository/ht_data_repository.dart';
28-
// Import exceptions
29-
// Import models, SuccessApiResponse, PaginatedResponse, ResponseMetadata
306
import 'package:ht_shared/ht_shared.dart';
317

328
import '../../../_middleware.dart';
@@ -47,7 +23,7 @@ Future<Response> onRequest(RequestContext context) async {
4723
return await _handleGet(
4824
context,
4925
modelName,
50-
modelConfig, // Pass modelConfig
26+
modelConfig,
5127
authenticatedUser,
5228
requestId,
5329
);
@@ -89,8 +65,8 @@ Future<Response> onRequest(RequestContext context) async {
8965
Future<Response> _handleGet(
9066
RequestContext context,
9167
String modelName,
92-
ModelConfig<dynamic> modelConfig, // Receive modelConfig
93-
User authenticatedUser, // Receive authenticatedUser
68+
ModelConfig<dynamic> modelConfig,
69+
User authenticatedUser,
9470
String requestId,
9571
) async {
9672
// Read query parameters
@@ -104,7 +80,7 @@ Future<Response> _handleGet(
10480
..remove('limit');
10581

10682
// Process based on model type
107-
PaginatedResponse<dynamic> paginatedResponse; // Use dynamic for the list
83+
PaginatedResponse<dynamic> paginatedResponse;
10884

10985
String? userIdForRepoCall;
11086
if (modelConfig.ownership == ModelOwnership.userOwned) {
@@ -222,7 +198,7 @@ Future<Response> _handlePost(
222198
RequestContext context,
223199
String modelName,
224200
ModelConfig<dynamic> modelConfig,
225-
User authenticatedUser, // Receive authenticatedUser
201+
User authenticatedUser,
226202
String requestId,
227203
) async {
228204
final requestBody = await context.request.json() as Map<String, dynamic>?;
@@ -234,7 +210,7 @@ Future<Response> _handlePost(
234210
}
235211

236212
// Deserialize using ModelConfig's fromJson, catching TypeErrors
237-
dynamic newItem; // Use dynamic initially
213+
dynamic newItem;
238214
try {
239215
newItem = modelConfig.fromJson(requestBody);
240216
} on TypeError catch (e) {
@@ -255,15 +231,14 @@ Future<Response> _handlePost(
255231
}
256232

257233
// Process based on model type
258-
dynamic createdItem; // Use dynamic
234+
dynamic createdItem;
259235

260236
String? userIdForRepoCall;
261237
if (modelConfig.ownership == ModelOwnership.userOwned) {
262238
userIdForRepoCall = authenticatedUser.id;
263239
} else {
264-
// For global models, creation might imply admin rights or specific logic.
265-
// For now, we pass null, assuming the repository handles global creation.
266-
// Or, a check could be added here: if global and user is not admin, throw Forbidden.
240+
// TODO(fulleni): For global models, update might imply admin rights.
241+
// For now, pass null, consider adding an admin user check.
267242
userIdForRepoCall = null;
268243
}
269244

@@ -325,7 +300,7 @@ Future<Response> _handlePost(
325300
// Wrap the created item in SuccessApiResponse with metadata
326301
final successResponse = SuccessApiResponse<dynamic>(
327302
data: createdItem,
328-
metadata: metadata, // Include the created metadata
303+
metadata: metadata,
329304
);
330305

331306
// Provide the correct toJsonT for the specific model type

routes/api/v1/users/[userId]/settings/display.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars, avoid_catches_without_on_clauses
3-
41
import 'dart:io';
52

63
import 'package:dart_frog/dart_frog.dart';
74
import 'package:ht_app_settings_client/ht_app_settings_client.dart';
85
import 'package:ht_app_settings_repository/ht_app_settings_repository.dart';
96
import 'package:ht_shared/ht_shared.dart';
107

11-
// Import RequestId from the root middleware file
12-
// Note: RequestId is provided by routes/_middleware.dart
13-
// User is provided by authentication_middleware.dart via routes/api/v1/users/[userId]/settings/_middleware.dart
148
import '../../../../../_middleware.dart' show RequestId;
159

1610
/// Handles requests for the /api/v1/users/{userId}/settings/display endpoint.
1711
Future<Response> onRequest(
1812
RequestContext context,
19-
String userIdFromPath, // userId from the path parameter
13+
String userIdFromPath,
2014
) async {
2115
// Read dependencies provided by middleware
2216
final requestId = context.read<RequestId>().id;
@@ -60,7 +54,7 @@ Future<Response> onRequest(
6054
// --- GET Handler ---
6155
Future<Response> _handleGet(
6256
RequestContext context,
63-
User authenticatedUser, // Receive the authenticated user
57+
User authenticatedUser,
6458
String requestId,
6559
) async {
6660
// Read the HtAppSettingsClient to instantiate a user-scoped repository

routes/api/v1/users/[userId]/settings/index.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//
2-
// ignore_for_file: lines_longer_than_80_chars, avoid_catches_without_on_clauses
3-
41
import 'dart:io';
52

63
import 'package:dart_frog/dart_frog.dart';
@@ -57,14 +54,14 @@ Future<Response> onRequest(
5754
// --- DELETE Handler ---
5855
Future<Response> _handleDelete(
5956
RequestContext context,
60-
User authenticatedUser, // Receive the authenticated user
57+
User authenticatedUser,
6158
String requestId, // For logging
6259
) async {
6360
// Read the HtAppSettingsClient to instantiate a user-scoped repository
6461
final settingsClient = context.read<HtAppSettingsClient>();
6562
final userSettingsRepo = HtAppSettingsRepository(
6663
client: settingsClient,
67-
userId: authenticatedUser.id, // Use the authenticated user's ID
64+
userId: authenticatedUser.id,
6865
);
6966

7067
// Call the repository method to clear settings.

0 commit comments

Comments
 (0)