feature(#134): add method for mapping a contact model to json data for http response
Browse filesFiles changed (2)
68 unmodified lines69707168 unmodified linesdef to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:return ReqModel(basic_req.to_json())68 unmodified lines69707172737475767778798081828384858668 unmodified linesdef to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:return ReqModel(basic_req.to_json())"""mapping data from a ContactModel into json{"contactId": int,"displayName": string,"phoneNumbers": [string]}"""def to_contact_result_format(self, contact: ContactModel) -> Any:return {"contactId": contact.contact_id,"displayName": contact.display_name,"phoneNumbers": contact.phone_numbers}
2 unmodified lines34567899 unmodified lines1081091101111121131141151161171181191201211221231241251261271281294 unmodified lines1341351361371381392 unmodified linesimport googlefrom Brain.src.model.req_model import ReqModelfrom Brain.src.rising_plugin.csv_embed import get_embedfrom Brain.src.rising_plugin.pinecone_engine import (99 unmodified lines"""create a contact into document which name is uuid in phone collections in firestore"""def create_one_contact(self, uuid: str, contact: ContactModel):data = {"contactId": contact.contact_id,"displayName": contact.display_name,"phoneNumbers": contact.phone_numbers}phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.set(data)"""update a contact into document which name is uuid in phone collections in firestore"""def update_one_contact(self, uuid: str, contact: ContactModel):data = {"contactId": contact.contact_id,"displayName": contact.display_name,"phoneNumbers": contact.phone_numbers}phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.update(data)4 unmodified linescontacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.delete()def getContactsByUUID(self, uuid: str) -> []:phones_doc_ref = self.phones_ref.document(uuid)contacts_ref = phones_doc_ref.collection("contacts")2 unmodified lines345678999 unmodified lines1091101111121131141151161171181191201211221231244 unmodified lines1291301311321331341351362 unmodified linesimport googlefrom Brain.src.common.assembler import Assemblerfrom Brain.src.model.req_model import ReqModelfrom Brain.src.rising_plugin.csv_embed import get_embedfrom Brain.src.rising_plugin.pinecone_engine import (99 unmodified lines"""create a contact into document which name is uuid in phone collections in firestore"""def create_one_contact(self, uuid: str, contact: ContactModel):assembler = Assembler()data = assembler.to_contact_result_format(contact)phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.set(data)"""update a contact into document which name is uuid in phone collections in firestore"""def update_one_contact(self, uuid: str, contact: ContactModel):assembler = Assembler()data = assembler.to_contact_result_format(contact)phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.update(data)4 unmodified linescontacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.delete()def getContactsByUUID(self, uuid: str) -> []:phones_doc_ref = self.phones_ref.document(uuid)contacts_ref = phones_doc_ref.collection("contacts")
Brain/src/common/assembler.py+15
Brain/src/service/contact_service.py+7-10