in frontend/frontend-flutter/lib/services/new_suggestions/new_suggestion_cubit.dart [199:266]
Future<void> getAllquestions(String userGrouping) async {
List<String> resp = [];
String body = "";
String timeString = "";
print('NewSuggestionCubit : getAllquestions() : START');
timeString = displayDateTime();
//Create the header
Map<String, String>? _headers = {
"Content-Type": "application/json",
//"Authorization": " Bearer ${client!.credentials.accessToken.toString()}",
};
//Create the body
body = '''{
"user_grouping": "$userGrouping"
}''';
print('NewSuggestionCubit : getAllquestions() : body = ' + body);
try {
var response = await html.HttpRequest.requestCrossOrigin(
'${TextToDocParameter.endpoint_opendataqnq}/get_known_sql',
method: "POST",
sendData: body);
print('NewSuggestionCubit : getAllquestions() : response = ' +
response.toString());
final jsonData = jsonDecode(response);
if (jsonData != null) {
print('NewSuggestionCubit: getAllquestions() : jsonData = $jsonData');
//KnownSQL = [{"example_user_question": "question1", "example_generated_sql": "sql1"},
// {"example_user_question": "question2", "example_generated_sql": "sql2"},
// ...]
var knownSql =
jsonData["KnownSQL"].replaceAll(RegExp(r'((\\n)|(\\r))'), '');
print('NewSuggestionCubit: getAllquestions() : knownSql = $knownSql');
var knownSqlMap = jsonDecode(knownSql);
for (int i = 0; i < knownSqlMap.length; i++) {
for (var entry in knownSqlMap[i].entries) {
print('${entry.key} : ${entry.value}');
if (entry.key == "example_user_question") resp.add(entry.value);
}
}
}
} catch (e) {
print('NewSuggestionCubit: getAllquestions() : EXCEPTION = $e');
throw Exception('Failed to get questions: $e');
} finally {
print('NewSuggestionCubit: getAllquestions() : resp = ${resp}');
}
emit(state.copyWith(
status: NewSuggestionStateStatus.all_questions_loaded,
suggestionList: resp,
time: timeString,
scenarioNumber: 0,
userGrouping: userGrouping));
}