diff --git a/backend/blueprints/chat/__init__.py b/backend/blueprints/chat/__init__.py index f796bd7..41f9177 100644 --- a/backend/blueprints/chat/__init__.py +++ b/backend/blueprints/chat/__init__.py @@ -14,7 +14,7 @@ chat = Blueprint('chat', __name__) @auth_required() def create_chat(): current_user: User = g.current_user # Fetch the logged-in user - data = request.args + data = request.form if not data.get("course_id"): return jsonify({"error": "Unknown Course"}), 400 if not data.get("message", "").strip(): @@ -26,7 +26,7 @@ def create_chat(): Enrollment.courseID == data.get("course_id"), Enrollment.userID == current_user.id) ) - ) + ).scalar() if not enrollment_record: return jsonify({"error": "You are not enrolled in this course."}), 403 if enrollment_record.currentPage < enrollment_record.course.pageForCommunity: @@ -43,6 +43,8 @@ def create_chat(): new_chat = Chat( textContent=data.get("message").strip(), userID=current_user.id, + user=g.current_user, + course=enrollment_record.course, courseID=data.get("course_id"), ) db.session.add(new_chat) @@ -57,11 +59,11 @@ def create_chat(): @auth_required() def get_messages(): try: - course_id: uuid.UUID = uuid.UUID(request.args.get('course_id')) + course_id: uuid.UUID = uuid.UUID(request.form.get('course_id')) current_user: User = g.current_user - limit = int(request.args.get('limit', 10)) - before_id = request.args.get('before') - after_id = request.args.get('after') + limit = int(request.form.get('limit', 10)) + before_id = request.form.get('before') + after_id = request.form.get('after') # Verify user's enrollment enrollment = db.session.execute( select(Enrollment).where( @@ -108,4 +110,5 @@ def get_messages(): 'count': len(chat_messages), }), 200 except Exception as e: - return jsonify({'message': f'An error occurred: {str(e)}'}), 500 \ No newline at end of file + raise e + # return jsonify({'message': f'An error occurred: {str(e)}'}), 500 \ No newline at end of file