Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let c = contacts.load::<Contacts>(cx).expect("loading contacts went wrong");
- let ce = ContactsEmails::belonging_to(&c).load::<ContactsEmails>(cx).expect("loading emails went wrong");
- let cp = ContactsPhonenumbers::belonging_to(&c).load::<ContactsPhonenumbers>(cx).expect("loading numbers went wrong ");
- let t = tags.load::<Tags>(cx).expect("loading all tags went wrong");
- let ct = ContactsTags::belonging_to(&c).load::<ContactsTags>(cx).expect("loading contacts tags went wrong");
- let mut tags_map: HashMap<i32, Tags> = HashMap::new();
- for contactTag in ct.iter() {
- for tt in t.iter() {
- match contactTag.ctag_tag_id {
- Some(_tag_id) if _tag_id == tt.id => { tags_map.insert(contactTag.id, tt.clone()); }
- _ => {}
- }
- }
- }
- let grouped_ct: Vec<Vec<ContactsTags>> = ct.grouped_by(&c);
- let grouped_ce: Vec<Vec<ContactsEmails>> = ce.grouped_by(&c);
- let grouped_cp: Vec<Vec<ContactsPhonenumbers>> = cp.grouped_by(&c);
- let c_and_ce: Vec<(Contacts, Vec<ContactsEmails>)> = c.into_iter().zip(grouped_ce).collect();
- let c_and_ce_and_cp: Vec<((Contacts, Vec<ContactsEmails>), Vec<ContactsPhonenumbers>)> = c_and_ce.into_iter().zip(grouped_cp).collect();
- let c_and_ce_and_cp_and_ct: Vec<(((Contacts, Vec<ContactsEmails>), Vec<ContactsPhonenumbers>), Vec<ContactsTags>)> = c_and_ce_and_cp.into_iter().zip(grouped_ct).collect();
- let mut c_out = vec![];
- for (((contact, email_list), phone_list), contacts_tags) in c_and_ce_and_cp_and_ct {
- let mut c_tags = vec![];
- for ct in contacts_tags {
- if let Some(tt) = tags_map.remove(&ct.id) {
- c_tags.push(tt);
- }
- }
- c_out.push(ApiContact{
- id: contact.id,
- firstname: contact.firstname,
- lastname: contact.lastname,
- emails: Some(email_list),
- phone: Some(phone_list),
- tags: Some(c_tags),
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement