chat connection improvements
parent
1cc5ebd9fb
commit
9d7c3a38b2
@ -0,0 +1,169 @@
|
||||
class Questionnaire {
|
||||
int? questionnaireId;
|
||||
int? surveySubmissionId;
|
||||
SurveyType? surveyType;
|
||||
String? surveyName;
|
||||
String? surveyDescription;
|
||||
ServiceRequestDetails? serviceRequestDetails;
|
||||
List<SurveyQuestions>? surveyQuestions;
|
||||
|
||||
Questionnaire({this.questionnaireId, this.surveySubmissionId, this.surveyType, this.surveyName, this.surveyDescription, this.serviceRequestDetails, this.surveyQuestions});
|
||||
|
||||
Questionnaire.fromJson(Map<String, dynamic> json) {
|
||||
questionnaireId = json['questionnaireId'];
|
||||
surveySubmissionId = json['surveySubmissionId'];
|
||||
surveyType = json['surveyType'] != null ? new SurveyType.fromJson(json['surveyType']) : null;
|
||||
surveyName = json['surveyName'];
|
||||
surveyDescription = json['surveyDescription'];
|
||||
serviceRequestDetails = json['serviceRequestDetails'] != null ? new ServiceRequestDetails.fromJson(json['serviceRequestDetails']) : null;
|
||||
if (json['surveyQuestions'] != null) {
|
||||
surveyQuestions = <SurveyQuestions>[];
|
||||
json['surveyQuestions'].forEach((v) {
|
||||
surveyQuestions!.add(new SurveyQuestions.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['questionnaireId'] = this.questionnaireId;
|
||||
data['surveySubmissionId'] = this.surveySubmissionId;
|
||||
if (this.surveyType != null) {
|
||||
data['surveyType'] = this.surveyType!.toJson();
|
||||
}
|
||||
data['surveyName'] = this.surveyName;
|
||||
data['surveyDescription'] = this.surveyDescription;
|
||||
if (this.serviceRequestDetails != null) {
|
||||
data['serviceRequestDetails'] = this.serviceRequestDetails!.toJson();
|
||||
}
|
||||
if (this.surveyQuestions != null) {
|
||||
data['surveyQuestions'] = this.surveyQuestions!.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class SurveyType {
|
||||
int? id;
|
||||
String? name;
|
||||
int? value;
|
||||
|
||||
SurveyType({this.id, this.name, this.value});
|
||||
|
||||
SurveyType.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
name = json['name'];
|
||||
value = json['value'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['name'] = this.name;
|
||||
data['value'] = this.value;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class ServiceRequestDetails {
|
||||
int? serviceRequestTypeId;
|
||||
String? serviceRequestType;
|
||||
String? serviceRequestNo;
|
||||
|
||||
ServiceRequestDetails({this.serviceRequestTypeId, this.serviceRequestType, this.serviceRequestNo});
|
||||
|
||||
ServiceRequestDetails.fromJson(Map<String, dynamic> json) {
|
||||
serviceRequestTypeId = json['serviceRequestTypeId'];
|
||||
serviceRequestType = json['serviceRequestType'];
|
||||
serviceRequestNo = json['serviceRequestNo'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['serviceRequestTypeId'] = this.serviceRequestTypeId;
|
||||
data['serviceRequestType'] = this.serviceRequestType;
|
||||
data['serviceRequestNo'] = this.serviceRequestNo;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class SurveyQuestions {
|
||||
int? questionId;
|
||||
String? questionText;
|
||||
SurveyType? questionType;
|
||||
List<SurveyAnswerOptions>? surveyAnswerOptions;
|
||||
|
||||
SurveyQuestions({this.questionId, this.questionText, this.questionType, this.surveyAnswerOptions});
|
||||
|
||||
SurveyQuestions.fromJson(Map<String, dynamic> json) {
|
||||
questionId = json['questionId'];
|
||||
questionText = json['questionText'];
|
||||
questionType = json['questionType'] != null ? new SurveyType.fromJson(json['questionType']) : null;
|
||||
if (json['surveyAnswerOptions'] != null) {
|
||||
surveyAnswerOptions = <SurveyAnswerOptions>[];
|
||||
json['surveyAnswerOptions'].forEach((v) {
|
||||
surveyAnswerOptions!.add(new SurveyAnswerOptions.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['questionId'] = this.questionId;
|
||||
data['questionText'] = this.questionText;
|
||||
if (this.questionType != null) {
|
||||
data['questionType'] = this.questionType!.toJson();
|
||||
}
|
||||
if (this.surveyAnswerOptions != null) {
|
||||
data['surveyAnswerOptions'] = this.surveyAnswerOptions!.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class SurveyAnswerOptions {
|
||||
int? optionId;
|
||||
String? optionText;
|
||||
int? displayOrder;
|
||||
|
||||
SurveyAnswerOptions({this.optionId, this.optionText, this.displayOrder});
|
||||
|
||||
SurveyAnswerOptions.fromJson(Map<String, dynamic> json) {
|
||||
optionId = json['optionId'];
|
||||
optionText = json['optionText'];
|
||||
displayOrder = json['displayOrder'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['optionId'] = this.optionId;
|
||||
data['optionText'] = this.optionText;
|
||||
data['displayOrder'] = this.displayOrder;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class SurveyAnswers {
|
||||
int? questionId;
|
||||
int? surveyAnswerOptionId;
|
||||
String? surveyAnswerText;
|
||||
int? surveyAnswerRating;
|
||||
|
||||
SurveyAnswers({this.questionId, this.surveyAnswerOptionId, this.surveyAnswerText, this.surveyAnswerRating});
|
||||
|
||||
SurveyAnswers.fromJson(Map<String, dynamic> json) {
|
||||
questionId = json['questionId'];
|
||||
surveyAnswerOptionId = json['surveyAnswerOptionId'];
|
||||
surveyAnswerText = json['surveyAnswerText'];
|
||||
surveyAnswerRating = json['surveyAnswerRating'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['questionId'] = this.questionId;
|
||||
data['surveyAnswerOptionId'] = this.surveyAnswerOptionId;
|
||||
data['surveyAnswerText'] = this.surveyAnswerText;
|
||||
data['surveyAnswerRating'] = this.surveyAnswerRating;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -1,34 +1,44 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||
import 'package:test_sa/extensions/string_extensions.dart';
|
||||
|
||||
import 'questionnaire_model.dart';
|
||||
|
||||
class SurveyProvider with ChangeNotifier {
|
||||
bool loading = false;
|
||||
|
||||
void reset() {
|
||||
loading = false;
|
||||
// questionnaire = null;
|
||||
// ChatApiClient().chatLoginResponse = null;
|
||||
}
|
||||
|
||||
Future<void> getQuestionnaire(int surveySubmissionId) async {
|
||||
reset();
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
final response = await ApiManager.instance.get(URLs.getQuestionnaire + "?surveySubmissionId=$surveySubmissionId");
|
||||
|
||||
loading = false;
|
||||
|
||||
notifyListeners();
|
||||
Future<Questionnaire?> getQuestionnaire(int surveySubmissionId) async {
|
||||
try {
|
||||
final response = await ApiManager.instance.get("${URLs.getQuestionnaire.toString().replaceFirst("/mobile/", "/api/")}?surveySubmissionId=$surveySubmissionId");
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
return Questionnaire.fromJson(jsonDecode(response.body)["data"]);
|
||||
}
|
||||
} catch (ex) {
|
||||
"Failed, Retry.".showToast;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Future<void> loadChatHistory(int moduleId, int requestId) async {
|
||||
// // loadChatHistoryLoading = true;
|
||||
// // notifyListeners();
|
||||
// chatLoginResponse = await ChatApiClient().loadChatHistory(moduleId, requestId);
|
||||
// loadChatHistoryLoading = false;
|
||||
// notifyListeners();
|
||||
// }
|
||||
Future<bool> submitQuestionare(Map<String, dynamic> payload) async {
|
||||
try {
|
||||
final response = await ApiManager.instance.post(URLs.submitSurvey.toString().replaceFirst("/mobile/", "/api/"), body: payload);
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
return true;
|
||||
}
|
||||
} catch (ex) {
|
||||
"Failed, Retry.".showToast;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue