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.
73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
|
|
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
|
import 'package:http/http.dart';
|
|
|
|
import '../models/user_model.dart';
|
|
import '../models/user_profile_search_model.dart';
|
|
import '../network/requests.dart';
|
|
import '../network/urls.dart';
|
|
|
|
class PUserRepo {
|
|
static Future<PangeaProfileResponse?> fetchPangeaUserInfo({
|
|
required String userID,
|
|
required String matrixAccessToken,
|
|
}) async {
|
|
Response res;
|
|
try {
|
|
final Requests req = Requests(
|
|
baseUrl: PApiUrls.baseAPI,
|
|
matrixAccessToken: matrixAccessToken,
|
|
);
|
|
res = await req.get(
|
|
url: PApiUrls.userDetails,
|
|
objectId: userID,
|
|
);
|
|
|
|
return PangeaProfileResponse.fromJson(jsonDecode(res.body));
|
|
} catch (err) {
|
|
//status code should be 400 - PTODO - check ffor this.
|
|
log("Most likely a first signup and needs to make an account");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static Future<UserProfileSearchResponse> searchUserProfiles({
|
|
// List<String>? interests,
|
|
String? targetLanguage,
|
|
String? sourceLanguage,
|
|
String? country,
|
|
// String? speaks,
|
|
String? pageNumber,
|
|
required String accessToken,
|
|
required int limit,
|
|
}) async {
|
|
final Requests req = Requests(
|
|
baseUrl: PApiUrls.baseAPI,
|
|
accessToken: accessToken,
|
|
);
|
|
final Map<String, dynamic> body = {};
|
|
// if (interests != null) body[ModelKey.userInterests] = interests.toString();
|
|
if (targetLanguage != null) {
|
|
body[ModelKey.userTargetLanguage] = targetLanguage;
|
|
}
|
|
if (sourceLanguage != null) {
|
|
body[ModelKey.userSourceLanguage] = sourceLanguage;
|
|
}
|
|
if (country != null) body[ModelKey.userCountry] = country;
|
|
|
|
final String searchUrl =
|
|
"${PApiUrls.searchUserProfiles}?limit=$limit${pageNumber != null ? '&page=$pageNumber' : ''}";
|
|
|
|
final Response res = await req.post(
|
|
url: searchUrl,
|
|
body: body,
|
|
);
|
|
|
|
//PTODO - implement paginiation - make another call with next url
|
|
|
|
return UserProfileSearchResponse.fromJson(jsonDecode(res.body));
|
|
}
|
|
}
|