From 09fd1d5a9b5b727acb6ee0d3c4393d1e76306d6b Mon Sep 17 00:00:00 2001 From: Ryan Oberlander Date: Fri, 18 Apr 2025 17:41:44 -0500 Subject: [PATCH 1/5] update loadDirectoryAccounts to use v2 endpoint [#590] --- lib/model/auth2.directory.dart | 33 ++++++++++++++++++++++++++++++++ lib/service/auth2.directory.dart | 23 ++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/model/auth2.directory.dart b/lib/model/auth2.directory.dart index b35ee6206..964de13b3 100644 --- a/lib/model/auth2.directory.dart +++ b/lib/model/auth2.directory.dart @@ -4,6 +4,39 @@ import 'package:collection/collection.dart'; import 'package:rokwire_plugin/model/auth2.dart'; import 'package:rokwire_plugin/utils/utils.dart'; +////////////////////////////////////////// +// Auth2PublicAccountsResult + +class Auth2PublicAccountsResult { + final List? accounts; + final Map? indexCounts; + final int? totalCount; + + Auth2PublicAccountsResult({this.accounts, this.indexCounts, this.totalCount}); + + static Auth2PublicAccountsResult? fromJson(Map? json) { + if (json != null) { + Map indexCounts = {}; + Map? indexCountsJson = JsonUtils.mapValue(json['total']); + for (MapEntry count in indexCountsJson?.entries ?? []) { + indexCounts[count.key] = (count.value is int) ? count.value : 0; + } + + return Auth2PublicAccountsResult( + accounts: Auth2PublicAccount.listFromJson(JsonUtils.listValue(json['accounts'])), + indexCounts: indexCounts, + totalCount: JsonUtils.intValue(json['total']), + ); + } + return null; + } + + Map toJson() => { + 'accounts': Auth2PublicAccount.listToJson(accounts), + 'total': totalCount, + }; +} + ////////////////////////////////////////// // Auth2PublicAccount diff --git a/lib/service/auth2.directory.dart b/lib/service/auth2.directory.dart index 1254b914f..6a4e00e06 100644 --- a/lib/service/auth2.directory.dart +++ b/lib/service/auth2.directory.dart @@ -15,15 +15,17 @@ List? _sampleDirectoryAccounts; extension Auh2Directory on Auth2 { static const String attributesScope = 'app-directory'; + static const String loadDirectoryAccountsAscending = 'asc'; + static const String loadDirectoryAccountsDescending = 'desc'; ContentAttributes? get directoryAttributes => Content().contentAttributes(attributesScope); - Future?> loadDirectoryAccounts({String? search, + Future loadDirectoryAccounts({String? search, String? userName, String? firstName, String? lastName, Iterable? ids, String? followingId, String? followerId, - Map? attriutes, - int? offset, int? limit}) async { + Map? attributes, + String? nameOffset, int? limit, String order = loadDirectoryAccountsAscending}) async { //TMP: //return _sampleAccounts; @@ -33,7 +35,7 @@ extension Auh2Directory on Auth2 { // ignore: dead_code if (Config().coreUrl != null) { - String url = UrlUtils.addQueryParameters("${Config().coreUrl}/services/accounts/public", { + String url = UrlUtils.addQueryParameters("${Config().coreUrl}/services/v2/accounts/public", { if (search != null) 'search': search, @@ -52,17 +54,18 @@ extension Auh2Directory on Auth2 { if (followerId != null) 'follower-id': followerId, - if (offset != null) - 'offset': offset.toString(), + if (nameOffset != null) + 'name-offset': nameOffset, if (limit != null) 'limit': limit.toString(), - - if (attriutes != null) - ...attriutes.map((k, v) => MapEntry(k, (v is List) ? v.join(',') : v.toString())) + 'order': order, + + if (attributes != null) + ...attributes.map((k, v) => MapEntry(k, (v is List) ? v.join(',') : v.toString())) }); Response? response = await Network().get(url, auth: Auth2()); - return (response?.statusCode == 200) ? Auth2PublicAccount.listFromJson(JsonUtils.decodeList(response?.body)) : null; + return (response?.statusCode == 200) ? Auth2PublicAccountsResult.fromJson(JsonUtils.decodeMap(response?.body)) : null; } return null; } From c3d390b208256c6996bfe63521f96968c22943ec Mon Sep 17 00:00:00 2001 From: Ryan Oberlander Date: Mon, 21 Apr 2025 17:18:56 -0500 Subject: [PATCH 2/5] change name-offset back to offset [#590] --- lib/service/auth2.directory.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/service/auth2.directory.dart b/lib/service/auth2.directory.dart index 6a4e00e06..2228ac2ca 100644 --- a/lib/service/auth2.directory.dart +++ b/lib/service/auth2.directory.dart @@ -25,7 +25,7 @@ extension Auh2Directory on Auth2 { String? userName, String? firstName, String? lastName, Iterable? ids, String? followingId, String? followerId, Map? attributes, - String? nameOffset, int? limit, String order = loadDirectoryAccountsAscending}) async { + String? offset, int? limit, String order = loadDirectoryAccountsAscending}) async { //TMP: //return _sampleAccounts; @@ -54,8 +54,8 @@ extension Auh2Directory on Auth2 { if (followerId != null) 'follower-id': followerId, - if (nameOffset != null) - 'name-offset': nameOffset, + if (offset != null) + 'offset': offset, if (limit != null) 'limit': limit.toString(), 'order': order, From ca973e539624fccb17e8443a8a58a23787ce7e34 Mon Sep 17 00:00:00 2001 From: Ryan Oberlander Date: Thu, 24 Apr 2025 00:06:04 -0500 Subject: [PATCH 3/5] fix index counts parsing for Auth2PublicAccountsResult [#590] --- lib/model/auth2.directory.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/model/auth2.directory.dart b/lib/model/auth2.directory.dart index 964de13b3..ad19cf2cb 100644 --- a/lib/model/auth2.directory.dart +++ b/lib/model/auth2.directory.dart @@ -17,7 +17,7 @@ class Auth2PublicAccountsResult { static Auth2PublicAccountsResult? fromJson(Map? json) { if (json != null) { Map indexCounts = {}; - Map? indexCountsJson = JsonUtils.mapValue(json['total']); + Map? indexCountsJson = JsonUtils.mapValue(json['counts']); for (MapEntry count in indexCountsJson?.entries ?? []) { indexCounts[count.key] = (count.value is int) ? count.value : 0; } @@ -33,6 +33,7 @@ class Auth2PublicAccountsResult { Map toJson() => { 'accounts': Auth2PublicAccount.listToJson(accounts), + 'counts': indexCounts, 'total': totalCount, }; } From a135bacfed0827ef33191b4e046cf754706ce112 Mon Sep 17 00:00:00 2001 From: Ryan Oberlander Date: Tue, 29 Apr 2025 00:37:23 -0500 Subject: [PATCH 4/5] change order param to reverse [#590] --- lib/service/auth2.directory.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/service/auth2.directory.dart b/lib/service/auth2.directory.dart index 2228ac2ca..c0fb5cb91 100644 --- a/lib/service/auth2.directory.dart +++ b/lib/service/auth2.directory.dart @@ -25,7 +25,7 @@ extension Auh2Directory on Auth2 { String? userName, String? firstName, String? lastName, Iterable? ids, String? followingId, String? followerId, Map? attributes, - String? offset, int? limit, String order = loadDirectoryAccountsAscending}) async { + String? offset, int? limit, bool reverse = false}) async { //TMP: //return _sampleAccounts; @@ -58,7 +58,7 @@ extension Auh2Directory on Auth2 { 'offset': offset, if (limit != null) 'limit': limit.toString(), - 'order': order, + 'order': reverse ? loadDirectoryAccountsDescending : loadDirectoryAccountsAscending, if (attributes != null) ...attributes.map((k, v) => MapEntry(k, (v is List) ? v.join(',') : v.toString())) From aa42f1bfaa05f7968da95369307bc28e13262f4b Mon Sep 17 00:00:00 2001 From: Ryan Oberlander Date: Tue, 29 Apr 2025 01:08:04 -0500 Subject: [PATCH 5/5] update changelog [#590] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e9547a2..edf3e6720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - PlatformUtils moved to plugin, extended with environment retrieval [#4950](https://github.com/rokwire/illinois-app/issues/4950). - Implemented Event2 duplication API, make satellite classes immutable [#5013](https://github.com/rokwire/illinois-app/issues/5013). - Events2.loadGroupEvents updated to get time filter parameter, cleaned up sort type setting [#5022](https://github.com/rokwire/illinois-app/issues/5022). +- Update directory accounts loading [#590](https://github.com/rokwire/app-flutter-plugin/issues/590). ## [1.8.3] - 2025-03-12 ### Added