From 8b388220cf8d08f7949d07c9ef3fc8b66a397f15 Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Sun, 27 Nov 2022 09:22:57 +0300 Subject: [PATCH] Added Question Dart Object --- lib/api/marathon/marathon_api_client.dart | 15 ++- lib/models/marathon/question_model.dart | 109 ++++++++++++++++++++++ 2 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 lib/models/marathon/question_model.dart diff --git a/lib/api/marathon/marathon_api_client.dart b/lib/api/marathon/marathon_api_client.dart index 3c111e7..52895ce 100644 --- a/lib/api/marathon/marathon_api_client.dart +++ b/lib/api/marathon/marathon_api_client.dart @@ -47,6 +47,7 @@ class MarathonApiClient { if (marathonModel.statusCode == 200) { if (marathonModel.data != null && marathonModel.isSuccessful == true) { + logger.i("message: ${marathonModel.data[0]["id"]}"); AppState().setMarathonProjectId = marathonModel.data[0]["id"] ?? ""; return marathonModel.data[0]["id"] ?? ""; } else { @@ -70,7 +71,7 @@ class MarathonApiClient { MarathonDetailModel marathonDetailModel = MarathonDetailModel.fromJson(marathonGenericModel.data); - AppState().setMarathonProjectId = marathonDetailModel.projects!.id!; + AppState().setMarathonProjectId = marathonDetailModel.id!; return marathonDetailModel; } @@ -109,7 +110,7 @@ class MarathonApiClient { ); if (hubConnection.state != HubConnectionState.Connected) { await hubConnection.start(); - logger.i("Hi jee"); + logger.i("Started HubConnection"); await hubConnection.invoke( "AddParticipant", @@ -124,22 +125,28 @@ class MarathonApiClient { logger.i("Error in AddParticipant: $e"); }); + logger.i("MarathonId: ${AppState().getMarathonProjectId}"); await hubConnection.invoke( "SendQuestionToParticipant", args: [ { - "marathonId": AppState().getMarathonProjectId, + "marathonId": "9c47d281-c5b5-4b5d-a90a-08dacb8cbdb6", } ], ).catchError((e) { logger.i("Error in SendQuestionToParticipant: $e"); }); - hubConnection.on("OnSendQuestionToParticipant", onSendQuestionToParticipant); + try { + hubConnection.on("OnSendQuestionToParticipant", onSendQuestionToParticipant); + } catch (e, s) { + logger.i("s"); + } } } Future onSendQuestionToParticipant(List? arguments) async { + print("arguments: $arguments"); logger.i(arguments); } diff --git a/lib/models/marathon/question_model.dart b/lib/models/marathon/question_model.dart new file mode 100644 index 0000000..90d030d --- /dev/null +++ b/lib/models/marathon/question_model.dart @@ -0,0 +1,109 @@ +class QuestionModel { + String? id; + String? titleEn; + String? titleAr; + String? marathonId; + int? questionTypeId; + int? questionTime; + int? nextQuestGap; + int? gapType; + String? gapText; + String? gapImage; + int? questOptionsLimit; + List? questionOptions; + + QuestionModel( + {id, + titleEn, + titleAr, + marathonId, + questionTypeId, + questionTime, + nextQuestGap, + gapType, + gapText, + gapImage, + questOptionsLimit, + questionOptions}); + + QuestionModel.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + marathonId = json['marathonId']; + questionTypeId = json['questionTypeId']; + questionTime = json['questionTime']; + nextQuestGap = json['nextQuestGap']; + gapType = json['gapType']; + gapText = json['gapText']; + gapImage = json['gapImage']; + questOptionsLimit = json['questOptionsLimit']; + if (json['questionOptions'] != null) { + questionOptions = []; + json['questionOptions'].forEach((v) { + questionOptions!.add( QuestionOptions.fromJson(v)); + }); + } + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['marathonId'] = marathonId; + data['questionTypeId'] = questionTypeId; + data['questionTime'] = questionTime; + data['nextQuestGap'] = nextQuestGap; + data['gapType'] = gapType; + data['gapText'] = gapText; + data['gapImage'] = gapImage; + data['questOptionsLimit'] = questOptionsLimit; + if (questionOptions != null) { + data['questionOptions'] = + questionOptions!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class QuestionOptions { + String? id; + String? titleEn; + String? titleAr; + String? questionId; + int? sequence; + String? image; + bool? isCorrectOption; + + QuestionOptions( + {id, + titleEn, + titleAr, + questionId, + sequence, + image, + isCorrectOption}); + + QuestionOptions.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + questionId = json['questionId']; + sequence = json['sequence']; + image = json['image']; + isCorrectOption = json['isCorrectOption']; + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['questionId'] = questionId; + data['sequence'] = sequence; + data['image'] = image; + data['isCorrectOption'] = isCorrectOption; + return data; + } +}