完成项目管理模块的接口测试
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user