getUser method

Future<ApiResponse<User>> getUser()

Implementation

Future<ApiResponse<User>> getUser() async {
  try {
    final response = await call(endpoint: 'users', method: Method.GET);
    final bodyJson = jsonDecode(response.body);

    if (response.statusCode == 200) {
      return ApiResponse.fromJson(
        bodyJson,
            (data) => User.fromJson(data),
      );
    } else {
      return ApiResponse(
        success: false,
        data: null,
        message: bodyJson['message'] ?? "Failed to fetch user data",
      );
    }
  } catch (e) {
    return ApiResponse(
      success: false,
      data: null,
      message: "Error fetching user: $e",
    );
  }
}