Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getDaoById query #262

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/core/network/api/services/dao_service.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/logging/log_helper.dart';
import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart';
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
import 'package:hypha_wallet/core/network/models/network.dart';
import 'package:hypha_wallet/core/network/models/user_profile_data.dart';
import 'package:hypha_wallet/core/network/networking_manager.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
Expand Down Expand Up @@ -45,4 +48,36 @@ class DaoService {
return Result.error(HyphaError.fromError(error));
}
}

Future<Result<DaoData?, HyphaError>> getDaoById({
required Network network,
required String daoId,
}) async {
final String query =
'{"query":"query getDaoById(\$docId: String!) { queryDao(filter: {docId: {eq: \$docId}}) {docId details_daoName_n settings { settings_daoTitle_s, settings_daoDescription_s, settings_logo_s, settings_daoUrl_s } } }", "variables": {"docId": "$daoId"} } ';

final url = _remoteConfigService.graphQLEndpoint(network: network);
try {
final res = await _networkingManager.post(url, data: query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels so weird to do posts in order to get data

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the body contains a rather elaborate query so... yeah. POST it is.

final Map<String, dynamic> response = res.data;

print("response: ${response}");

final List<dynamic> daos = response['data']['queryDao'];
return Result.value(daos.isNotEmpty ? DaoData.fromJson(daos[0]) : null);
} catch (error, stackTrace) {
LogHelper.e('Error accessing graphQL', stacktrace: stackTrace, error: error);
if (error is DioException) {
final dioError = error;
LogHelper.d('message: ${dioError.message}');
LogHelper.d('status code: ${dioError.response?.statusCode}');
LogHelper.d('message: ${dioError.response?.statusMessage}');
LogHelper.d('dioError: $dioError');
}

LogHelper.e('Error accessing graphQL');
LogHelper.e(error.toString());
return Result.error(HyphaError.fromError(error));
}
}
}
Loading