def _get_contact(self, s, tenant_uuid, phonebook_id, contact_uuid): filter_ = self._new_contact_filter(tenant_uuid, phonebook_id, contact_uuid) contact = s.query(Contact).join(Phonebook).filter(filter_).first() if not contact: raise NoSuchContact(contact_uuid) return contact
def _delete_personal_contact(self, session, user_uuid, contact_uuid): filter_ = and_(User.user_uuid == user_uuid, ContactFields.contact_uuid == contact_uuid) nb_deleted = self._delete_personal_contacts_with_filter( session, filter_) if nb_deleted == 0: raise NoSuchContact(contact_uuid)
def get(self, tenant_uuid, phonebook_id, contact_id): with self.new_session() as s: phonebook = self._get_phonebook(s, tenant_uuid, phonebook_id) filter_ = self._new_contact_filter(tenant_uuid, phonebook.id, contact_id) fields = s.query(ContactFields).join(Contact).filter(filter_).all() if not fields: raise NoSuchContact(contact_id) return {field.name: field.value for field in fields}
def get_personal_contact(self, user_uuid, contact_uuid): with self.new_session() as s: filter_ = and_(User.user_uuid == user_uuid, ContactFields.contact_uuid == contact_uuid) contact_uuids = (s.query(distinct( ContactFields.contact_uuid)).join(Contact).join(User).filter( filter_)) for contact in list_contacts_by_uuid(s, contact_uuids): return contact raise NoSuchContact(contact_uuid)