from flask import Blueprint, render_template
from flask_login import login_required, current_user
from app.models import Job

dashboard_bp = Blueprint('dashboard', __name__, url_prefix='/dashboard')

@dashboard_bp.route('/')
@login_required
def index():
    if current_user.is_admin:
        jobs = Job.query.order_by(Job.submitted_at.desc()).all()
    else:
        jobs = Job.query.filter_by(user_id=current_user.id).order_by(Job.submitted_at.desc()).all()
    
    return render_template('dashboard/index.html', jobs=jobs)
