155 lines
4.5 KiB
Dart
155 lines
4.5 KiB
Dart
import 'dart:convert';
|
|
|
|
LeaderboardParticipentListResponseModel
|
|
leaderboardParticipentListResponseModelFromJson(String str) =>
|
|
LeaderboardParticipentListResponseModel.fromJson(json.decode(str));
|
|
|
|
String leaderboardParticipentListResponseModelToJson(
|
|
LeaderboardParticipentListResponseModel data,
|
|
) => json.encode(data.toJson());
|
|
|
|
class LeaderboardParticipentListResponseModel {
|
|
bool? isSuccess;
|
|
int? statusCode;
|
|
String? message;
|
|
ChallengeLeaderBoardData? data;
|
|
dynamic errors;
|
|
|
|
LeaderboardParticipentListResponseModel({
|
|
this.isSuccess,
|
|
this.statusCode,
|
|
this.message,
|
|
this.data,
|
|
this.errors,
|
|
});
|
|
|
|
factory LeaderboardParticipentListResponseModel.fromJson(
|
|
Map<String, dynamic> json,
|
|
) => LeaderboardParticipentListResponseModel(
|
|
isSuccess: json["isSuccess"],
|
|
statusCode: _parseToInt(json["statusCode"]),
|
|
message: json["message"],
|
|
data:
|
|
json["data"] == null
|
|
? null
|
|
: ChallengeLeaderBoardData.fromJson(json["data"]),
|
|
errors: json["errors"],
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"isSuccess": isSuccess,
|
|
"statusCode": statusCode,
|
|
"message": message,
|
|
"data": data?.toJson(),
|
|
"errors": errors,
|
|
};
|
|
}
|
|
|
|
class ChallengeLeaderBoardData {
|
|
int? totalCount;
|
|
List<SingleUserLeaderboard>? items;
|
|
|
|
ChallengeLeaderBoardData({this.totalCount, this.items});
|
|
|
|
factory ChallengeLeaderBoardData.fromJson(Map<String, dynamic> json) =>
|
|
ChallengeLeaderBoardData(
|
|
totalCount: _parseToInt(json["totalCount"]),
|
|
items:
|
|
json["items"] == null
|
|
? []
|
|
: List<SingleUserLeaderboard>.from(
|
|
json["items"]!.map((x) => SingleUserLeaderboard.fromJson(x)),
|
|
),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"totalCount": totalCount,
|
|
"items":
|
|
items == null ? [] : List<dynamic>.from(items!.map((x) => x.toJson())),
|
|
};
|
|
}
|
|
|
|
class SingleUserLeaderboard {
|
|
int? challengeId;
|
|
int? challengeParticipationId;
|
|
String? userId;
|
|
String? firstName;
|
|
String? lastName;
|
|
String? fullName;
|
|
String? profilePicture;
|
|
String? status;
|
|
int? challengeProgressTrackingId;
|
|
int? challengeConsistency;
|
|
int? challengeProgressPercentage;
|
|
int? leaderboardScore;
|
|
bool? isComplete;
|
|
|
|
SingleUserLeaderboard({
|
|
this.challengeId,
|
|
this.challengeParticipationId,
|
|
this.userId,
|
|
this.firstName,
|
|
this.lastName,
|
|
this.fullName,
|
|
this.profilePicture,
|
|
this.status,
|
|
this.challengeProgressTrackingId,
|
|
this.challengeConsistency,
|
|
this.challengeProgressPercentage,
|
|
this.leaderboardScore,
|
|
this.isComplete,
|
|
});
|
|
|
|
factory SingleUserLeaderboard.fromJson(Map<String, dynamic> json) =>
|
|
SingleUserLeaderboard(
|
|
challengeId: _parseToInt(json["challengeID"]),
|
|
challengeParticipationId: _parseToInt(json["challengeParticipationID"]),
|
|
userId: json["userID"]?.toString(),
|
|
firstName: json["firstName"]?.toString(),
|
|
lastName: json["lastName"]?.toString(),
|
|
fullName: json["fullName"]?.toString(),
|
|
profilePicture: json["profilePicture"]?.toString(),
|
|
status: json["status"]?.toString(),
|
|
challengeProgressTrackingId: _parseToInt(
|
|
json["challengeProgressTrackingID"],
|
|
),
|
|
challengeConsistency: _parseToInt(json["challengeConsistency"]),
|
|
challengeProgressPercentage: _parseToInt(
|
|
json["challengeProgressPercentage"],
|
|
),
|
|
leaderboardScore: _parseToInt(json["leaderboardScore"]),
|
|
isComplete:
|
|
json["isComplete"] is bool
|
|
? json["isComplete"]
|
|
: json["isComplete"]?.toString().toLowerCase() == 'true',
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"challengeID": challengeId,
|
|
"challengeParticipationID": challengeParticipationId,
|
|
"userID": userId,
|
|
"firstName": firstName,
|
|
"lastName": lastName,
|
|
"fullName": fullName,
|
|
"profilePicture": profilePicture,
|
|
"status": status,
|
|
"challengeProgressTrackingID": challengeProgressTrackingId,
|
|
"challengeConsistency": challengeConsistency,
|
|
"challengeProgressPercentage": challengeProgressPercentage,
|
|
"leaderboardScore": leaderboardScore,
|
|
"isComplete": isComplete,
|
|
};
|
|
}
|
|
|
|
// Helper function to safely parse values to int
|
|
int? _parseToInt(dynamic value) {
|
|
if (value == null) return null;
|
|
if (value is int) return value;
|
|
if (value is double) return value.round();
|
|
if (value is String) {
|
|
final parsed = double.tryParse(value);
|
|
return parsed?.round();
|
|
}
|
|
return null;
|
|
}
|