2023-02-01 08:03:05 +00:00
|
|
|
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';
|
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-07 01:29:38 +00:00
|
|
|
import 'package:unit2/model/profile/educational_background.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
import 'package:unit2/model/profile/eligibility.dart';
|
2023-02-08 08:06:27 +00:00
|
|
|
import 'package:unit2/model/profile/family_backround.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
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';
|
2023-02-01 08:03:05 +00:00
|
|
|
import 'package:unit2/model/profile/profileInfomation.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
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';
|
2023-02-01 08:03:05 +00:00
|
|
|
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';
|
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-02-08 03:07:30 +00:00
|
|
|
PrimaryInformation? primaryInformation;
|
|
|
|
List<WorkHistory> workExperiences = [];
|
2023-02-07 01:29:38 +00:00
|
|
|
List<PersonalReference> references = [];
|
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-03-02 00:40:47 +00:00
|
|
|
|
2023-02-08 08:06:27 +00:00
|
|
|
List<FamilyBackground> families = [];
|
2023-02-03 03:34:09 +00:00
|
|
|
List<Citizenship> citizenships = [];
|
2023-02-07 01:29:38 +00:00
|
|
|
List<LearningDevelopement> learningsDevelopments = [];
|
|
|
|
List<EducationalBackground> educationalBackgrounds = [];
|
2023-02-08 03:07:30 +00:00
|
|
|
List<VoluntaryWork> voluntaryWorks = [];
|
2023-02-07 06:17:49 +00:00
|
|
|
List<SkillsHobbies> skillsHobbies = [];
|
|
|
|
List<OrganizationMembership> orgMemberships = [];
|
2023-02-08 03:07:30 +00:00
|
|
|
List<NonAcademicRecognition> nonAcademicRecognitions = [];
|
2023-02-01 08:03:05 +00:00
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'Authorization': "Token $token"
|
|
|
|
};
|
2023-03-02 00:40:47 +00:00
|
|
|
Map<String,String> param={"basic":"true"};
|
2023-02-03 03:34:09 +00:00
|
|
|
// try{
|
2023-02-01 08:03:05 +00:00
|
|
|
http.Response response = await Request.instance
|
2023-03-02 00:40:47 +00:00
|
|
|
.getRequest(path: path, param: param, headers: headers);
|
2023-02-01 08:03:05 +00:00
|
|
|
if (response.statusCode == 200) {
|
2023-02-07 01:29:38 +00:00
|
|
|
Map data = jsonDecode(response.body);
|
2023-02-08 03:07:30 +00:00
|
|
|
|
2023-02-01 08:03:05 +00:00
|
|
|
// get primary information
|
2023-02-08 03:07:30 +00:00
|
|
|
if (data['data']['basic_information']['primary_information'] != null) {
|
|
|
|
primaryInformation = PrimaryInformation.fromJson(
|
|
|
|
data['data']['basic_information']['primary_information']);
|
|
|
|
} else {
|
|
|
|
primaryInformation = null;
|
|
|
|
}
|
|
|
|
|
2023-02-01 08:03:05 +00:00
|
|
|
// get all contacts
|
2023-02-08 03:07:30 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-03 03:34:09 +00:00
|
|
|
// get all identifications
|
2023-02-08 03:07:30 +00:00
|
|
|
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-02-08 08:06:27 +00:00
|
|
|
// get all family background
|
2023-03-02 00:40:47 +00:00
|
|
|
// if(data['data']['family_background'] != null){
|
|
|
|
// data['data']['family_background'].forEach((var family){
|
|
|
|
// FamilyBackground familyBackground = FamilyBackground.fromJson(family);
|
|
|
|
// families.add(familyBackground);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-08 08:06:27 +00:00
|
|
|
|
2023-02-03 03:34:09 +00:00
|
|
|
//get all eligibilities
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['eligibilities'] != null) {
|
|
|
|
// data['data']['eligibilities']!.forEach((var cert) {
|
|
|
|
// EligibityCert eligibility = EligibityCert.fromJson(cert);
|
|
|
|
// eligibilities.add(eligibility);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-08 03:07:30 +00:00
|
|
|
|
2023-02-03 03:34:09 +00:00
|
|
|
// get all citizenships
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['citizenship'] != null) {
|
|
|
|
// data['data']['citizenships']!.forEach((var citizenship) {
|
|
|
|
// Citizenship person = Citizenship.fromJson(citizenship);
|
|
|
|
// citizenships.add(person);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-03 03:34:09 +00:00
|
|
|
// get all references;
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['personal_references'] != null) {
|
|
|
|
// data['data']['personal_references'].forEach((var person) {
|
|
|
|
// PersonalReference reference = PersonalReference.fromJson(person);
|
|
|
|
// references.add(reference);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-03 03:34:09 +00:00
|
|
|
|
2023-02-07 01:29:38 +00:00
|
|
|
//get all learning and developments
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['learning_development'] != null) {
|
|
|
|
// data['data']['learning_development'].forEach((var training) {
|
|
|
|
// LearningDevelopement learnings =
|
|
|
|
// LearningDevelopement.fromJson(training);
|
|
|
|
// learningsDevelopments.add(learnings);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-03 03:34:09 +00:00
|
|
|
|
2023-02-07 01:29:38 +00:00
|
|
|
//get all educational background
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['education_background'] != null) {
|
|
|
|
// data['data']['education_background'].forEach((var education) {
|
|
|
|
// EducationalBackground educationalBackground =
|
|
|
|
// EducationalBackground.fromJson(education);
|
|
|
|
// educationalBackgrounds.add(educationalBackground);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-07 01:29:38 +00:00
|
|
|
|
|
|
|
// get all work history
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['work_experiences'] != null) {
|
|
|
|
// data['data']['work_experiences'].forEach((var work) {
|
|
|
|
// WorkHistory experience = WorkHistory.fromJson(work);
|
|
|
|
// workExperiences.add(experience);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-03 03:34:09 +00:00
|
|
|
|
2023-02-07 02:37:15 +00:00
|
|
|
// get all voluntary works
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['voluntary_works'] != null) {
|
|
|
|
// data['data']['voluntary_works'].forEach((var work) {
|
|
|
|
// VoluntaryWork vwork = VoluntaryWork.fromJson(work);
|
|
|
|
// voluntaryWorks.add(vwork);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-07 02:37:15 +00:00
|
|
|
|
2023-02-08 03:07:30 +00:00
|
|
|
// get all hobbies
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['other_information']['skills_hobbies'] != null) {
|
|
|
|
// data['data']['other_information']['skills_hobbies']
|
|
|
|
// .forEach((var skills_hobbies) {
|
|
|
|
// SkillsHobbies skillsAndHobbies =
|
|
|
|
// SkillsHobbies.fromJson(skills_hobbies);
|
|
|
|
// skillsHobbies.add(skillsAndHobbies);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-07 06:17:49 +00:00
|
|
|
|
2023-02-08 03:07:30 +00:00
|
|
|
//get all organization memberships
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['other_information']['organization_memberships'] !=
|
|
|
|
// null) {
|
|
|
|
// data['data']['other_information']['organization_memberships']
|
|
|
|
// .forEach((var org) {
|
|
|
|
// OrganizationMembership organization =
|
|
|
|
// OrganizationMembership.fromJson(org);
|
|
|
|
// orgMemberships.add(organization);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-07 06:17:49 +00:00
|
|
|
|
2023-02-08 03:07:30 +00:00
|
|
|
//get all non academic recognition
|
2023-03-02 00:40:47 +00:00
|
|
|
// if (data['data']['other_information']['non_academic_records'] != null) {
|
|
|
|
// data['data']['other_information']['non_academic_records']
|
|
|
|
// .forEach((var recognition) {
|
|
|
|
// NonAcademicRecognition nonAcademicRecognition =
|
|
|
|
// NonAcademicRecognition.fromJson(recognition);
|
|
|
|
// nonAcademicRecognitions.add(nonAcademicRecognition);
|
|
|
|
// });
|
|
|
|
// }
|
2023-02-07 02:37:15 +00:00
|
|
|
|
2023-02-07 01:29:38 +00:00
|
|
|
BasicInfo basicInfo = BasicInfo(
|
|
|
|
contactInformation: contactInformation,
|
|
|
|
primaryInformation: primaryInformation,
|
|
|
|
identifications: identificationInformation,
|
2023-02-08 03:07:30 +00:00
|
|
|
citizenships: citizenships,
|
|
|
|
addresses: addresses);
|
2023-03-02 00:40:47 +00:00
|
|
|
// OtherInformation otherInformation = OtherInformation(
|
|
|
|
// skillsAndHobbies: skillsHobbies,
|
|
|
|
// orgMemberships: orgMemberships,
|
|
|
|
// nonAcademicRecognition: nonAcademicRecognitions);
|
2023-02-07 01:29:38 +00:00
|
|
|
ProfileInformation profileInformation = ProfileInformation(
|
2023-03-02 00:40:47 +00:00
|
|
|
// families: families,
|
|
|
|
// otherInformation: otherInformation,
|
|
|
|
// workExperiences: workExperiences,
|
2023-02-07 01:29:38 +00:00
|
|
|
basicInfo: basicInfo,
|
2023-03-02 00:40:47 +00:00
|
|
|
// eligibilities: eligibilities,
|
|
|
|
// references: references,
|
|
|
|
// learningsAndDevelopment: learningsDevelopments,
|
|
|
|
// educationalBackgrounds: educationalBackgrounds,
|
|
|
|
// voluntaryWorks: voluntaryWorks
|
|
|
|
);
|
2023-02-07 01:29:38 +00:00
|
|
|
profileInformation0 = profileInformation;
|
2023-02-01 08:03:05 +00:00
|
|
|
}
|
2023-02-03 03:34:09 +00:00
|
|
|
// }catch(e){
|
|
|
|
// throw(e.toString());
|
|
|
|
// }
|
|
|
|
return profileInformation0;
|
2023-02-01 08:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-02 00:40:47 +00:00
|
|
|
|
|
|
|
|