PC端
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
公司黑名单路由:拉黑后 RPA 不再投递该公司的任何职位
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..auth import get_current_user
|
||||
from ..database import get_db
|
||||
from ..models import User, CompanyBlacklist
|
||||
from ..schemas import BlacklistIn, BlacklistOut, Message
|
||||
|
||||
router = APIRouter(prefix="/api/blacklist", tags=["公司黑名单"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[BlacklistOut])
|
||||
def list_blacklist(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""查询当前用户的黑名单列表(按拉黑时间倒序)"""
|
||||
return db.query(CompanyBlacklist).filter(
|
||||
CompanyBlacklist.user_id == current_user.id,
|
||||
).order_by(CompanyBlacklist.created_at.desc()).all()
|
||||
|
||||
|
||||
@router.post("", response_model=BlacklistOut)
|
||||
def add_blacklist(
|
||||
req: BlacklistIn,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""拉黑一家公司(重复拉黑幂等返回已有记录)"""
|
||||
company = req.company.strip()
|
||||
if not company:
|
||||
raise HTTPException(status_code=422, detail="公司名不能为空")
|
||||
|
||||
existing = db.query(CompanyBlacklist).filter(
|
||||
CompanyBlacklist.user_id == current_user.id,
|
||||
CompanyBlacklist.company == company,
|
||||
).first()
|
||||
if existing:
|
||||
return existing
|
||||
|
||||
item = CompanyBlacklist(user_id=current_user.id, company=company)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return item
|
||||
|
||||
|
||||
@router.delete("/{item_id}", response_model=Message)
|
||||
def remove_blacklist(
|
||||
item_id: int,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""移除一条黑名单记录"""
|
||||
item = db.query(CompanyBlacklist).filter(
|
||||
CompanyBlacklist.id == item_id,
|
||||
CompanyBlacklist.user_id == current_user.id,
|
||||
).first()
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="黑名单记录不存在")
|
||||
db.delete(item)
|
||||
db.commit()
|
||||
return Message(msg="已移除")
|
||||
Reference in New Issue
Block a user