passo_mobile_app/lib/sevices/profile/profile_service.dart

146 lines
5.6 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
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';
import 'package:unit2/model/profile/basic_information/citizenship.dart';
import 'package:unit2/model/profile/basic_information/contact_information.dart';
import 'package:unit2/model/profile/basic_information/identification_information.dart';
2023-02-07 01:29:38 +00:00
import 'package:unit2/model/profile/educational_background.dart';
import 'package:unit2/model/profile/eligibility.dart';
2023-02-08 08:06:27 +00:00
import 'package:unit2/model/profile/family_backround.dart';
import 'package:unit2/model/profile/learning_development.dart';
2023-02-08 03:07:30 +00:00
import 'package:unit2/model/profile/other_information/non_acedimic_recognition.dart';
import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/model/profile/references.dart';
2023-02-07 06:17:49 +00:00
import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart';
2023-02-07 02:37:15 +00:00
import 'package:unit2/model/profile/voluntary_works.dart';
2023-02-07 01:29:38 +00:00
import 'package:unit2/model/profile/work_history.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import '../../model/profile/basic_information/primary-information.dart';
2023-02-07 06:17:49 +00:00
import '../../model/profile/other_information/organization_memberships.dart';
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 = [];
List<Citizenship> citizenships = [];
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);
});
}
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,
"middle_name": profileInfo.middleName,
"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
};
// try {
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;
// } catch (e) {
// throw e.toString();
// }
}
}