完成项目信息管理的迁移
This commit is contained in:
@ -4,12 +4,13 @@
|
||||
# @Create Time : 2025/04/03 10:25
|
||||
# @File : views.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : 路由,视图文件
|
||||
# @desc : 路由,项目信息管理,包括项目主体,项目图片,项目标签和图片的标注信息
|
||||
from utils.response import SuccessResponse, ErrorResponse
|
||||
from . import params, schemas, crud, models
|
||||
from core.dependencies import IdList
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from typing import List
|
||||
from fastapi import APIRouter, Depends, UploadFile, File, Form
|
||||
from apps.vadmin.auth.utils.current import FullAdminAuth
|
||||
from apps.vadmin.auth.utils.validation.auth import Auth
|
||||
|
||||
@ -42,7 +43,7 @@ async def add_project(
|
||||
|
||||
|
||||
@app.get("/info/{pro_id}", summary="查询项目信息")
|
||||
async def project(
|
||||
async def project_info(
|
||||
pro_id: int,
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
@ -98,10 +99,64 @@ async def delete_label(
|
||||
label_ids: IdList = Depends(),
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
# 删除标签信息,然后删除图片标签关联表
|
||||
await crud.ProjectLabelDal(auth.db).delete_datas(label_ids.ids)
|
||||
for label_id in label_ids.ids:
|
||||
await crud.ProjectImgLabelDal(auth.db).delete_datas(label_id=label_id)
|
||||
return SuccessResponse(msg="删除成功")
|
||||
|
||||
|
||||
@app.get("/img", summary="获取图片列表,分两种情况,一个带分页的,一个不带分页的")
|
||||
async def project_pager(
|
||||
param: params.ProjectImageParams = Depends(),
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
if param.limit:
|
||||
# 分页查询,关联一个标签数量
|
||||
datas, count = await crud.ProjectImageDal(auth.db).img_page(param)
|
||||
return SuccessResponse(data=datas, count=count)
|
||||
else:
|
||||
# 直接查询
|
||||
datas = await crud.ProjectImageDal(auth.db).get_datas(v_schema=schemas.ProjectImage, **param.dict())
|
||||
return SuccessResponse(data=datas)
|
||||
|
||||
|
||||
@app.post("/img", summary="上传图片")
|
||||
async def up_img(
|
||||
project_id: int = Form(...),
|
||||
files: List[UploadFile] = File(...),
|
||||
img_type: str = Form(...),
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
pro = await crud.ProjectInfoDal(auth.db).get_data(data_id=project_id)
|
||||
if pro is None:
|
||||
return ErrorResponse(msg="项目查询失败,请稍后再试")
|
||||
count = await crud.ProjectImageDal(auth.db).upload_imgs(files=files, pro=pro, img_type=img_type)
|
||||
if count > 0:
|
||||
return SuccessResponse(msg="上传成功")
|
||||
|
||||
|
||||
@app.delete("/img", summary="删除照片")
|
||||
async def del_img(
|
||||
img_id: IdList = Depends(),
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
await crud.ProjectImageDal(auth.db).del_img(img_id.ids)
|
||||
return SuccessResponse(msg="删除成功")
|
||||
|
||||
|
||||
@app.post("/img_label", summary="保存图片的标注信息")
|
||||
async def add_img_label(
|
||||
img_label_in: schemas.ProjectImgLeaferLabel,
|
||||
auth: Auth = Depends(FullAdminAuth())
|
||||
):
|
||||
await crud.ProjectImgLabelDal(auth.db).add_img_label(img_label_in)
|
||||
await crud.ProjectImgLeaferDal(auth.db).add_leafer(img_label_in)
|
||||
return SuccessResponse(msg="保存成功")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user