39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:unit2/utils/request.dart';
|
|
import '../../model/profile/voluntary_works.dart';
|
|
import '../../utils/urls.dart';
|
|
|
|
class VoluntaryService{
|
|
static final VoluntaryService _instance = VoluntaryService();
|
|
static VoluntaryService get instance => _instance;
|
|
|
|
Future< List<VoluntaryWork>> getVoluntaryWorks(int profileId, String token)async{
|
|
List<VoluntaryWork> voluntaryWorks = [];
|
|
String authToken = "Token $token";
|
|
String path = "${Url.instance.getVoluntaryWorks()}$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 work){
|
|
VoluntaryWork voluntaryWork = VoluntaryWork.fromJson(work);
|
|
voluntaryWorks.add(voluntaryWork);
|
|
});
|
|
}
|
|
}
|
|
}catch(e){
|
|
throw(e.toString());
|
|
}
|
|
|
|
return voluntaryWorks;
|
|
}
|
|
} |