Skip to content

Commit c891df1

Browse files
committed
refactor(api): simplify me route with ResponseHelper
Updates the `/api/v1/auth/me` 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 fa93eac commit c891df1

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

routes/api/v1/auth/me.dart

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

33
import 'package:dart_frog/dart_frog.dart';
4-
// To read RequestId if needed
4+
import 'package:ht_api/src/helpers/response_helper.dart';
55
import 'package:ht_shared/ht_shared.dart'; // For User, SuccessApiResponse etc.
66

7-
import '../../../_middleware.dart'; // Potentially for RequestId definition
8-
97
/// Handles GET requests to `/api/v1/auth/me`.
108
///
119
/// Retrieves the details of the currently authenticated user based on the
@@ -30,18 +28,10 @@ Future<Response> onRequest(RequestContext context) async {
3028
throw const UnauthorizedException('Authentication required.');
3129
}
3230

33-
// Create metadata, including the requestId from the context.
34-
final metadata = ResponseMetadata(
35-
requestId: context.read<RequestId>().id,
36-
timestamp: DateTime.now().toUtc(),
37-
);
38-
39-
// Wrap the user data in SuccessApiResponse
40-
final responsePayload = SuccessApiResponse<User>(
31+
// Use the helper to create a standardized success response
32+
return ResponseHelper.success(
33+
context: context,
4134
data: user,
42-
metadata: metadata,
35+
toJsonT: (data) => data.toJson(),
4336
);
44-
45-
// Return 200 OK with the wrapped and serialized response
46-
return Response.json(body: responsePayload.toJson((user) => user.toJson()));
4737
}

0 commit comments

Comments
 (0)