passo_mobile_app/lib/sevices/profile/non_academic_services.dart

42 lines
1.4 KiB
Dart

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';
import '../../model/profile/other_information/non_acedimic_recognition.dart';
import '../../utils/urls.dart';
class NonAcademicRecognitionServices {
static final NonAcademicRecognitionServices _instance =
NonAcademicRecognitionServices();
static NonAcademicRecognitionServices get instance => _instance;
Future<List<NonAcademicRecognition>> getNonAcademicRecognition(
int profileId, String token) async {
List<NonAcademicRecognition> nonAcademicRecognitions = [];
String authToken = "Token $token";
String path = "${Url.instance.getNonAcademicRecognition()}$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 recognition) {
NonAcademicRecognition nonAcademicRecognition =
NonAcademicRecognition.fromJson(recognition);
nonAcademicRecognitions.add(nonAcademicRecognition);
});
}
}
} catch (e) {
throw e.toString();
}
return nonAcademicRecognitions;
}
}