40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
|
|
||
|
|
||
|
|
||
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:unit2/utils/request.dart';
|
||
|
|
||
|
import '../../model/profile/references.dart';
|
||
|
import '../../utils/urls.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
class ReferencesServices{
|
||
|
static final ReferencesServices _instance = ReferencesServices();
|
||
|
static ReferencesServices get instace => _instance;
|
||
|
|
||
|
Future<List<PersonalReference>> getRefences(int profileId, String token)async{
|
||
|
|
||
|
List<PersonalReference> references = [];
|
||
|
String authToken = "Token $token";
|
||
|
String path = "${Url.instance.getRefences()}$profileId/";
|
||
|
Map<String, String> headers = {
|
||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||
|
'Authorization': authToken
|
||
|
};
|
||
|
try{
|
||
|
http.Response response = await Request.instance.getRequest(path: path,param: {},headers: headers);
|
||
|
if(response.statusCode == 200){
|
||
|
Map data = jsonDecode(response.body);
|
||
|
if(data['data'] != null){
|
||
|
data['data'].forEach((var ref){
|
||
|
PersonalReference reference = PersonalReference.fromJson(ref);
|
||
|
references.add(reference);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}catch(e){
|
||
|
throw e.toString();
|
||
|
}
|
||
|
return references;
|
||
|
}
|
||
|
}
|