完成项目管理模块的接口测试

This commit is contained in:
2025-04-18 17:22:57 +08:00
parent 434e1af3e8
commit 7a9e571a96
16 changed files with 91 additions and 74 deletions

View File

@ -8,7 +8,7 @@
from . import schemas, models, params
from apps.vadmin.auth.utils.validation.auth import Auth
from utils import os_utils as os, random_utils as ru
from utils.huawei_obs import ObsClient
from utils.huawei_obs import MyObs
from utils import status
from core.exception import CustomException
from application.settings import datasets_url, runs_url, images_url
@ -169,6 +169,7 @@ class ProjectImageDal(DalBase):
上传项目图片
"""
image_models = []
obs = MyObs()
for file in files:
image = models.ProjectImage()
image.project_id = pro.id
@ -179,14 +180,14 @@ class ProjectImageDal(DalBase):
image.image_url = path
# 上传图片到obs
object_key = pro.project_no + '/' + img_type + '/' + file.filename
success, key, url = ObsClient.put_file(object_key=object_key, file_path=path)
success, key, url = obs.put_file(object_key=object_key, file_path=path)
if success:
image.object_key = object_key
image.thumb_image_url = url
else:
raise CustomException("obs上传失败", code=status.HTTP_ERROR)
image_models.append(image)
await self.create_datas(datas=image_models)
await self.create_models(datas=image_models)
return len(image_models)
async def check_img_name(self, file_name: str, project_id: int, img_type: str):
@ -207,12 +208,12 @@ class ProjectImageDal(DalBase):
file_urls = []
object_keys = []
for img_id in ids:
image = self.get_data(data_id=img_id)
image = await self.get_data(data_id=img_id)
if image:
file_urls.append(image.image_url)
object_keys.append(image.object_key)
os.delete_file_if_exists(**file_urls)
ObsClient.del_objects(object_keys)
os.delete_file_if_exists(*file_urls)
MyObs().del_objects(object_keys)
await self.delete_datas(ids)
async def get_img_count(
@ -330,6 +331,11 @@ class ProjectImgLabelDal(DalBase):
v_order="asc",
v_order_field="id")
async def del_img_label(self, label_ids: list[int]):
img_labels = self.get_datas(v_where=[self.model.label_id.in_(label_ids)])
img_label_ids = [i.id for i in img_labels]
self.delete_datas(ids=img_label_ids)
class ProjectImgLeaferDal(DalBase):
"""
@ -342,6 +348,10 @@ class ProjectImgLeaferDal(DalBase):
self.model = models.ProjectImgLeafer
self.schema = schemas.ProjectImgLeaferOut
async def get_leafer(self, image_id: int):
img_label = self.get_data(v_where=[self.model.image_id == image_id])
return img_label.leafer
async def add_leafer(self, img_label_in: schemas.ProjectImgLeaferLabel):
# 先把历史数据都删掉,然后再保存
image_id = img_label_in.image_id

View File

@ -16,7 +16,7 @@ class ProjectImage(BaseModel):
project_id: Optional[int] = Field(..., description="项目id")
file_name: Optional[str] = Field(None, description="文件名称")
thumb_image_url: Optional[str] = Field(None, description="图片在obs上的链接")
create_time: DatetimeStr
create_datetime: DatetimeStr
model_config = ConfigDict(from_attributes=True)
@ -26,7 +26,7 @@ class ProjectImageOut(BaseModel):
project_id: Optional[int] = Field(..., description="项目id")
file_name: Optional[str] = Field(None, description="文件名称")
thumb_image_url: Optional[str] = Field(None, description="图片在obs上的链接")
create_time: DatetimeStr
label_count: Optional[int]
label_count: Optional[int] = Field(0, description="图片的标注数量")
create_datetime: DatetimeStr
model_config = ConfigDict(from_attributes=True)

View File

@ -5,11 +5,11 @@
# @File : views.py
# @IDE : PyCharm
# @desc : 路由,项目信息管理,包括项目主体,项目图片,项目标签和图片的标注信息
from utils.response import SuccessResponse, ErrorResponse
from . import params, schemas, crud, models
from core.dependencies import IdList
from typing import List
from core.dependencies import IdList
from . import params, schemas, crud, models
from utils.response import SuccessResponse, ErrorResponse
from fastapi import APIRouter, Depends, UploadFile, Form
from apps.vadmin.auth.utils.current import FullAdminAuth
from apps.vadmin.auth.utils.validation.auth import Auth
@ -60,12 +60,12 @@ async def del_project(
return SuccessResponse(msg="删除成功")
@app.get("/label/{pro_id}", summary="查询标签列表")
@app.get("/label/{project_id}", summary="查询标签列表")
async def label_list(
pro_id: int,
project_id: int,
auth: Auth = Depends(FullAdminAuth())
):
result = await crud.ProjectLabelDal(auth.db).get_datas(v_where=[models.ProjectLabel.project_id == pro_id],
result = await crud.ProjectLabelDal(auth.db).get_datas(v_where=[models.ProjectLabel.project_id == project_id],
v_schema=schemas.ProjectLabel)
return SuccessResponse(data=result)
@ -101,8 +101,7 @@ async def delete_label(
):
# 删除标签信息,然后删除图片标签关联表
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)
await crud.ProjectImgLabelDal(auth.db).del_img_label(label_ids.ids)
return SuccessResponse(msg="删除成功")
@ -111,7 +110,7 @@ async def project_pager(
param: params.ProjectImageParams = Depends(),
auth: Auth = Depends(FullAdminAuth())
):
if param.limit:
if param.limit > 0:
# 分页查询,关联一个标签数量
datas, count = await crud.ProjectImageDal(auth.db).img_page(param)
return SuccessResponse(data=datas, count=count)
@ -124,7 +123,7 @@ async def project_pager(
@app.post("/img", summary="上传图片")
async def up_img(
project_id: int = Form(...),
files: List[UploadFile] = Form(...),
files: list[UploadFile] = Form(...),
img_type: str = Form(...),
auth: Auth = Depends(FullAdminAuth())
):
@ -155,8 +154,10 @@ async def add_img_label(
return SuccessResponse(msg="保存成功")
@app.get("/img_label/{image_id}", summary="获取图片的标注信息")
async def get_img_label(
image_id: int,
auth: Auth = Depends(FullAdminAuth())
):
leafer = await crud.ProjectImgLeaferDal(auth.db).get_leafer(image_id)
return SuccessResponse(data=leafer)