passo_mobile_app/lib/sevices/profile/profile_service.dart

218 lines
8.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-07 06:17:49 +00:00
import 'package:unit2/model/profile/other_info.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-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 = [];
List<EligibityCert> eligibilities = [];
2023-02-08 08:06:27 +00:00
List<FamilyBackground> families = [];
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 = [];
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': "Token $token"
};
// try{
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-08 03:07:30 +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;
}
// 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);
});
}
// 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
if(data['data']['family_background'] != null){
data['data']['family_background'].forEach((var family){
FamilyBackground familyBackground = FamilyBackground.fromJson(family);
families.add(familyBackground);
});
}
//get all eligibilities
2023-02-08 03:07:30 +00:00
if (data['data']['eligibilities'] != null) {
data['data']['eligibilities']!.forEach((var cert) {
EligibityCert eligibility = EligibityCert.fromJson(cert);
eligibilities.add(eligibility);
});
}
// get all citizenships
2023-02-07 01:29:38 +00:00
if (data['data']['citizenship'] != null) {
2023-02-08 03:07:30 +00:00
data['data']['citizenships']!.forEach((var citizenship) {
Citizenship person = Citizenship.fromJson(citizenship);
citizenships.add(person);
2023-02-07 01:29:38 +00:00
});
}
// get all references;
2023-02-08 03:07:30 +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-07 01:29:38 +00:00
//get all learning and developments
2023-02-08 03:07:30 +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-07 01:29:38 +00:00
//get all educational background
2023-02-08 03:07:30 +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-02-08 03:07:30 +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-07 02:37:15 +00:00
// get all voluntary works
2023-02-08 03:07:30 +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
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
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
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);
OtherInformation otherInformation = OtherInformation(
skillsAndHobbies: skillsHobbies,
orgMemberships: orgMemberships,
nonAcademicRecognition: nonAcademicRecognitions);
2023-02-07 01:29:38 +00:00
ProfileInformation profileInformation = ProfileInformation(
2023-02-08 08:06:27 +00:00
families: families,
2023-02-08 03:07:30 +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,
2023-02-08 03:07:30 +00:00
voluntaryWorks: voluntaryWorks);
2023-02-07 01:29:38 +00:00
profileInformation0 = profileInformation;
}
// }catch(e){
// throw(e.toString());
// }
return profileInformation0;
}
}