Added initial APIs for Marathon
parent
143d0772f2
commit
35a4b780a7
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>aps-environment</key>
|
||||
<string>development</string>
|
||||
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.com.cloudsolutions.mohemm</string>
|
||||
</array>
|
||||
<key>com.apple.developer.icloud-services</key>
|
||||
<array>
|
||||
<string>CloudDocuments</string>
|
||||
</array>
|
||||
<key>com.apple.developer.networking.HotspotConfiguration</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.networking.networkextension</key>
|
||||
<array/>
|
||||
<key>com.apple.developer.networking.wifi-info</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.nfc.readersession.formats</key>
|
||||
<array>
|
||||
<string>TAG</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.com.cloudsolutions.mohemm</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@ -0,0 +1,71 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:mohem_flutter_app/api/api_client.dart';
|
||||
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
||||
import 'package:mohem_flutter_app/classes/consts.dart';
|
||||
import 'package:mohem_flutter_app/models/marathon/marathon_generic_model.dart';
|
||||
import 'package:mohem_flutter_app/models/marathon/marathon_model.dart';
|
||||
|
||||
class MarathonApiClient {
|
||||
Future<String> getMarathonToken() async {
|
||||
String employeeUserName = AppState().getUserName ?? "";
|
||||
String employeeSession = AppState().postParamsObject?.pSessionId.toString() ?? "";
|
||||
|
||||
Map<String, String> jsonObject = {"userName": employeeUserName, "password": employeeSession};
|
||||
Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonParticipantLoginUrl, jsonObject);
|
||||
|
||||
var json = jsonDecode(response.body);
|
||||
|
||||
MarathonGenericModel marathonModel = MarathonGenericModel.fromJson(json);
|
||||
|
||||
if (marathonModel.statusCode == 200) {
|
||||
if (marathonModel.data != null && marathonModel.isSuccessful == true) {
|
||||
print("bearerToken: ${marathonModel.data["token"]}");
|
||||
AppState().setMarathonToken = marathonModel.data["token"] ?? "";
|
||||
return marathonModel.data["token"] ?? "";
|
||||
} else {
|
||||
//TODO : DO ERROR HANDLING HERE
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
//TODO : DO ERROR HANDLING HERE
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getProjectId() async {
|
||||
Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonProjectGetUrl, <String, dynamic>{}, token: AppState().getMarathonToken ?? await getMarathonToken());
|
||||
|
||||
var json = jsonDecode(response.body);
|
||||
MarathonGenericModel marathonModel = MarathonGenericModel.fromJson(json);
|
||||
|
||||
if (marathonModel.statusCode == 200) {
|
||||
if (marathonModel.data != null && marathonModel.isSuccessful == true) {
|
||||
print("projectID: ${marathonModel.data[0]["id"]}");
|
||||
AppState().setMarathonProjectId = marathonModel.data[0]["id"] ?? "";
|
||||
return marathonModel.data[0]["id"] ?? "";
|
||||
} else {
|
||||
//TODO : DO ERROR HANDLING HERE
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
//TODO : DO ERROR HANDLING HERE
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Future<MarathonDetailModel> getMarathonDetails() async {
|
||||
String payrollString = AppState().postParamsObject?.payrollCodeStr.toString() ?? "CS";
|
||||
|
||||
Response response = await ApiClient().getJsonForResponse(ApiConsts.marathonUpcomingUrl + payrollString, token: AppState().getMarathonToken ?? await getMarathonToken());
|
||||
|
||||
var json = jsonDecode(response.body);
|
||||
|
||||
MarathonGenericModel marathonGenericModel = MarathonGenericModel.fromJson(json);
|
||||
|
||||
MarathonDetailModel marathonDetailModel = MarathonDetailModel.fromJson(marathonGenericModel.data);
|
||||
|
||||
return marathonDetailModel;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
class MarathonGenericModel {
|
||||
MarathonGenericModel({
|
||||
this.data,
|
||||
this.isSuccessful,
|
||||
this.message,
|
||||
this.statusCode,
|
||||
this.errors,
|
||||
});
|
||||
|
||||
dynamic data;
|
||||
bool? isSuccessful;
|
||||
String? message;
|
||||
int? statusCode;
|
||||
dynamic errors;
|
||||
|
||||
factory MarathonGenericModel.fromJson(Map<String, dynamic> json) => MarathonGenericModel(
|
||||
data: json["data"],
|
||||
isSuccessful: json["isSuccessful"],
|
||||
message: json["message"],
|
||||
statusCode: json["statusCode"],
|
||||
errors: json["errors"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"data": data,
|
||||
"isSuccessful": isSuccessful,
|
||||
"message": message,
|
||||
"statusCode": statusCode,
|
||||
"errors": errors,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
class MarathonDetailModel {
|
||||
String? id;
|
||||
String? titleEn;
|
||||
String? titleAr;
|
||||
String? descEn;
|
||||
String? descAr;
|
||||
int? winDeciderTime;
|
||||
int? winnersCount;
|
||||
int? questGapTime;
|
||||
String? startTime;
|
||||
String? endTime;
|
||||
int? marathoneStatusId;
|
||||
String? scheduleTime;
|
||||
int? selectedLanguage;
|
||||
List? projects;
|
||||
List? sponsors;
|
||||
List? questions;
|
||||
|
||||
MarathonDetailModel(
|
||||
{id,
|
||||
titleEn,
|
||||
titleAr,
|
||||
descEn,
|
||||
descAr,
|
||||
winDeciderTime,
|
||||
winnersCount,
|
||||
questGapTime,
|
||||
startTime,
|
||||
endTime,
|
||||
marathoneStatusId,
|
||||
scheduleTime,
|
||||
selectedLanguage,
|
||||
projects,
|
||||
sponsors,
|
||||
questions});
|
||||
|
||||
MarathonDetailModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
titleEn = json['titleEn'];
|
||||
titleAr = json['titleAr'];
|
||||
descEn = json['descEn'];
|
||||
descAr = json['descAr'];
|
||||
winDeciderTime = json['winDeciderTime'];
|
||||
winnersCount = json['winnersCount'];
|
||||
questGapTime = json['questGapTime'];
|
||||
startTime = json['startTime'];
|
||||
endTime = json['endTime'];
|
||||
marathoneStatusId = json['marathoneStatusId'];
|
||||
scheduleTime = json['scheduleTime'];
|
||||
selectedLanguage = json['selectedLanguage'];
|
||||
projects = json['projects'];
|
||||
sponsors = json['sponsors'];
|
||||
if (json['questions'] != null) {
|
||||
questions = <Null>[];
|
||||
json['questions'].forEach((v) {
|
||||
// questions!.add( Null.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = id;
|
||||
data['titleEn'] = titleEn;
|
||||
data['titleAr'] = titleAr;
|
||||
data['descEn'] = descEn;
|
||||
data['descAr'] = descAr;
|
||||
data['winDeciderTime'] = winDeciderTime;
|
||||
data['winnersCount'] = winnersCount;
|
||||
data['questGapTime'] = questGapTime;
|
||||
data['startTime'] = startTime;
|
||||
data['endTime'] = endTime;
|
||||
data['marathoneStatusId'] = marathoneStatusId;
|
||||
data['scheduleTime'] = scheduleTime;
|
||||
data['selectedLanguage'] = selectedLanguage;
|
||||
data['projects'] = projects;
|
||||
data['sponsors'] = sponsors;
|
||||
if (questions != null) {
|
||||
data['questions'] = questions!.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue