42 lines
1.3 KiB
Dart
42 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:unit2/model/profile/educational_background.dart';
|
|
import 'package:unit2/utils/request.dart';
|
|
|
|
import '../../utils/urls.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class EducationService {
|
|
static final EducationService _instance = EducationService();
|
|
static EducationService get instace => _instance;
|
|
|
|
Future<List<EducationalBackground>> getEducationalBackground(
|
|
int profileId, String token) async {
|
|
List<EducationalBackground> educationalBackgrounds = [];
|
|
String authToken = "Token $token";
|
|
String path = "${Url.instance.getEducationalBackgrounds()}$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 education) {
|
|
EducationalBackground educationalBackground =
|
|
EducationalBackground.fromJson(education);
|
|
educationalBackgrounds.add(educationalBackground);
|
|
});
|
|
}
|
|
}
|
|
} catch (e) {
|
|
throw e.toString();
|
|
}
|
|
|
|
return educationalBackgrounds;
|
|
}
|
|
}
|