kanno927 commited on
Commit
d05535d
·
1 Parent(s): 1dabf5e

feature(#134): add method for mapping a contact model to json data for http response

Browse files
Brain/src/common/assembler.py CHANGED
@@ -69,3 +69,18 @@ class Assembler:
69
 
70
  def to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:
71
  return ReqModel(basic_req.to_json())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  def to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:
71
  return ReqModel(basic_req.to_json())
72
+
73
+ """mapping data from a ContactModel into json
74
+ {
75
+ "contactId": int,
76
+ "displayName": string,
77
+ "phoneNumbers": [string]
78
+ }
79
+ """
80
+
81
+ def to_contact_result_format(self, contact: ContactModel) -> Any:
82
+ return {
83
+ "contactId": contact.contact_id,
84
+ "displayName": contact.display_name,
85
+ "phoneNumbers": contact.phone_numbers
86
+ }
Brain/src/service/contact_service.py CHANGED
@@ -3,6 +3,7 @@ from typing import List, Any
3
 
4
  import google
5
 
 
6
  from Brain.src.model.req_model import ReqModel
7
  from Brain.src.rising_plugin.csv_embed import get_embed
8
  from Brain.src.rising_plugin.pinecone_engine import (
@@ -108,22 +109,16 @@ class ContactsService:
108
 
109
  """create a contact into document which name is uuid in phone collections in firestore"""
110
  def create_one_contact(self, uuid: str, contact: ContactModel):
111
- data = {
112
- "contactId": contact.contact_id,
113
- "displayName": contact.display_name,
114
- "phoneNumbers": contact.phone_numbers
115
- }
116
  phones_doc_ref = self.phones_ref.document(uuid)
117
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
118
  contacts_doc_ref.set(data)
119
 
120
  """update a contact into document which name is uuid in phone collections in firestore"""
121
  def update_one_contact(self, uuid: str, contact: ContactModel):
122
- data = {
123
- "contactId": contact.contact_id,
124
- "displayName": contact.display_name,
125
- "phoneNumbers": contact.phone_numbers
126
- }
127
  phones_doc_ref = self.phones_ref.document(uuid)
128
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
129
  contacts_doc_ref.update(data)
@@ -134,6 +129,8 @@ class ContactsService:
134
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
135
  contacts_doc_ref.delete()
136
 
 
 
137
  def getContactsByUUID(self, uuid: str) -> []:
138
  phones_doc_ref = self.phones_ref.document(uuid)
139
  contacts_ref = phones_doc_ref.collection("contacts")
 
3
 
4
  import google
5
 
6
+ from Brain.src.common.assembler import Assembler
7
  from Brain.src.model.req_model import ReqModel
8
  from Brain.src.rising_plugin.csv_embed import get_embed
9
  from Brain.src.rising_plugin.pinecone_engine import (
 
109
 
110
  """create a contact into document which name is uuid in phone collections in firestore"""
111
  def create_one_contact(self, uuid: str, contact: ContactModel):
112
+ assembler = Assembler()
113
+ data = assembler.to_contact_result_format(contact)
 
 
 
114
  phones_doc_ref = self.phones_ref.document(uuid)
115
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
116
  contacts_doc_ref.set(data)
117
 
118
  """update a contact into document which name is uuid in phone collections in firestore"""
119
  def update_one_contact(self, uuid: str, contact: ContactModel):
120
+ assembler = Assembler()
121
+ data = assembler.to_contact_result_format(contact)
 
 
 
122
  phones_doc_ref = self.phones_ref.document(uuid)
123
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
124
  contacts_doc_ref.update(data)
 
129
  contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)
130
  contacts_doc_ref.delete()
131
 
132
+
133
+
134
  def getContactsByUUID(self, uuid: str) -> []:
135
  phones_doc_ref = self.phones_ref.document(uuid)
136
  contacts_ref = phones_doc_ref.collection("contacts")