Referral: Add gateway and model classes
This commit is contained in:
parent
72bcfa989f
commit
a149e661f5
22
lib/gateways/storage_bonus_gw.dart
Normal file
22
lib/gateways/storage_bonus_gw.dart
Normal file
|
@ -0,0 +1,22 @@
|
|||
import "package:dio/dio.dart";
|
||||
import "package:photos/models/api/storage_bonus/storage_bonus.dart";
|
||||
|
||||
class StorageBonusGateway {
|
||||
final Dio _enteDio;
|
||||
|
||||
StorageBonusGateway(this._enteDio);
|
||||
|
||||
Future<ReferralView> getReferralView() async {
|
||||
final response = await _enteDio.get("/storage-bonus/referral-view");
|
||||
return ReferralView.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<void> claimReferralCode(String code) {
|
||||
return _enteDio.post("/storage-bonus/referral-claim?code=$code");
|
||||
}
|
||||
|
||||
Future<BonusDetails> getBonusDetails() async {
|
||||
final response = await _enteDio.get("/storage-bonus/details");
|
||||
return BonusDetails.fromJson(response.data);
|
||||
}
|
||||
}
|
146
lib/models/api/storage_bonus/storage_bonus.dart
Normal file
146
lib/models/api/storage_bonus/storage_bonus.dart
Normal file
|
@ -0,0 +1,146 @@
|
|||
class ReferralView {
|
||||
PlanInfo planInfo;
|
||||
String code;
|
||||
bool enableApplyCode;
|
||||
bool isFamilyMember;
|
||||
bool hasAppliedCode;
|
||||
|
||||
ReferralView({
|
||||
required this.planInfo,
|
||||
required this.code,
|
||||
required this.enableApplyCode,
|
||||
required this.isFamilyMember,
|
||||
required this.hasAppliedCode,
|
||||
});
|
||||
|
||||
factory ReferralView.fromJson(Map<String, dynamic> json) => ReferralView(
|
||||
planInfo: PlanInfo.fromJson(json["planInfo"]),
|
||||
code: json["code"],
|
||||
enableApplyCode: json["enableApplyCode"],
|
||||
isFamilyMember: json["isFamilyMember"],
|
||||
hasAppliedCode: json["hasAppliedCode"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"planInfo": planInfo.toJson(),
|
||||
"code": code,
|
||||
"enableApplyCode": enableApplyCode,
|
||||
"isFamilyMember": isFamilyMember,
|
||||
"hasAppliedCode": hasAppliedCode,
|
||||
};
|
||||
}
|
||||
|
||||
class PlanInfo {
|
||||
bool isEnabled;
|
||||
String planType;
|
||||
int storageInGB;
|
||||
int maxClaimableStorageInGB;
|
||||
|
||||
PlanInfo({
|
||||
required this.isEnabled,
|
||||
required this.planType,
|
||||
required this.storageInGB,
|
||||
required this.maxClaimableStorageInGB,
|
||||
});
|
||||
|
||||
factory PlanInfo.fromJson(Map<String, dynamic> json) => PlanInfo(
|
||||
isEnabled: json["isEnabled"],
|
||||
planType: json["planType"],
|
||||
storageInGB: json["storageInGB"],
|
||||
maxClaimableStorageInGB: json["maxClaimableStorageInGB"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"isEnabled": isEnabled,
|
||||
"planType": planType,
|
||||
"storageInGB": storageInGB,
|
||||
"maxClaimableStorageInGB": maxClaimableStorageInGB,
|
||||
};
|
||||
}
|
||||
|
||||
class ReferralStat {
|
||||
String planType;
|
||||
int totalCount;
|
||||
int upgradedCount;
|
||||
|
||||
ReferralStat(this.planType, this.totalCount, this.upgradedCount);
|
||||
|
||||
factory ReferralStat.fromJson(Map<String, dynamic> json) {
|
||||
return ReferralStat(
|
||||
json['planType'],
|
||||
json['totalCount'],
|
||||
json['upgradedCount'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'planType': planType,
|
||||
'totalCount': totalCount,
|
||||
'upgradedCount': upgradedCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Bonus {
|
||||
int storage;
|
||||
String type;
|
||||
int validTill;
|
||||
bool isRevoked;
|
||||
|
||||
Bonus(this.storage, this.type, this.validTill, this.isRevoked);
|
||||
|
||||
// fromJson
|
||||
factory Bonus.fromJson(Map<String, dynamic> json) {
|
||||
return Bonus(
|
||||
json['storage'],
|
||||
json['type'],
|
||||
json['validTill'],
|
||||
json['isRevoked'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'storage': storage,
|
||||
'type': type,
|
||||
'validTill': validTill,
|
||||
'isRevoked': isRevoked,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class BonusDetails {
|
||||
List<ReferralStat> referralStats;
|
||||
List<Bonus> bonuses;
|
||||
int refCount;
|
||||
int refUpgradeCount;
|
||||
bool hasAppliedCode;
|
||||
|
||||
BonusDetails({
|
||||
required this.referralStats,
|
||||
required this.bonuses,
|
||||
required this.refCount,
|
||||
required this.refUpgradeCount,
|
||||
required this.hasAppliedCode,
|
||||
});
|
||||
|
||||
factory BonusDetails.fromJson(Map<String, dynamic> json) => BonusDetails(
|
||||
referralStats: List<ReferralStat>.from(
|
||||
json["referralStats"].map((x) => ReferralStat.fromJson(x))),
|
||||
bonuses:
|
||||
List<Bonus>.from(json["bonuses"].map((x) => Bonus.fromJson(x))),
|
||||
refCount: json["refCount"],
|
||||
refUpgradeCount: json["refUpgradeCount"],
|
||||
hasAppliedCode: json["hasAppliedCode"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"referralStats":
|
||||
List<dynamic>.from(referralStats.map((x) => x.toJson())),
|
||||
"bonuses": List<dynamic>.from(bonuses.map((x) => x.toJson())),
|
||||
"refCount": refCount,
|
||||
"refUpgradeCount": refUpgradeCount,
|
||||
"hasAppliedCode": hasAppliedCode,
|
||||
};
|
||||
}
|
18
lib/services/storage_bonus_service.dart
Normal file
18
lib/services/storage_bonus_service.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
import "package:photos/core/network/network.dart";
|
||||
import "package:photos/gateways/storage_bonus_gw.dart";
|
||||
import "package:shared_preferences/shared_preferences.dart";
|
||||
|
||||
class StorageBonusService {
|
||||
late StorageBonusGateway gateway;
|
||||
late SharedPreferences prefs;
|
||||
|
||||
void init(SharedPreferences preferences) {
|
||||
prefs = preferences;
|
||||
gateway = StorageBonusGateway(NetworkClient.instance.enteDio);
|
||||
}
|
||||
|
||||
StorageBonusService._privateConstructor();
|
||||
|
||||
static StorageBonusService instance =
|
||||
StorageBonusService._privateConstructor();
|
||||
}
|
Loading…
Reference in a new issue