rairo commited on
Commit
e73ed91
·
verified ·
1 Parent(s): be900bf

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +41 -0
main.py CHANGED
@@ -654,6 +654,47 @@ def process_input_and_generate_notes():
654
  logging.error(f"Unexpected error processing input for user {user.id}: {traceback.format_exc()}")
655
  return jsonify({'error': f'An unexpected error occurred: {e}'}), 500
656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
  @app.route('/api/tutor/notes/<uuid:notes_id>/generate_quiz', methods=['POST'])
658
  def generate_quiz_for_notes(notes_id):
659
  user, error = verify_token(request.headers.get('Authorization'))
 
654
  logging.error(f"Unexpected error processing input for user {user.id}: {traceback.format_exc()}")
655
  return jsonify({'error': f'An unexpected error occurred: {e}'}), 500
656
 
657
+ @app.route('/api/view/notes/<uuid:note_id>', methods=['GET'])
658
+ def get_note_by_id(note_id):
659
+ try:
660
+ # --- Authentication ---
661
+ user, error = verify_token(request.headers.get('Authorization'))
662
+ if error:
663
+ return jsonify({'error': error['error']}), error['status']
664
+
665
+ # --- Query Database ---
666
+ note_res = supabase.table('notes') \
667
+ .select('id, content, created_at, tts_audio_url, study_materials(title, type, source_ref)') \
668
+ .eq('id', note_id) \
669
+ .eq('user_id', user.id) \ # Ensure user owns the note
670
+ .maybe_single() \
671
+ .execute()
672
+
673
+ if not note_res.data:
674
+ return jsonify({'error': 'Note not found or unauthorized'}), 404
675
+
676
+ # --- Format Response ---
677
+ note_data = note_res.data
678
+ response_data = {
679
+ "note": {
680
+ "note_id": note_data['id'],
681
+ "content": note_data['content'],
682
+ "audio_url": note_data['tts_audio_url'],
683
+ "created_at": note_data['created_at'],
684
+ "material": {
685
+ "title": note_data['study_materials']['title'] if note_data['study_materials'] else "Untitled",
686
+ "type": note_data['study_materials']['type'] if note_data['study_materials'] else None,
687
+ "source_ref": note_data['study_materials']['source_ref'] if note_data['study_materials'] else None
688
+ }
689
+ }
690
+ }
691
+
692
+ return jsonify(response_data)
693
+
694
+ except Exception as e:
695
+ logging.error(f"Error fetching note {note_id}: {str(e)}")
696
+ return jsonify({'error': 'Internal server error'}), 500
697
+
698
  @app.route('/api/tutor/notes/<uuid:notes_id>/generate_quiz', methods=['POST'])
699
  def generate_quiz_for_notes(notes_id):
700
  user, error = verify_token(request.headers.get('Authorization'))