|
1 | 1 | import 'dart:io'; |
2 | 2 |
|
3 | 3 | import 'package:dart_frog/dart_frog.dart'; |
| 4 | +import 'package:ht_api/src/helpers/response_helper.dart'; |
4 | 5 | import 'package:ht_api/src/services/auth_service.dart'; |
5 | 6 | // Import exceptions, User, SuccessApiResponse, AND AuthSuccessResponse |
6 | 7 | import 'package:ht_shared/ht_shared.dart'; |
7 | 8 |
|
8 | | -import '../../../_middleware.dart'; |
9 | | - |
10 | 9 | /// Handles POST requests to `/api/v1/auth/verify-code`. |
11 | 10 | /// |
12 | 11 | /// Verifies the provided email and code, completes the sign-in/sign-up, |
@@ -86,22 +85,11 @@ Future<Response> onRequest(RequestContext context) async { |
86 | 85 | token: result.token, |
87 | 86 | ); |
88 | 87 |
|
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, |
97 | 91 | 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(), |
105 | 93 | ); |
106 | 94 | } on HtHttpException catch (_) { |
107 | 95 | // Let the central errorHandler middleware handle known exceptions |
|
0 commit comments