fix: 调整seek路由顺序,将/{seek_id}移到匹配API之后
问题:FastAPI路由匹配顺序问题,/{seek_id}在/my-match之前导致404
解决:把my-match/network-match等具体路由移到/{seek_id}之前
This commit is contained in:
parent
875e40a79d
commit
c17525c1e1
|
|
@ -172,72 +172,6 @@ def create_seek(
|
|||
db.refresh(seek)
|
||||
return seek
|
||||
|
||||
@router.get("/{seek_id}", response_model=SeekInfoResponse)
|
||||
def get_seek(
|
||||
seek_id: str,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取寻配号详情"""
|
||||
seek = db.query(SeekInfo).filter(SeekInfo.id == seek_id).first()
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
|
||||
# 增加浏览数
|
||||
seek.view_count += 1
|
||||
db.commit()
|
||||
|
||||
return seek
|
||||
|
||||
@router.put("/{seek_id}", response_model=SeekInfoResponse)
|
||||
def update_seek(
|
||||
seek_id: str,
|
||||
data: SeekInfoUpdate,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新寻配号"""
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="请先登录")
|
||||
|
||||
seek = db.query(SeekInfo).filter(
|
||||
SeekInfo.id == seek_id,
|
||||
SeekInfo.user_id == current_user.f99_90_id
|
||||
).first()
|
||||
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
|
||||
for key, value in data.model_dump(exclude_unset=True).items():
|
||||
setattr(seek, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(seek)
|
||||
return seek
|
||||
|
||||
@router.delete("/{seek_id}")
|
||||
def delete_seek(
|
||||
seek_id: str,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除寻配号"""
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="请先登录")
|
||||
|
||||
seek = db.query(SeekInfo).filter(
|
||||
SeekInfo.id == seek_id,
|
||||
SeekInfo.user_id == current_user.f99_90_id
|
||||
).first()
|
||||
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
|
||||
seek.status = "deleted"
|
||||
db.commit()
|
||||
|
||||
return {"message": "删除成功"}
|
||||
|
||||
# ============ 匹配相关API ============
|
||||
|
||||
@router.get("/my-match")
|
||||
|
|
@ -406,3 +340,68 @@ def get_publisher_info(
|
|||
"phone": publisher.phone,
|
||||
"contact": contact,
|
||||
}
|
||||
|
||||
|
||||
# ============ 通配路由(必须放最后,避免匹配冲突)============
|
||||
@router.get("/{seek_id}", response_model=SeekInfoResponse)
|
||||
def get_seek(
|
||||
seek_id: str,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取寻配号详情"""
|
||||
seek = db.query(SeekInfo).filter(SeekInfo.id == seek_id).first()
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
seek.view_count += 1
|
||||
db.commit()
|
||||
return seek
|
||||
|
||||
@router.put("/{seek_id}", response_model=SeekInfoResponse)
|
||||
def update_seek(
|
||||
seek_id: str,
|
||||
data: SeekInfoUpdate,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新寻配号"""
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="请先登录")
|
||||
seek = db.query(SeekInfo).filter(SeekInfo.id == seek_id).first()
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
if seek.user_id != current_user.f99_90_id:
|
||||
raise HTTPException(status_code=403, detail="无权限")
|
||||
if data.title is not None:
|
||||
seek.title = data.title
|
||||
if data.content is not None:
|
||||
seek.content = data.content
|
||||
if data.expect_category is not None:
|
||||
seek.expect_category = data.expect_category
|
||||
if data.expect_version is not None:
|
||||
seek.expect_version = data.expect_version
|
||||
if data.expect_packaging is not None:
|
||||
seek.expect_packaging = data.expect_packaging
|
||||
if data.status is not None:
|
||||
seek.status = data.status
|
||||
db.commit()
|
||||
db.refresh(seek)
|
||||
return seek
|
||||
|
||||
@router.delete("/{seek_id}")
|
||||
def delete_seek(
|
||||
seek_id: str,
|
||||
current_user = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除寻配号"""
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="请先登录")
|
||||
seek = db.query(SeekInfo).filter(SeekInfo.id == seek_id).first()
|
||||
if not seek:
|
||||
raise HTTPException(status_code=404, detail="寻配号不存在")
|
||||
if seek.user_id != current_user.f99_90_id:
|
||||
raise HTTPException(status_code=403, detail="无权限")
|
||||
seek.status = "deleted"
|
||||
db.commit()
|
||||
return {"message": "删除成功"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue