diff --git a/app-backend/app.py b/app-backend/app.py index 78ce83f..1fcb4e5 100644 --- a/app-backend/app.py +++ b/app-backend/app.py @@ -189,7 +189,11 @@ class Therapist(db.Model): is_available = db.Column(db.Boolean, default=True) patients_treated = db.Column(db.Integer, default=0) patients_queue = db.Column(db.Integer, default=0) - + about = db.Column(db.Text, nullable=True) + description = db.Column(db.Text, nullable=True) + specialization = db.Column(db.Text, nullable=True) + rating = db.Column(db.Integer, nullable=True) + experience = db.Column(db.Text,nullable=True) feedbacks = db.relationship('Feedback', backref='therapists', lazy=True) @@ -360,7 +364,6 @@ class Meta: @app.route('/signup', methods=['POST']) def signup(): data = request.get_json() - print("data",data) fname = data.get('fname') lname = data.get('lname') email = data.get('email') @@ -504,7 +507,7 @@ def generate_response(): if chatt: chatt.title = title db.session.commit() - print(f"Chat updated with title: {chatt.title}") + if not data or 'user_input' not in data: return jsonify({"error": "Please say something"}), 400 user_input = data.get('user_input', 'I am not feeling well') @@ -613,8 +616,7 @@ def delete_chat(): @app.route("/contact_us", methods=["POST"]) def contact_us(): - # print(f"Form Data: {request.form}") - # if request.method == "POST": + try: data = request.get_json() name = data.get('name') @@ -650,8 +652,6 @@ def contact_us(): db.session.add(new_query) db.session.commit() - # print(new_query) - print(name) return jsonify({"status": "success"}), 200 except Exception as e: print(f'Error: {e}, Trace: {traceback.format_exc()}') @@ -893,6 +893,24 @@ def list_reviews(): return jsonify(review_list), 200 +@app.route('/list_queries', methods=['GET']) +def list_queries(): + queries = db.session.query(ContactUs).all() + + query_list = [ + { + "id": q.id, + "name": q.name, + "email": q.email, + "query": q.query, + "contacted_on": q.contacted_on + } + for q in queries + ] + print(query_list) + + return jsonify(query_list), 200 + @app.route('/create_therapist', methods=['POST']) @@ -921,24 +939,21 @@ def create_therapist(): @app.route('/list_therapists', methods=['GET']) def list_therapists(): - therapists = db.session.query(Therapist).all() - - therapist_list = [ - { - "id": therapist.id, - "name": therapist.name, - "designation": therapist.designation, - "qualification": therapist.qualification, - "location": therapist.location, - "is_available": therapist.is_available, - "patients_treated": therapist.patients_treated, - "patients_queue": therapist.patients_queue - } - for therapist in therapists + result = [ + {c.name: getattr(t, c.name) for c in t.__table__.columns} + for t in therapists ] + return jsonify(result), 200 + +@app.route('/get_therapist/', methods=['GET']) +def get_therapist(id): + therapist = db.session.query(Therapist).get(id) + if therapist is None: + return jsonify({'error': 'Therapist not found'}), 404 - return jsonify(therapist_list), 200 + result = {c.name: getattr(therapist, c.name) for c in therapist.__table__.columns} + return jsonify(result), 200 @app.route('/edit_therapist/', methods=['PUT']) @@ -1253,11 +1268,8 @@ def add_journal(): try: prompt = f"Analyze the following journal and determine the mood. Just give a single word answer.Mood must be among these [\"happy\", \"sad\", \"angry\", \"calm\", \"stressed\", \"excited\", \"bored\", \"anxious\", \"content\"].Just give a single word answer.\nJournal: {text}" - print(1,prompt) response = model.generate_content(prompt) - print(2,response) detected_mood = response.candidates[0].content.parts[0].text.strip() if response.candidates else "Neutral" - print(3,detected_mood) except Exception as e: detected_mood = "Unknown" @@ -2358,7 +2370,6 @@ def alot_coupons(): def update_profile(): try: data = request.get_json() - print("data",data) client_id = data.get('client_id') if not client_id: return jsonify({"error": "Client ID is required"}), 400 @@ -2366,7 +2377,6 @@ def update_profile(): user = db.session.get(User, client_id) if not user: return jsonify({"error": "User not found"}), 404 - print(2) if 'fname' in data: user.first_name = data['fname'] if 'lname' in data: @@ -2375,10 +2385,8 @@ def update_profile(): user.phone = data['phone'] if 'religion' in data: user.religion = data['religion'] - print(3) user.updated_at = datetime.now(timezone.utc) db.session.commit() - print(user) return jsonify({"message": "Profile updated successfully"}), 200 except Exception as e: diff --git a/app-backend/instance/eunoia.db b/app-backend/instance/eunoia.db index cbe8d5d..082512c 100755 Binary files a/app-backend/instance/eunoia.db and b/app-backend/instance/eunoia.db differ diff --git a/app-backend/migrations/versions/01480a35f8d5_add_4_columns_to_therapist_table.py b/app-backend/migrations/versions/01480a35f8d5_add_4_columns_to_therapist_table.py new file mode 100644 index 0000000..ea26c43 --- /dev/null +++ b/app-backend/migrations/versions/01480a35f8d5_add_4_columns_to_therapist_table.py @@ -0,0 +1,38 @@ +"""add 4 columns to therapist table + +Revision ID: 01480a35f8d5 +Revises: e23fd24ef6fe +Create Date: 2025-05-22 19:15:20.005443 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '01480a35f8d5' +down_revision = 'e23fd24ef6fe' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('therapists', schema=None) as batch_op: + batch_op.add_column(sa.Column('specialization', sa.Text(), nullable=True)) + batch_op.add_column(sa.Column('about', sa.Text(), nullable=True)) + batch_op.add_column(sa.Column('rating', sa.Text(), nullable=True)) + batch_op.add_column(sa.Column('description', sa.Text(), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('therapists', schema=None) as batch_op: + batch_op.drop_column('description') + batch_op.drop_column('rating') + batch_op.drop_column('about') + batch_op.drop_column('specialization') + + # ### end Alembic commands ### diff --git a/app-backend/migrations/versions/5827c077fcb2_add_experience_column_to_therapist_table.py b/app-backend/migrations/versions/5827c077fcb2_add_experience_column_to_therapist_table.py new file mode 100644 index 0000000..7f6cf32 --- /dev/null +++ b/app-backend/migrations/versions/5827c077fcb2_add_experience_column_to_therapist_table.py @@ -0,0 +1,40 @@ +"""add experience column to therapist table + +Revision ID: 5827c077fcb2 +Revises: 01480a35f8d5 +Create Date: 2025-05-22 20:29:16.719588 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '5827c077fcb2' +down_revision = '01480a35f8d5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('therapists', schema=None) as batch_op: + batch_op.add_column(sa.Column('experience', sa.Text(), nullable=True)) + batch_op.alter_column('rating', + existing_type=sa.TEXT(), + type_=sa.Integer(), + existing_nullable=True) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('therapists', schema=None) as batch_op: + batch_op.alter_column('rating', + existing_type=sa.Integer(), + type_=sa.TEXT(), + existing_nullable=True) + batch_op.drop_column('experience') + + # ### end Alembic commands ### diff --git a/app-backend/update_therapists.py b/app-backend/update_therapists.py index d85c730..a723e80 100644 --- a/app-backend/update_therapists.py +++ b/app-backend/update_therapists.py @@ -33,10 +33,11 @@ class Therapist(db.Model): is_available = db.Column(db.Boolean, default=True) patients_treated = db.Column(db.Integer, default=0) patients_queue = db.Column(db.Integer, default=0) - # about = db.Column(db.Text, nullable=True) - # description = db.Column(db.Text, nullable=True) - # specialization = db.Column(db.Text, nullable=True) - # rating = db.Column(db.Integer, nullable=True) + about = db.Column(db.Text, nullable=True) + description = db.Column(db.Text, nullable=True) + specialization = db.Column(db.Text, nullable=True) + rating = db.Column(db.Integer, nullable=True) + experience = db.Column(db.Text, nullable=True) def generate_therapist_info(therapist): prompt = f""" @@ -48,10 +49,11 @@ def generate_therapist_info(therapist): Return a JSON object in this exact format without any markdown formatting or additional text: {{ "location": "", - "rating": , + "rating": , "description": "<2-3 sentences about their practice>", "about": "<3-4 sentences about their background>", - "specialization": "<2-3 mental health specialties>" + "specialization": "<2-3 mental health specialties>", + "experience":"" }} """ @@ -80,11 +82,12 @@ def generate_therapist_info(therapist): 'rating': random.randint(3, 5), 'description': 'Experienced therapist providing compassionate care and evidence-based treatment.', 'about': 'Dedicated mental health professional with years of experience in helping clients achieve emotional well-being.', - 'specialization': ', '.join(random.sample(specialties, 2)) + 'specialization': ', '.join(random.sample(specialties, 2)), + 'experience':'1-2' } def update_therapists(): - with app.app_context(): + with app.app_context(): therapists = Therapist.query.all() print(f"Found {len(therapists)} therapists") @@ -97,13 +100,34 @@ def update_therapists(): info = generate_therapist_info(therapist) if info: try: - therapist.location = info.get('location') - therapist.rating = info.get('rating') - therapist.description = info.get('description') - therapist.about = info.get('about') - therapist.specialization = info.get('specialization') + # Always use random choice for rating to ensure variability + therapist.rating = random.choice([3, 4, 5]) + # Process other fields + therapist.location = info.get('location', random.choice(['Lahore', 'Karachi', 'Islamabad'])) + therapist.description = info.get('description', 'Experienced therapist providing compassionate care.') + therapist.about = info.get('about', 'Dedicated mental health professional.') + + # Handle specialization which might come as list or string + specs = info.get('specialization') + if isinstance(specs, list): + specs = ', '.join(specs) + elif not specs: + specs = random.choice([ + 'Anxiety & Depression, Stress Management', + 'Cognitive Behavioral Therapy, Trauma Recovery', + 'Family Counseling, Mental Wellness' + ]) + therapist.specialization = specs + + # Handle experience + exp = info.get('experience') + if not exp: + x = random.randint(1, 4) + exp = f"{x}-{x+1}" + therapist.experience = exp + db.session.commit() - print(f"Successfully updated {therapist.name} with: {info}") + print(f"Successfully updated {therapist.name} with rating: {therapist.rating}") except Exception as e: print(f"Error updating database for {therapist.name}: {str(e)}") db.session.rollback() diff --git a/app-frontend/src/App.jsx b/app-frontend/src/App.jsx index 6936837..fa96b62 100644 --- a/app-frontend/src/App.jsx +++ b/app-frontend/src/App.jsx @@ -37,7 +37,9 @@ import EmailSent from "./pages/auth/EmailSent"; import PasswordUpdated from "./pages/auth/PasswordUpdated"; import ArticleDetails from "./pages/user/Articles/ArticleDetails"; import { ToastContainer } from "react-toastify"; - +import RoleBasedRoute from "./components/molecules/RoleBasedRoute"; +import { adminRoutes, userRoutes } from "./routesConfig"; +import Unauthorized from "./pages/auth/Unauthorized"; function App() { const location = useLocation(); const showNavbar = @@ -61,33 +63,32 @@ function App() { /> {showNavbar && } - } /> - } /> + {/* } /> } /> } /> } /> } /> } /> } /> - } /> - } /> - } /> - } /> - } /> + } /> */} + {/* } /> */} + {/* } /> } /> + } /> + } /> */} {/* Admin Dashboard*/} - } /> + {/* } /> } /> } /> } /> } /> } /> } /> - } /> + } /> */} {/* */} {/* User Dashboard */} - } /> + {/* } /> } /> } /> } /> @@ -95,6 +96,7 @@ function App() { } /> } /> } /> + } /> */} {/* */} {/* Legal Agreements */} @@ -102,8 +104,53 @@ function App() { } /> {/* Page Not Found */} + {/* } /> */} + + {/* new way */} + {/* */} + {/* Public Routes */} + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + {/* Admin Routes */} + {adminRoutes.map(({ path, element }) => ( + + {element} + + } + /> + ))} + + {/* User Routes */} + {userRoutes.map(({ path, element }) => ( + {element} + } + /> + ))} + + {/* 404 */} } /> + {/* */} {showNavbar &&