.
This commit is contained in:
		@@ -46,48 +46,30 @@ class ApplicationResponse(BaseModel):
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@router.get("/", response_model=List[ApplicationResponse])
 | 
			
		||||
async def get_applications(skip: int = 0, limit: int = 100, db: Session = Depends(SessionLocal), request: Request = None):
 | 
			
		||||
    """Get all applications for the current tenant"""
 | 
			
		||||
    tenant_id = getattr(request.state, 'tenant_id', None)
 | 
			
		||||
    if not tenant_id and settings.MULTI_TENANT_ENABLED:
 | 
			
		||||
        raise HTTPException(status_code=400, detail="Tenant ID is required")
 | 
			
		||||
    
 | 
			
		||||
    # Get applications for jobs in the current tenant or applications by users in the current tenant
 | 
			
		||||
    applications = db.query(Application).join(JobPosting).filter(
 | 
			
		||||
        (JobPosting.tenant_id == tenant_id) | (Application.user_id.in_(
 | 
			
		||||
            db.query(User.id).filter(User.tenant_id == tenant_id)
 | 
			
		||||
        ))
 | 
			
		||||
    ).offset(skip).limit(limit).all()
 | 
			
		||||
async def get_applications(skip: int = 0, limit: int = 100, db: Session = Depends(SessionLocal)):
 | 
			
		||||
    """Get all applications"""
 | 
			
		||||
    applications = db.query(Application).offset(skip).limit(limit).all()
 | 
			
		||||
    return applications
 | 
			
		||||
 | 
			
		||||
@router.get("/{application_id}", response_model=ApplicationResponse)
 | 
			
		||||
async def get_application(application_id: int, db: Session = Depends(SessionLocal), request: Request = None):
 | 
			
		||||
