Update main.py
Browse files
main.py
CHANGED
|
@@ -994,34 +994,39 @@ def view_notes():
|
|
| 994 |
@app.route('/api/view/quizzes', methods=['GET'])
|
| 995 |
def view_quizzes():
|
| 996 |
try:
|
| 997 |
-
#
|
| 998 |
user, error = verify_token(request.headers.get('Authorization'))
|
| 999 |
if error: return jsonify({'error': error['error']}), error['status']
|
| 1000 |
|
| 1001 |
-
#
|
| 1002 |
-
|
| 1003 |
-
.select('id, difficulty, created_at, notes(content, study_materials(title))') \
|
| 1004 |
.eq('user_id', user.id) \
|
| 1005 |
-
.order('created_at', desc=True)
|
| 1006 |
-
.execute()
|
| 1007 |
|
| 1008 |
-
|
| 1009 |
-
raise Exception(quizzes_res.error.message)
|
| 1010 |
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
|
|
|
|
|
|
|
|
|
| 1015 |
"quiz_id": quiz['id'],
|
| 1016 |
"difficulty": quiz['difficulty'],
|
| 1017 |
"created_at": quiz['created_at'],
|
| 1018 |
-
"notes_preview": quiz['notes']['content'][:100] + "..." if quiz['notes'] else None,
|
| 1019 |
-
"material_title": quiz['notes']['study_materials']['title'] if quiz['notes'] and quiz['notes']['study_materials'] else
|
|
|
|
| 1020 |
})
|
| 1021 |
|
| 1022 |
-
return jsonify({"quizzes":
|
| 1023 |
|
| 1024 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
| 1025 |
return jsonify({'error': str(e)}), 500
|
| 1026 |
|
| 1027 |
@app.route('/api/user/performance', methods=['GET'])
|
|
|
|
| 994 |
@app.route('/api/view/quizzes', methods=['GET'])
|
| 995 |
def view_quizzes():
|
| 996 |
try:
|
| 997 |
+
# Authentication
|
| 998 |
user, error = verify_token(request.headers.get('Authorization'))
|
| 999 |
if error: return jsonify({'error': error['error']}), error['status']
|
| 1000 |
|
| 1001 |
+
# Query with proper error handling
|
| 1002 |
+
query = supabase.table('quizzes') \
|
| 1003 |
+
.select('id, difficulty, created_at, notes(content, study_materials(title, type))') \
|
| 1004 |
.eq('user_id', user.id) \
|
| 1005 |
+
.order('created_at', desc=True)
|
|
|
|
| 1006 |
|
| 1007 |
+
result = query.execute()
|
|
|
|
| 1008 |
|
| 1009 |
+
if hasattr(result, 'error') and result.error:
|
| 1010 |
+
raise Exception(result.error.message)
|
| 1011 |
+
|
| 1012 |
+
# Format response to match frontend expectations
|
| 1013 |
+
quizzes = []
|
| 1014 |
+
for quiz in result.data:
|
| 1015 |
+
quizzes.append({
|
| 1016 |
"quiz_id": quiz['id'],
|
| 1017 |
"difficulty": quiz['difficulty'],
|
| 1018 |
"created_at": quiz['created_at'],
|
| 1019 |
+
"notes_preview": quiz['notes']['content'][:100] + "..." if quiz['notes'] and quiz['notes']['content'] else None,
|
| 1020 |
+
"material_title": quiz['notes']['study_materials']['title'] if quiz['notes'] and quiz['notes']['study_materials'] else "Untitled Quiz",
|
| 1021 |
+
"material_type": quiz['notes']['study_materials']['type'] if quiz['notes'] and quiz['notes']['study_materials'] else None
|
| 1022 |
})
|
| 1023 |
|
| 1024 |
+
return jsonify({"quizzes": quizzes})
|
| 1025 |
|
| 1026 |
except Exception as e:
|
| 1027 |
+
print(f"Error in /api/view/quizzes: {str(e)}") # Debug logging
|
| 1028 |
+
logging.error(f"Quizzes endpoint error: {str(e)}")
|
| 1029 |
+
logging.error(traceback.format_exc())
|
| 1030 |
return jsonify({'error': str(e)}), 500
|
| 1031 |
|
| 1032 |
@app.route('/api/user/performance', methods=['GET'])
|