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'; 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'; import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/profileInfomation.dart'; import 'package:unit2/model/profile/references.dart'; 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'; class ProfileService { static final ProfileService _instance = ProfileService(); static ProfileService get instance => _instance; Future getProfile(String token, int id) async { String url = Url.instance.profileInformation(); String path = url + id.toString(); ProfileInformation? profileInformation0; PrimaryInformation primaryInformation; List workExperiences =[]; List references = []; List identificationInformation = []; List contactInformation = []; List eligibilities = []; List citizenships = []; List learningsDevelopments = []; List educationalBackgrounds = []; Map 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) { Map data = jsonDecode(response.body); // get primary information primaryInformation = PrimaryInformation.fromJson( data['data']['basic_information']['primary_information']); // get all contacts data['data']['basic_information']['contact_information'] .forEach((var contact) { ContactInfo contactInfo = ContactInfo.fromJson(contact['contact_info']); contactInformation.add(contactInfo); }); // get all identifications data['data']['basic_information']['identification_records'] .forEach((var identity) { Identification identification = Identification.fromJson(identity); identificationInformation.add(identification); }); //get all eligibilities data['data']['eligibilities'].forEach((var cert) { EligibityCert eligibility = EligibityCert.fromJson(cert); eligibilities.add(eligibility); }); // get all citizenships if (data['data']['citizenship'] != null) { data['data']['citizenships'].forEach((var citizenship) { Citizenship person = Citizenship.fromJson(citizenship); citizenships.add(person); }); } // get all references; data['data']['personal_references'].forEach((var person) { PersonalReference reference = PersonalReference.fromJson(person); references.add(reference); }); //get all learning and developments data['data']['learning_development'].forEach((var training) { LearningDevelopement learnings = LearningDevelopement.fromJson(training); learningsDevelopments.add(learnings); }); //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); }); BasicInfo basicInfo = BasicInfo( contactInformation: contactInformation, primaryInformation: primaryInformation, identifications: identificationInformation, citizenships: citizenships); ProfileInformation profileInformation = ProfileInformation( workExperiences: workExperiences, basicInfo: basicInfo, eligibilities: eligibilities, references: references, learningsAndDevelopment: learningsDevelopments, educationalBackgrounds: educationalBackgrounds); profileInformation0 = profileInformation; } // }catch(e){ // throw(e.toString()); // } return profileInformation0; } }