Skip to content

Commit

Permalink
added null check and handling for document_groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwell-Lindsey committed Feb 26, 2024
1 parent f9f6dd8 commit 49f354d
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions ai_ta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,51 +733,57 @@ def addDocumentToGroup():

@app.route('/appendDocumentToGroup', methods=['POST'])
def appendDocumentToGroup():
data = request.get_json()
print("In /appendDocumentToGroup", data)
course_name = data['course_name']
doc_group = data['doc_group']

try:
document = MaterialDocument(**data.get('document', {}))
except ValidationError as e:
abort(400, description=f"Invalid document data: {e}")

if course_name == '' or doc_group == '':
abort(
400,
description=
f"Missing one or more required parameters: 'course_name' and 'doc_group' must be provided. Course name: `{course_name}`, doc_group: `{doc_group}`, document: `{document}`"
)
ingester = Ingest()
res = ingester.append_doc_group(course_name=course_name, doc=document, doc_group=doc_group)
response = jsonify({'outcome': res})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
data = request.get_json()
print("In /appendDocumentToGroup", data)
course_name = data['course_name']
doc_group = data['doc_group']

document_data = data.get('document', {})
document_data['doc_groups'] = document_data.get('doc_groups', [])

try:
document = MaterialDocument(**document_data)
except ValidationError as e:
abort(400, description=f"Invalid document data: {e}")

if course_name == '' or doc_group == '':
abort(
400,
description=
f"Missing one or more required parameters: 'course_name' and 'doc_group' must be provided. Course name: `{course_name}`, doc_group: `{doc_group}`, document: `{document}`"
)
ingester = Ingest()
res = ingester.append_doc_group(course_name=course_name, doc=document, doc_group=doc_group)
response = jsonify({'outcome': res})
response.headers.add('Access-Control-Allow-Origin', '*')
return response

@app.route('/removeDocumentFromGroup', methods=['POST'])
def removeDocumentFromGroup():
data = request.get_json()
print("In /removeDocumentFromGroup", data)
course_name = data['course_name']
doc_group = data['doc_group']

try:
document = MaterialDocument(**data.get('document', {}))
except ValidationError as e:
abort(400, description=f"Invalid document data: {e}")

if course_name == '' or doc_group == '':
abort(
400,
description=
f"Missing one or more required parameters: 'course_name' and 'doc_group' must be provided. Course name: `{course_name}`, doc_group: `{doc_group}`, document: `{document}`"
)
ingester = Ingest()
res = ingester.remove_doc_group(course_name=course_name, doc=document, doc_group=doc_group)
response = jsonify({'outcome': res})
response.headers.add('Access-Control-Allow-Origin', '*')
return response
data = request.get_json()
print("In /removeDocumentFromGroup", data)
course_name = data['course_name']
doc_group = data['doc_group']

document_data = data.get('document', {})
document_data['doc_groups'] = document_data.get('doc_groups', [])

try:
document = MaterialDocument(**document_data)
except ValidationError as e:
abort(400, description=f"Invalid document data: {e}")

if course_name == '' or doc_group == '':
abort(
400,
description=
f"Missing one or more required parameters: 'course_name' and 'doc_group' must be provided. Course name: `{course_name}`, doc_group: `{doc_group}`, document: `{document}`"
)
ingester = Ingest()
res = ingester.remove_doc_group(course_name=course_name, doc=document, doc_group=doc_group)
response = jsonify({'outcome': res})
response.headers.add('Access-Control-Allow-Origin', '*')
return response


if __name__ == '__main__':
Expand Down

0 comments on commit 49f354d

Please sign in to comment.