Spaces:
Paused
Paused
Update backend/mongodb/operations/calls.py
Browse files
backend/mongodb/operations/calls.py
CHANGED
@@ -20,13 +20,13 @@ def list_calls(collection, limit: int):
|
|
20 |
|
21 |
|
22 |
'''Finding calls based on call id'''
|
23 |
-
def
|
24 |
user_calls = collection.find_one({"call_id": call_id})
|
25 |
if user_calls is not None:
|
26 |
return user_calls
|
27 |
else:
|
28 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Call with ID: '{call_id}' not found.")
|
29 |
-
|
30 |
|
31 |
'''Finding calls based on user id'''
|
32 |
def find_user_calls(collection, user_id: str):
|
@@ -94,10 +94,10 @@ def update_calls(collection, call_id: str, calls: UpdateCall = Body(...)):
|
|
94 |
|
95 |
def update_captions(collection, call_id: str, calls: UserCaptions = Body(...)):
|
96 |
# calls = {k: v for k, v in calls.model_dump().items() if v is not None}
|
97 |
-
|
98 |
if len(calls) >= 1:
|
99 |
update_result = collection.update_one({"call_id": call_id},
|
100 |
-
{"$push": {"captions":
|
101 |
|
102 |
if update_result.modified_count == 0:
|
103 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Captions not updated!")
|
@@ -115,3 +115,17 @@ def delete_calls(collection, call_id: str):
|
|
115 |
return f"Call deleted sucessfully!"
|
116 |
|
117 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Call not found!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
'''Finding calls based on call id'''
|
23 |
+
def find_call(collection, call_id: str):
|
24 |
user_calls = collection.find_one({"call_id": call_id})
|
25 |
if user_calls is not None:
|
26 |
return user_calls
|
27 |
else:
|
28 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Call with ID: '{call_id}' not found.")
|
29 |
+
|
30 |
|
31 |
'''Finding calls based on user id'''
|
32 |
def find_user_calls(collection, user_id: str):
|
|
|
94 |
|
95 |
def update_captions(collection, call_id: str, calls: UserCaptions = Body(...)):
|
96 |
# calls = {k: v for k, v in calls.model_dump().items() if v is not None}
|
97 |
+
captions = {k: v for k, v in calls.items() if v is not None}
|
98 |
if len(calls) >= 1:
|
99 |
update_result = collection.update_one({"call_id": call_id},
|
100 |
+
{"$push": {"captions": captions}})
|
101 |
|
102 |
if update_result.modified_count == 0:
|
103 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Captions not updated!")
|
|
|
115 |
return f"Call deleted sucessfully!"
|
116 |
|
117 |
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Call not found!")
|
118 |
+
|
119 |
+
|
120 |
+
def get_caption_text(collection, call_id):
|
121 |
+
call_record = find_call((collection), call_id)
|
122 |
+
|
123 |
+
try: # Check if call has any captions first
|
124 |
+
caption_records = call_record['captions']
|
125 |
+
except KeyError:
|
126 |
+
return None
|
127 |
+
|
128 |
+
# iterate through caption embedded document and store original text
|
129 |
+
combined_text = [caption['original_text'] for caption in caption_records]
|
130 |
+
|
131 |
+
return " ".join(combined_text)
|