Revert "Made it so the save_to_db also returns the ID of the document"

This reverts commit 4a0ae88fed.
This commit is contained in:
Tiago Ribeiro
2023-11-29 15:23:30 +00:00
parent 4a0ae88fed
commit 760fe27411
2 changed files with 11 additions and 15 deletions

20
app.py
View File

@@ -169,9 +169,8 @@ def save_listening():
file_url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
template["parts"][i]["audio"]["source"] = file_url
template["parts"][i]["exercises"] = part["exercises"]
(result, id) = save_to_db("listening", template)
if result:
return {**template, "id": id}
if save_to_db("listening", template):
return template
else:
raise Exception("Failed to save question: " + parts)
except Exception as e:
@@ -280,9 +279,8 @@ def save_writing_task():
template = getWritingTemplate()
for i, exercise in enumerate(exercises, start=0):
template["exercises"][i]["prompt"] = exercise
(result, id) = save_to_db("writing", template)
if result:
return {**template, "id": id}
if save_to_db("writing", template):
return template
else:
raise Exception("Failed to save writing: " + template)
except Exception as e:
@@ -508,9 +506,8 @@ def save_speaking():
template["exercises"][2]["prompts"] = sp3_questions
template["exercises"][2]["title"] = exercises[2]["topic"]
(result, id) = save_to_db("speaking", template)
if result:
return {**template, "id": id}
if save_to_db("speaking", template):
return template
else:
raise Exception("Failed to save speaking: " + template)
except Exception as e:
@@ -608,9 +605,8 @@ def save_reading_passage():
parts = data.get('parts')
template = getReadingTemplate()
template["parts"] = parts
(result, id) = save_to_db("reading", template)
if result:
return {**template, "id": id}
if save_to_db("reading", template):
return template
else:
raise Exception("Failed to save reading: " + template)
except Exception as e:

View File

@@ -51,10 +51,10 @@ def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file
def save_to_db(collection: str, item):
db = firestore.client()
collection_ref = db.collection(collection)
document_ref = collection_ref.add(item)
(update_time, document_ref) = collection_ref.add(item)
if document_ref:
print(f"Document added with ID: {document_ref}")
return (True, document_ref)
print(f"Document added with ID: {document_ref.id}")
return (True, document_ref.id)
else:
return (False, None)