diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FileAssociationSourceUtil.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FileAssociationSourceUtil.java index 25f05807d9..03ac016410 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FileAssociationSourceUtil.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FileAssociationSourceUtil.java @@ -14,12 +14,14 @@ public class FileAssociationSourceUtil { public static final String SOURCE_TYPE_BUG = "BUG"; public static final String SOURCE_TYPE_FUNCTIONAL_CASE = "FUNCTIONAL_CASE"; public static final String SOURCE_TYPE_API_DEBUG = "API_DEBUG"; + public static final String SOURCE_TYPE_API_TEST_CASE = "API_TEST_CASE"; public static final Map QUERY_SQL = new HashMap<>(); static { QUERY_SQL.put(SOURCE_TYPE_BUG, "SELECT id AS sourceId,title AS sourceName FROM bug"); QUERY_SQL.put(SOURCE_TYPE_FUNCTIONAL_CASE, "SELECT id AS sourceId,name AS sourceName FROM functional_case"); QUERY_SQL.put(SOURCE_TYPE_API_DEBUG, "SELECT id AS sourceId,name AS sourceName FROM api_debug"); + QUERY_SQL.put(SOURCE_TYPE_API_TEST_CASE, "SELECT id AS sourceId,name AS sourceName FROM api_test_case"); } public static void validate(String type) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index d139f0fa7b..4fa325f36f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -40,8 +41,8 @@ public class ApiTestCaseController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD) @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiTestCaseLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.CASE_CREATE, target = "#targetClass.getCaseDTO(#request)", targetClass = ApiTestCaseNoticeService.class) - public ApiTestCase add(@Validated @RequestPart("request") ApiTestCaseAddRequest request, @RequestPart(value = "files", required = false) List files) { - return apiTestCaseService.addCase(request, files, SessionUtils.getUserId()); + public ApiTestCase add(@Validated @RequestBody ApiTestCaseAddRequest request) { + return apiTestCaseService.addCase(request, SessionUtils.getUserId()); } @GetMapping(value = "/get-detail/{id}") @@ -64,7 +65,7 @@ public class ApiTestCaseController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_RECOVER) @Log(type = OperationLogType.RECOVER, expression = "#msClass.recoverLog(#id)", msClass = ApiTestCaseLogService.class) public void recover(@PathVariable String id) { - apiTestCaseService.recover(id); + apiTestCaseService.recover(id, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); } @GetMapping("follow/{id}") @@ -95,8 +96,8 @@ public class ApiTestCaseController { @Operation(summary = "接口测试-接口管理-接口用例-更新") @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiTestCaseLogService.class) - public ApiTestCase update(@Validated @RequestPart("request") ApiTestCaseUpdateRequest request, @RequestPart(value = "files", required = false) List files) { - return apiTestCaseService.update(request, files, SessionUtils.getUserId()); + public ApiTestCase update(@Validated @RequestBody ApiTestCaseUpdateRequest request) { + return apiTestCaseService.update(request, SessionUtils.getUserId()); } @GetMapping(value = "/update-status/{id}/{status}") @@ -150,5 +151,11 @@ public class ApiTestCaseController { apiTestCaseService.editPos(request); } + @PostMapping("/upload/temp/file") + @Operation(summary = "上传接口调试所需的文件资源,并返回文件ID") + @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}) + public String uploadTempFile(@RequestParam("file") MultipartFile file) { + return apiTestCaseService.uploadTempFile(file); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseAddRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseAddRequest.java index def25f96fe..c68c2f34d7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseAddRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseAddRequest.java @@ -51,7 +51,16 @@ public class ApiTestCaseAddRequest implements Serializable { @NotBlank private String request; - @Schema(description = "接口用例所需的所有文件资源ID") - private List fileIds; + /** + * 新上传的文件ID + * 创建时先按ID创建目录,再把文件放入目录 + */ + @Schema(description = "新上传的文件ID") + private List uploadFileIds; + /** + * 新关联的文件ID + */ + @Schema(description = "关联文件ID") + private List linkFileIds; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java index 54db6eae74..de5d66a574 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseDTO.java @@ -84,6 +84,4 @@ public class ApiTestCaseDTO { @Schema(description = "请求内容") private AbstractMsTestElement request; - @Schema(description = "接口用例所关联的文件ID列表,修改时需要作为参数传入") - private List fileIds; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseUpdateRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseUpdateRequest.java index 746ed3cb34..fca49d1dcc 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseUpdateRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseUpdateRequest.java @@ -45,15 +45,29 @@ public class ApiTestCaseUpdateRequest implements Serializable { @NotBlank private String request; - @Schema(description = "接口用例所需的所有文件资源ID") - private List fileIds; - /** * 新上传的文件ID - * 为了解决文件名称重复的问题,需要把文件和ID一一对应 * 创建时先按ID创建目录,再把文件放入目录 */ - @Schema(description = "新上传的文件ID,与上传的文件顺序保持一致") - private List addFileIds; + @Schema(description = "新上传的文件ID") + private List uploadFileIds; + + /** + * 新关联文件管理的文件ID + */ + @Schema(description = "关联文件ID") + private List linkFileIds; + + /** + * 删除本地上传的文件ID + */ + @Schema(description = "删除的文件ID") + private List deleteFileIds; + + /** + * 删除关联的文件ID + */ + @Schema(description = "取消关联文件ID") + private List unLinkRefIds; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml index 54211a1832..adee48e5b1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml @@ -58,7 +58,9 @@