You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
Dart
57 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:http/http.dart';
|
|
|
|
import 'package:fluffychat/pangea/activity_planner/list_request_schema.dart';
|
|
import 'package:fluffychat/pangea/common/config/environment.dart';
|
|
import 'package:fluffychat/pangea/common/network/urls.dart';
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
import '../common/network/requests.dart';
|
|
|
|
class TopicListRepo {
|
|
static final GetStorage _topicListStorage = GetStorage('topic_list_storage');
|
|
|
|
static void set(
|
|
ActivitySettingRequestSchema request,
|
|
List<ActivitySettingResponseSchema> response,
|
|
) {
|
|
_topicListStorage.write(
|
|
request.storageKey,
|
|
response.map((e) => e.toJson()).toList(),
|
|
);
|
|
}
|
|
|
|
static List<ActivitySettingResponseSchema> fromJson(Iterable json) {
|
|
return List<ActivitySettingResponseSchema>.from(
|
|
json.map((x) => ActivitySettingResponseSchema.fromJson(x)),
|
|
);
|
|
}
|
|
|
|
static Future<List<ActivitySettingResponseSchema>> get(
|
|
ActivitySettingRequestSchema request,
|
|
) async {
|
|
final cachedJson = _topicListStorage.read(request.storageKey);
|
|
if (cachedJson != null) {
|
|
return TopicListRepo.fromJson(cachedJson);
|
|
}
|
|
|
|
final Requests req = Requests(
|
|
choreoApiKey: Environment.choreoApiKey,
|
|
accessToken: MatrixState.pangeaController.userController.accessToken,
|
|
);
|
|
|
|
final Response res = await req.post(
|
|
url: PApiUrls.topicList,
|
|
body: request.toJson(),
|
|
);
|
|
|
|
final decodedBody = jsonDecode(utf8.decode(res.bodyBytes));
|
|
final response = TopicListRepo.fromJson(decodedBody);
|
|
|
|
set(request, response);
|
|
|
|
return response;
|
|
}
|
|
}
|