rairo commited on
Commit
b99f6a9
·
verified ·
1 Parent(s): 41468c7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -13
main.py CHANGED
@@ -872,35 +872,37 @@ def speak_notes(notes_id):
872
  @app.route('/api/view/notes', methods=['GET'])
873
  def view_notes():
874
  try:
875
- # --- Authentication ---
876
  user, error = verify_token(request.headers.get('Authorization'))
877
  if error: return jsonify({'error': error['error']}), error['status']
878
 
879
- # --- Query Notes for the Authenticated User ---
880
- notes_res = supabase.table('notes') \
881
  .select('id, content, created_at, tts_audio_url, study_materials(title, type)') \
882
  .eq('user_id', user.id) \
883
- .order('created_at', desc=True) \
884
- .execute()
885
 
886
- if notes_res.error:
887
- raise Exception(notes_res.error.message)
888
 
889
- # Format response
890
- formatted_notes = []
891
- for note in notes_res.data:
892
- formatted_notes.append({
 
 
 
893
  "note_id": note['id'],
894
  "content": note['content'],
895
  "audio_url": note['tts_audio_url'],
896
  "created_at": note['created_at'],
897
- "material_title": note['study_materials']['title'] if note['study_materials'] else None,
898
  "material_type": note['study_materials']['type'] if note['study_materials'] else None
899
  })
900
 
901
- return jsonify({"notes": formatted_notes})
902
 
903
  except Exception as e:
 
904
  logging.error(f"Notes endpoint error: {str(e)}")
905
  logging.error(traceback.format_exc())
906
  return jsonify({'error': str(e)}), 500
 
872
  @app.route('/api/view/notes', methods=['GET'])
873
  def view_notes():
874
  try:
875
+ # Authentication
876
  user, error = verify_token(request.headers.get('Authorization'))
877
  if error: return jsonify({'error': error['error']}), error['status']
878
 
879
+ # Query with proper error handling
880
+ query = supabase.table('notes') \
881
  .select('id, content, created_at, tts_audio_url, study_materials(title, type)') \
882
  .eq('user_id', user.id) \
883
+ .order('created_at', desc=True)
 
884
 
885
+ result = query.execute()
 
886
 
887
+ if hasattr(result, 'error') and result.error:
888
+ raise Exception(result.error.message)
889
+
890
+ # Format response to match frontend expectations
891
+ notes = []
892
+ for note in result.data:
893
+ notes.append({
894
  "note_id": note['id'],
895
  "content": note['content'],
896
  "audio_url": note['tts_audio_url'],
897
  "created_at": note['created_at'],
898
+ "material_title": note['study_materials']['title'] if note['study_materials'] else "Untitled Note",
899
  "material_type": note['study_materials']['type'] if note['study_materials'] else None
900
  })
901
 
902
+ return jsonify({"notes": notes}) # Changed from "notes" to match frontend
903
 
904
  except Exception as e:
905
+ print(f"Error in /api/view/notes: {str(e)}") # Debug logging
906
  logging.error(f"Notes endpoint error: {str(e)}")
907
  logging.error(traceback.format_exc())
908
  return jsonify({'error': str(e)}), 500