fromflaskimportBlueprint,render_template,jsonify,request,flashfromflask_loginimportlogin_requiredfromkusibot.servicesimport(DashboardService)fromkusibot.app.auth.utilsimportprofessional_user_requiredprofessional_bp=Blueprint('professional_bp',__name__,template_folder='templates',static_folder='static')dashboard_service=DashboardService()DB_USER_ERROR_FETCH="There was an error while fetching the users. Try again later."
[docs]@professional_bp.route('/')@login_required@professional_user_requireddefdashboard():"""Render the dashboard page (protected) with the list of users using KusiBot. Returns: str: The HTML dashboard page to render. """try:users=dashboard_service.get_chat_users()returnrender_template('dashboard.html',users=users)exceptException:flash(DB_USER_ERROR_FETCH,"error")returnrender_template('dashboard.html',users=[])
[docs]@professional_bp.route('/conversations')@login_required@professional_user_requireddefdashboard_conversations():"""Get the conversations history for a selected user (URL parameter). Returns: Response: The JSON conversations for the given user. """user_id=request.args.get('user_id',type=int)ifuser_idisNone:returnjsonify({'error':'user_id is required'}),400response=dashboard_service.get_conversations_for_user(user_id)returnjsonify(response)
[docs]@professional_bp.route('/conversation_messages')@login_required@professional_user_requireddefdashboard_conversation_messages():"""Get the conversation messages for a specific conversation ID (URL parameter). Returns: Response: The JSON details of the specified conversation. """conversation_id=request.args.get('conversation_id',type=int)ifconversation_idisNone:returnjsonify({'error':'conversation_id is required'}),400response=dashboard_service.get_conversation_messages(conversation_id)returnjsonify(response)
[docs]@professional_bp.route('/assessments')@login_required@professional_user_requireddefdashboard_assessments():"""Get the assessments for a selected user (URL parameter). Returns: Response: The JSON assessments for the given user. """user_id=request.args.get('user_id',type=int)ifuser_idisNone:returnjsonify({'error':'user_id is required'}),400response=dashboard_service.get_assessments_for_user(user_id)returnjsonify(response)