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-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';
|
|
|
|
import 'package:unit2/model/profile/learning_development.dart';
|
2023-02-07 06:17:49 +00:00
|
|
|
import 'package:unit2/model/profile/other_info.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-01 08:03:05 +00:00
|
|
|
PrimaryInformation primaryInformation;
|
2023-02-07 01:29:38 +00:00
|
|
|
List<WorkHistory> workExperiences =[];
|
|
|
|
List<PersonalReference> references = [];
|
|
|
|
List<Identification> identificationInformation = [];
|
|
|
|
List<ContactInfo> contactInformation = [];
|
2023-02-03 03:34:09 +00:00
|
|
|
List<EligibityCert> eligibilities = [];
|
|
|
|
List<Citizenship> citizenships = [];
|
2023-02-07 01:29:38 +00:00
|
|
|
List<LearningDevelopement> learningsDevelopments = [];
|
|
|
|
List<EducationalBackground> educationalBackgrounds = [];
|
2023-02-07 02:37:15 +00:00
|
|
|
List<VoluntaryWork> voluntaryWorks =[];
|
2023-02-07 06:17:49 +00:00
|
|
|
List<SkillsHobbies> skillsHobbies = [];
|
|
|
|
List<OrganizationMembership> orgMemberships = [];
|
2023-02-01 08:03:05 +00:00
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
'Authorization': "Token $token"
|
|
|
|
};
|
2023-02-03 03:34:09 +00:00
|
|
|
// try{
|
2023-02-01 08:03:05 +00:00
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(path: path, param: {}, headers: headers);
|
|
|
|
if (response.statusCode == 200) {
|
2023-02-07 01:29:38 +00:00
|
|
|
Map data = jsonDecode(response.body);
|
2023-02-01 08:03:05 +00:00
|
|
|
// get primary information
|
|
|
|
primaryInformation = PrimaryInformation.fromJson(
|
|
|
|
data['data']['basic_information']['primary_information']);
|
|
|
|
// get all contacts
|
|
|
|
data['data']['basic_information']['contact_information']
|
|
|
|
.forEach((var contact) {
|
2023-02-07 01:29:38 +00:00
|
|
|
ContactInfo contactInfo = ContactInfo.fromJson(contact['contact_info']);
|
2023-02-01 08:03:05 +00:00
|
|
|
contactInformation.add(contactInfo);
|
|
|
|
});
|
2023-02-03 03:34:09 +00:00
|
|
|
// get all identifications
|
2023-02-07 01:29:38 +00:00
|
|
|
data['data']['basic_information']['identification_records']
|
|
|
|
.forEach((var identity) {
|
|
|
|
Identification identification = Identification.fromJson(identity);
|
2023-02-03 03:34:09 +00:00
|
|
|
identificationInformation.add(identification);
|
|
|
|
});
|
|
|
|
//get all eligibilities
|
2023-02-07 01:29:38 +00:00
|
|
|
data['data']['eligibilities'].forEach((var cert) {
|
2023-02-03 03:34:09 +00:00
|
|
|
EligibityCert eligibility = EligibityCert.fromJson(cert);
|
|
|
|
eligibilities.add(eligibility);
|
|
|
|
});
|
|
|
|
// get all citizenships
|
2023-02-07 01:29:38 +00:00
|
|
|
if (data['data']['citizenship'] != null) {
|
|
|
|
data['data']['citizenships'].forEach((var citizenship) {
|
2023-02-03 03:34:09 +00:00
|
|
|
Citizenship person = Citizenship.fromJson(citizenship);
|
|
|
|
citizenships.add(person);
|
2023-02-07 01:29:38 +00:00
|
|
|
});
|
2023-02-03 03:34:09 +00:00
|
|
|
}
|
|
|
|
// get all references;
|
2023-02-07 01:29:38 +00:00
|
|
|
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-02-03 03:34:09 +00:00
|
|
|
|
2023-02-07 01:29:38 +00:00
|
|
|
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
|
|
|
|
data['data']['education_background'].forEach((var education) {
|
|
|
|
EducationalBackground educationalBackground =
|
|
|
|
EducationalBackground.fromJson(education);
|
|
|
|
educationalBackgrounds.add(educationalBackground);
|
|
|
|
});
|
|
|
|
|
|
|
|
// get all work history
|
|
|
|
|
|
|
|
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
|
|
|
|
data['data']['voluntary_works'].forEach((var work){
|
|
|
|
VoluntaryWork vwork = VoluntaryWork.fromJson(work);
|
|
|
|
voluntaryWorks.add(vwork);
|
|
|
|
});
|
|
|
|
|
2023-02-07 06:17:49 +00:00
|
|
|
// get all hobbies
|
|
|
|
data['data']['other_information']['skills_hobbies'].forEach((var skills_hobbies){
|
|
|
|
SkillsHobbies skillsAndHobbies = SkillsHobbies.fromJson(skills_hobbies);
|
|
|
|
skillsHobbies.add(skillsAndHobbies);
|
|
|
|
});
|
|
|
|
|
|
|
|
data['data']['other_information']['organization_memberships'].forEach((var org) {
|
|
|
|
OrganizationMembership organization =
|
|
|
|
OrganizationMembership.fromJson(org);
|
|
|
|
orgMemberships.add(organization);
|
|
|
|
});
|
|
|
|
|
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,
|
|
|
|
citizenships: citizenships);
|
2023-02-07 06:17:49 +00:00
|
|
|
OtherInformation otherInformation = OtherInformation(skillsAndHobbies: skillsHobbies,orgMemberships: orgMemberships);
|
2023-02-07 01:29:38 +00:00
|
|
|
ProfileInformation profileInformation = ProfileInformation(
|
2023-02-07 06:17:49 +00:00
|
|
|
otherInformation: otherInformation,
|
2023-02-07 01:29:38 +00:00
|
|
|
workExperiences: workExperiences,
|
|
|
|
basicInfo: basicInfo,
|
|
|
|
eligibilities: eligibilities,
|
|
|
|
references: references,
|
|
|
|
learningsAndDevelopment: learningsDevelopments,
|
2023-02-07 02:37:15 +00:00
|
|
|
educationalBackgrounds: educationalBackgrounds,
|
|
|
|
voluntaryWorks: voluntaryWorks
|
2023-02-07 06:17:49 +00:00
|
|
|
|
2023-02-07 02:37:15 +00:00
|
|
|
);
|
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
|
|
|
}
|
|
|
|
}
|