passo_mobile_app/lib/utils/profile_utilities.dart

145 lines
4.4 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:unit2/model/location/country.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/model/location/region.dart';
2023-02-20 07:48:24 +00:00
import 'package:unit2/model/utils/eligibility.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
2023-04-05 00:54:24 +00:00
import '../model/profile/basic_information/contact_information.dart';
import '../model/utils/agency.dart';
import '../model/utils/category.dart';
2023-04-25 07:50:36 +00:00
import '../model/utils/position.dart';
class ProfileUtilities {
static final ProfileUtilities _instance = ProfileUtilities();
static ProfileUtilities get instance => _instance;
2023-04-25 07:50:36 +00:00
Future<List<Eligibility>> getEligibilities() async {
List<Eligibility> eligibilities = [];
String path = Url.instance.eligibilities();
2023-04-25 07:50:36 +00:00
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
2023-04-25 07:50:36 +00:00
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 eligibility) {
Eligibility newEligibilities = Eligibility.fromJson(eligibility);
eligibilities.add(newEligibilities);
});
}
}
} catch (e) {
throw (e.toString());
}
2023-04-25 07:50:36 +00:00
return eligibilities;
2023-04-05 00:54:24 +00:00
}
2023-04-25 07:50:36 +00:00
////get agency position
Future<List<Position>> getAgencyPosition() async {
List<Position> agencyPositions = [];
String path = Url.instance.getPositions();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
data['data'].forEach((var agencyPosition) {
Position position = Position.fromJson(agencyPosition);
agencyPositions.add(position);
});
}
}
} catch (e) {
throw (e.toString());
}
return agencyPositions;
}
2023-04-25 07:50:36 +00:00
////get agencies
Future<List<Agency>> getAgecies() async {
List<Agency> agencies = [];
String path = Url.instance.getAgencies();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
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 agency) {
Agency newAgency = Agency.fromJson(agency);
agencies.add(newAgency);
});
}
}
} catch (e) {
throw e.toString();
}
return agencies;
}
2023-04-25 07:50:36 +00:00
////get agency category
Future<List<Category>> agencyCategory() async {
List<Category> agencyCategory = [];
String path = Url.instance.getAgencyCategory();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
data['data'].forEach((var agency) {
Category category = Category.fromJson(agency);
agencyCategory.add(category);
});
}
}
} catch (e) {
throw e.toString();
}
return agencyCategory;
}
2023-04-05 00:54:24 +00:00
//// get service type
2023-04-25 07:50:36 +00:00
Future<List<ServiceType>> getServiceType() async {
2023-04-05 00:54:24 +00:00
List<ServiceType> serviceTypes = [];
2023-04-25 07:50:36 +00:00
Map<String, String> headers = {
2023-04-05 00:54:24 +00:00
'Content-Type': 'application/json; charset=UTF-8',
};
String path = Url.instance.getServiceTypes();
2023-04-25 07:50:36 +00:00
try {
http.Response response = await Request.instance
.getRequest(param: {}, path: path, headers: headers);
if (response.statusCode == 200) {
2023-04-05 00:54:24 +00:00
Map data = jsonDecode(response.body);
2023-04-25 07:50:36 +00:00
if (data['data'] != null) {
for (var element in data['data']) {
2023-04-05 00:54:24 +00:00
ServiceType newServiceType = ServiceType.fromJson(element);
serviceTypes.add(newServiceType);
}
}
}
2023-04-25 07:50:36 +00:00
} catch (e) {
2023-04-05 00:54:24 +00:00
throw e.toString();
}
return serviceTypes;
}
2023-04-25 07:50:36 +00:00
}