Skip to content

Commit e98c5fa

Browse files
committed
refactor(api): simplify verify-code route with ResponseHelper
Updates the `/api/v1/auth/verify-code` route handler to use the new `ResponseHelper.success` method. This change removes several lines of boilerplate code related to manually creating metadata and the success response object, making the handler cleaner and more focused on its core logic.
1 parent c891df1 commit e98c5fa

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

routes/api/v1/auth/verify-code.dart

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import 'dart:io';
22

33
import 'package:dart_frog/dart_frog.dart';
4+
import 'package:ht_api/src/helpers/response_helper.dart';
45
import 'package:ht_api/src/services/auth_service.dart';
56
// Import exceptions, User, SuccessApiResponse, AND AuthSuccessResponse
67
import 'package:ht_shared/ht_shared.dart';
78

8-
import '../../../_middleware.dart';
9-
109
/// Handles POST requests to `/api/v1/auth/verify-code`.
1110
///
1211
/// Verifies the provided email and code, completes the sign-in/sign-up,
@@ -86,22 +85,11 @@ Future<Response> onRequest(RequestContext context) async {
8685
token: result.token,
8786
);
8887

89-
// Create metadata, including the requestId from the context.
90-
final metadata = ResponseMetadata(
91-
requestId: context.read<RequestId>().id,
92-
timestamp: DateTime.now().toUtc(),
93-
);
94-
95-
// Wrap the payload in the standard SuccessApiResponse
96-
final responsePayload = SuccessApiResponse<AuthSuccessResponse>(
88+
// Use the helper to create a standardized success response
89+
return ResponseHelper.success(
90+
context: context,
9791
data: authPayload,
98-
metadata: metadata,
99-
);
100-
101-
// Return 200 OK with the standardized, serialized response
102-
return Response.json(
103-
// Use the toJson method, providing the toJson factory for the inner type
104-
body: responsePayload.toJson((authSuccess) => authSuccess.toJson()),
92+
toJsonT: (data) => data.toJson(),
10593
);
10694
} on HtHttpException catch (_) {
10795
// Let the central errorHandler middleware handle known exceptions

0 commit comments

Comments
 (0)