async def get_application(application_id: int, db: Session = Depends(SessionLocal)):
 | 
			
		||||
    """Get a specific application"""
 | 
			
		||||
    tenant_id = getattr(request.state, 'tenant_id', None)
 | 
			
		||||
    if not tenant_id and settings.MULTI_TENANT_ENABLED:
 | 
			
		||||
        raise HTTPException(status_code=400, detail="Tenant ID is required")
 | 
			
		||||
    
 | 
			
		||||
    application = db.query(Application).join(JobPosting).filter(
 | 
			
		||||
    application = db.query(Application).filter(
 | 
			
		||||
        Application.id == application_id,
 | 
			
		||||
        (JobPosting.tenant_id == tenant_id) | (Application.user_id.in_(
 | 
			
		||||
            db.query(User.id).filter(User.tenant_id == tenant_id)
 | 
			
		||||
        ))
 | 
			
		||||
    ).first()
 | 
			
		||||
    if not application:
 | 
			
		||||
        raise HTTPException(status_code=404, detail="Application not found")
 | 
			
		||||
    return application
 | 
			
		||||
 | 
			
		||||
@router.post("/", response_model=ApplicationResponse)
 | 
			
		||||
async def create_application(application: ApplicationCreate, db: Session = Depends(SessionLocal), request: Request = None, user_id: int = 1):  # In real app, get from auth context
 | 
			
		||||
async def create_application(application: ApplicationCreate, db: Session = Depends(SessionLocal), user_id: int = 1):  # Default for testing
 | 
			
		||||
    """Create a new job application"""
 | 
			
		||||
    tenant_id = getattr(request.state, 'tenant_id', None)
 | 
			
		||||
    if not tenant_id and settings.MULTI_TENANT_ENABLED:
 | 
			
		||||
        raise HTTPException(status_code=400, detail="Tenant ID is required")
 | 
			
		||||
    # For testing, use default tenant
 | 
			
		||||
    tenant_id = 1  # Default tenant for testing
 | 
			
		||||
    
 | 
			
		||||
    # Verify user exists and has permission to apply
 | 
			
		||||
    user = db.query(User).filter(
 | 
			
		||||
        User.id == user_id,
 | 
			
		||||
        User.tenant_id == tenant_id  # Make sure user belongs to current tenant
 | 
			
		||||
        User.id == user_id
 | 
			
		||||
    ).first()
 | 
			
		||||
    if not user or user.role != "job_seeker":
 | 
			
		||||
        raise HTTPException(
 | 
			
		||||
@@ -95,14 +77,13 @@ async def create_application(application: ApplicationCreate, db: Session = Depen
 | 
			
		||||
            detail="Only job seekers can apply for jobs"
 | 
			
		||||
        )
 | 
			
		||||
    
 | 
			
		||||
    # Verify job posting exists and is active and belongs to the same tenant
 | 
			
		||||
    # Verify job posting exists and is active
 | 
			
		||||
    job_posting = db.query(JobPosting).filter(
 | 
			
		||||
        JobPosting.id == application.job_posting_id,
 | 
			
		||||
        JobPosting.is_active == True,
 | 
			
		||||
        JobPosting.tenant_id == tenant_id  # Ensure job belongs to current tenant
 | 
			
		||||
        JobPosting.is_active == True
 | 
			
		||||
    ).first()
 | 
			
		||||
    if not job_posting:
 | 
			
		||||
        raise HTTPException(status_code=404, detail="Job posting not found or inactive or not in your tenant")
 | 
			
		||||
        raise HTTPException(status_code=404, detail="Job posting not found or inactive")
 | 
			
		||||
    
 | 
			
		||||
    # Verify resume exists and belongs to user
 | 
			
		||||
    resume = db.query(Resume).filter(
 | 
			
		||||
@@ -124,17 +105,10 @@ async def create_application(application: ApplicationCreate, db: Session = Depen
 | 
			
		||||
    return db_application
 | 
			
		||||
 | 
			
		||||
@router.put("/{application_id}", response_model=ApplicationResponse)
 | 
			
		||||
async def update_application(application_id: int, app_update: ApplicationUpdate, db: Session = Depends(SessionLocal), request: Request = None):
 | 
			
		||||
async def update_application(application_id: int, app_update: ApplicationUpdate, db: Session = Depends(SessionLocal)):
 | 
			
		||||
    """Update an application"""
 | 
			
		||||
    tenant_id = getattr(request.state, 'tenant_id', None)
 | 
			
		||||
    if not tenant_id and settings.MULTI_TENANT_ENABLED:
 | 
			
		||||
        raise HTTPException(status_code=400, detail="Tenant ID is required")
 | 
			
		||||
    
 | 
			
		||||
    db_application = db.query(Application).join(JobPosting).filter(
 | 
			
		||||
        Application.id == application_id,
 | 
			
		||||
        (JobPosting.tenant_id == tenant_id) | (Application.user_id.in_(
 | 
			
		||||
            db.query(User.id).filter(User.tenant_id == tenant_id)
 | 
			
		||||
        ))
 | 
			
		||||
    db_application = db.query(Application).filter(
 | 
			
		||||
        Application.id == application_id
 | 
			
		||||
    ).first()
 | 
			
		||||
    if not db_application:
 | 
			
		||||
        raise HTTPException(status_code=404, detail="Application not found")
 | 
			
		||||
@@ -150,17 +124,10 @@ async def update_application(application_id: int, app_update: ApplicationUpdate,
 | 
			
		||||
    return db_application
 | 
			
		||||
 | 
			
		||||
@router.delete("/{application_id}")
 | 
			
		||||
async def delete_application(application_id: int, db: Session = Depends(SessionLocal), request: Request = None):
 | 
			
		||||
async def delete_application(application_id: int, db: Session = Depends(SessionLocal)):
 | 
			
		||||
    """Delete an application"""
 | 
			
		||||
    tenant_id = getattr(request.state, 'tenant_id', None)
 | 
			
		||||
    if not tenant_id and settings.MULTI_TENANT_ENABLED:
 | 
			
		||||
        raise HTTPException(status_code=400, detail="Tenant ID is required")
 | 
			
		||||
    
 | 
			
		||||
    db_application = db.query(Application).join(JobPosting).filter(
 | 
			
		||||
        Application.id == application_id,
 | 
			
		||||
        (JobPosting.tenant_id == tenant_id) | (Application.user_id.in_(
 | 
			
		||||
            db.query(User.id).filter(User.tenant_id == tenant_id)
 | 
			
		||||
        ))
 | 
			
		||||
    db_application = db.query(Application).filter(
 | 
			
		||||
        Application.id == application_id
 | 
			
		||||
    ).first()
 | 
			
		||||
    if not db_application:
 | 
			
		||||
        raise HTTPException(status_code=404, detail="Application not found")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user