Bläddra i källkod

UserService: Support to fetch user/details/v2

Neeraj Gupta 3 år sedan
förälder
incheckning
9000974fb6
2 ändrade filer med 76 tillägg och 0 borttagningar
  1. 58 0
      lib/models/user_details.dart
  2. 18 0
      lib/services/user_service.dart

+ 58 - 0
lib/models/user_details.dart

@@ -6,6 +6,7 @@ class UserDetails {
   final int fileCount;
   final int fileCount;
   final int sharedCollectionsCount;
   final int sharedCollectionsCount;
   final Subscription subscription;
   final Subscription subscription;
+  final FamilyData familyData;
 
 
   UserDetails(
   UserDetails(
     this.email,
     this.email,
@@ -13,6 +14,7 @@ class UserDetails {
     this.fileCount,
     this.fileCount,
     this.sharedCollectionsCount,
     this.sharedCollectionsCount,
     this.subscription,
     this.subscription,
+    this.familyData,
   );
   );
 
 
   factory UserDetails.fromMap(Map<String, dynamic> map) {
   factory UserDetails.fromMap(Map<String, dynamic> map) {
@@ -22,6 +24,7 @@ class UserDetails {
       map['fileCount'] as int,
       map['fileCount'] as int,
       map['sharedCollectionsCount'] as int,
       map['sharedCollectionsCount'] as int,
       Subscription.fromMap(map['subscription']),
       Subscription.fromMap(map['subscription']),
+      FamilyData.fromMap(map['familyData']),
     );
     );
   }
   }
 
 
@@ -32,6 +35,61 @@ class UserDetails {
       'fileCount': fileCount,
       'fileCount': fileCount,
       'sharedCollectionsCount': sharedCollectionsCount,
       'sharedCollectionsCount': sharedCollectionsCount,
       'subscription': subscription,
       'subscription': subscription,
+      'familyData': familyData
+    };
+  }
+}
+
+class FamilyMember {
+  final String email;
+  final int usage;
+  final String id;
+  final bool isAdmin;
+
+  FamilyMember(this.email, this.usage, this.id, this.isAdmin);
+
+  factory FamilyMember.fromMap(Map<String, dynamic> map) {
+    return FamilyMember(
+      (map['email'] ?? '') as String,
+      map['usage'] as int,
+      map['id'] as String,
+      map['isAdmin'] as bool,
+    );
+  }
+
+  Map<String, dynamic> toMap() {
+    return {'email': email, 'usage': usage, 'id': id, 'isAdmin': isAdmin};
+  }
+}
+
+class FamilyData {
+  final List<FamilyMember> members;
+
+  // Storage available based on the family plan
+  final int storage;
+  final int expiry;
+
+  FamilyData(this.members, this.storage, this.expiry);
+
+  factory FamilyData.fromMap(Map<String, dynamic> map) {
+    if (map == null) {
+      return null;
+    }
+    assert(map['members'] != null && map['members'].length >= 0);
+    final members = List<FamilyMember>.from(
+        map['members'].map((x) => FamilyMember.fromMap(x)));
+    return FamilyData(
+      members,
+      map['storage'] as int,
+      map['expiry'] as int,
+    );
+  }
+
+  Map<String, dynamic> toMap() {
+    return {
+      'members': members.map((x) => x?.toMap())?.toList(),
+      'storage': storage,
+      'expiry': expiry
     };
     };
   }
   }
 }
 }

+ 18 - 0
lib/services/user_service.dart

@@ -121,6 +121,24 @@ class UserService {
     }
     }
   }
   }
 
 
+  Future<UserDetails> getUserDetailsV2({bool memberCount = true}) async {
+    try {
+      final response = await _dio.get(
+        _config.getHttpEndpoint() +
+            "/users/details/v2?memoryCount=$memberCount",
+        options: Options(
+          headers: {
+            "X-Auth-Token": _config.getToken(),
+          },
+        ),
+      );
+      return UserDetails.fromMap(response.data);
+    } on DioError catch (e) {
+      _logger.info(e);
+      rethrow;
+    }
+  }
+
   Future<Sessions> getActiveSessions() async {
   Future<Sessions> getActiveSessions() async {
     try {
     try {
       final response = await _dio.get(
       final response = await _dio.get(