2023-02-01 08:03:05 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:unit2/model/profile/basic_info.dart';
|
2023-02-08 03:07:30 +00:00
|
|
|
import 'package:unit2/model/profile/basic_information/adress.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
import 'package:unit2/model/profile/basic_information/citizenship.dart';
|
2023-02-01 08:03:05 +00:00
|
|
|
import 'package:unit2/model/profile/basic_information/contact_information.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
import 'package:unit2/model/profile/basic_information/identification_information.dart';
|
2023-02-01 08:03:05 +00:00
|
|
|
import 'package:unit2/model/profile/profileInfomation.dart';
|
|
|
|
import 'package:unit2/utils/urls.dart';
|
|
|
|
import '../../model/profile/basic_information/primary-information.dart';
|
2023-06-06 06:54:51 +00:00
|
|
|
import '../../utils/request.dart';
|
2023-02-01 08:03:05 +00:00
|
|
|
|
|
|
|
class ProfileService {
|
|
|
|
static final ProfileService _instance = ProfileService();
|
|
|
|
static ProfileService get instance => _instance;
|
|
|
|
|
|
|
|
Future<ProfileInformation?> getProfile(String token, int id) async {
|
|
|
|
String url = Url.instance.profileInformation();
|
|
|
|
String path = url + id.toString();
|
2023-02-07 01:29:38 +00:00
|
|
|
ProfileInformation? profileInformation0;
|
2023-05-22 02:23:56 +00:00
|
|
|
|
2023-02-08 03:07:30 +00:00
|
|
|
List<MainAdress> addresses = [];
|
2023-02-07 01:29:38 +00:00
|
|
|
List<Identification> identificationInformation = [];
|
|
|
|
List<ContactInfo> contactInformation = [];
|
2023-02-03 03:34:09 +00:00
|
|
|
List<Citizenship> citizenships = [];
|
2023-02-01 08:03:05 +00:00
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'Authorization': "Token $token"
|
|
|
|
};
|
2023-05-22 02:23:56 +00:00
|
|
|
Map<String, String> param = {"basic": "true"};
|
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(path: path, param: param, headers: headers);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
Map data = jsonDecode(response.body);
|
|
|
|
|
|
|
|
// get all contacts
|
|
|
|
if (data['data']['basic_information']['contact_information'] != null) {
|
|
|
|
data['data']['basic_information']['contact_information']
|
|
|
|
.forEach((var contact) {
|
|
|
|
ContactInfo contactInfo =
|
|
|
|
ContactInfo.fromJson(contact['contact_info']);
|
|
|
|
contactInformation.add(contactInfo);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// get all addresses
|
|
|
|
if (data['data']['basic_information']['addresses'] != null) {
|
|
|
|
data['data']['basic_information']['addresses'].forEach((var address) {
|
|
|
|
MainAdress mainAdress = MainAdress.fromJson(address);
|
|
|
|
addresses.add(mainAdress);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// get all identifications
|
|
|
|
if (data['data']['basic_information']['identification_records'] !=
|
|
|
|
null) {
|
|
|
|
data['data']['basic_information']['identification_records']!
|
|
|
|
.forEach((var identity) {
|
|
|
|
Identification identification = Identification.fromJson(identity);
|
|
|
|
identificationInformation.add(identification);
|
|
|
|
});
|
|
|
|
}
|
2023-06-06 06:54:51 +00:00
|
|
|
if(data['data']['basic_information']['citizenships'] != null){
|
|
|
|
data['data']['basic_information']['citizenships']!
|
|
|
|
.forEach((var citizenship) {
|
|
|
|
Citizenship newCitizenShip = Citizenship.fromJson(citizenship);
|
|
|
|
citizenships.add(newCitizenShip);
|
|
|
|
});
|
|
|
|
}
|
2023-05-22 02:23:56 +00:00
|
|
|
|
|
|
|
BasicInfo basicInfo = BasicInfo(
|
|
|
|
contactInformation: contactInformation,
|
|
|
|
identifications: identificationInformation,
|
|
|
|
citizenships: citizenships,
|
|
|
|
addresses: addresses);
|
|
|
|
|
|
|
|
ProfileInformation profileInformation = ProfileInformation(
|
|
|
|
basicInfo: basicInfo,
|
|
|
|
);
|
|
|
|
profileInformation0 = profileInformation;
|
2023-02-08 03:07:30 +00:00
|
|
|
}
|
2023-05-22 02:23:56 +00:00
|
|
|
} catch (e) {
|
|
|
|
throw (e.toString());
|
|
|
|
}
|
|
|
|
return profileInformation0;
|
|
|
|
}
|
2023-02-08 03:07:30 +00:00
|
|
|
|
2023-05-22 02:23:56 +00:00
|
|
|
////Update Profile info
|
|
|
|
Future<Map<dynamic, dynamic>> updateBasicProfileInfo(
|
|
|
|
{required String token,
|
|
|
|
required int profileId,
|
|
|
|
required Profile profileInfo,
|
|
|
|
required int? genderId,
|
|
|
|
required int? indigencyId,
|
|
|
|
required int? disabilityId,
|
|
|
|
required int? ethnicityId,
|
|
|
|
required int? reqligionId}) async {
|
|
|
|
String authtoken = "Token $token";
|
|
|
|
String path = Url.instance.updatePersonalInfor();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'Authorization': authtoken
|
|
|
|
};
|
|
|
|
Map<dynamic, dynamic>? statusResponse = {};
|
|
|
|
Map body = {
|
|
|
|
"profile_id": profileId,
|
|
|
|
"first_name": profileInfo.firstName,
|
2023-06-21 00:22:43 +00:00
|
|
|
"middle_name": profileInfo.middleName!.isEmpty?null:profileInfo.middleName,
|
2023-05-22 02:23:56 +00:00
|
|
|
"last_name": profileInfo.lastName,
|
|
|
|
"name_extension": profileInfo.nameExtension,
|
|
|
|
"birthdate": profileInfo.birthdate.toString(),
|
|
|
|
"sex": profileInfo.sex,
|
|
|
|
"blood_type": profileInfo.bloodType,
|
|
|
|
"civil_status": profileInfo.civilStatus,
|
|
|
|
"height": profileInfo.heightM,
|
|
|
|
"weight": profileInfo.weightKg,
|
|
|
|
"ethnicity_id": ethnicityId,
|
|
|
|
"disability_id": disabilityId,
|
|
|
|
"gender_id": genderId,
|
|
|
|
"religion_id": reqligionId,
|
|
|
|
"ip_id": indigencyId,
|
|
|
|
"title_prefix": profileInfo.titlePrefix,
|
|
|
|
"title_suffix": profileInfo.titleSuffix
|
|
|
|
};
|
2023-06-06 06:54:51 +00:00
|
|
|
try {
|
2023-05-22 02:23:56 +00:00
|
|
|
http.Response response = await Request.instance
|
|
|
|
.postRequest(path: path, headers: headers, body: body, param: {});
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
Map data = jsonDecode(response.body);
|
|
|
|
statusResponse = data;
|
|
|
|
} else {
|
|
|
|
statusResponse.addAll({'success': false});
|
2023-02-08 03:07:30 +00:00
|
|
|
}
|
2023-05-22 02:23:56 +00:00
|
|
|
return statusResponse;
|
2023-06-06 06:54:51 +00:00
|
|
|
} catch (e) {
|
|
|
|
throw e.toString();
|
|
|
|
}
|
2023-02-01 08:03:05 +00:00
|
|
|
}
|
|
|
|
}
|