From ea79196478ffe08a64b8a80094983797f1f9e500 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 28 Jan 2021 18:03:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E8=B0=83=E8=AF=95=E9=BB=98=E8=AE=A4=E6=94=BE?= =?UTF-8?q?=E5=88=B0bug=E7=9B=AE=E5=BD=95=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/ApiModuleController.java | 6 +++++ .../api/service/ApiModuleService.java | 24 ++++++++++++++++++- .../components/case/ApiCaseItem.vue | 14 +++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java index 6d79390f91..8b37847748 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java @@ -29,6 +29,12 @@ public class ApiModuleController { return apiModuleService.getNodeTreeByProjectId(projectId,protocol); } + @GetMapping("/getModuleByName/{projectId}/{protocol}") + public ApiModule getModuleByName(@PathVariable String projectId,@PathVariable String protocol) { + checkPermissionService.checkProjectOwner(projectId); + return apiModuleService.getModuleByName(projectId,protocol); + } + @GetMapping("/list/plan/{planId}/{protocol}") public List getNodeByPlanId(@PathVariable String planId, @PathVariable String protocol) { checkPermissionService.checkTestPlanOwner(planId); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index b80947b793..d207ca7912 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -332,5 +332,27 @@ public class ApiModuleService extends NodeTreeService { sqlSession.flushStatements(); } - + public ApiModule getModuleByName(String projectId, String protocol) { + ApiModuleExample example = new ApiModuleExample(); + ApiModuleExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo("bug") + .andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol); + List modules = apiModuleMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(modules)) { + return modules.get(0); + } else { + ApiModule node = new ApiModule(); + node.setName("bug"); + node.setLevel(1); + node.setPos(0.0); + node.setParentId(null); + node.setProjectId(projectId); + node.setProtocol(protocol); + node.setCreateTime(System.currentTimeMillis()); + node.setUpdateTime(System.currentTimeMillis()); + node.setId(UUID.randomUUID().toString()); + apiModuleMapper.insertSelective(node); + return node; + } + } } diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue index 021c0aaa71..b6f86c8132 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue @@ -250,9 +250,19 @@ data.method = data.protocol; } }, - saveApi(row) { + addModule(row) { + let url = '/api/module/getModuleByName/' + getCurrentProjectID() + "/" + this.api.protocol; + this.$get(url, response => { + if (response.data) { + this.saveApi(row, response.data); + } + }); + }, + saveApi(row, module) { let data = this.api; data.name = this.apiCase.name; + data.moduleId = module.id; + data.modulePath = '/bug'; this.setParameters(data); let bodyFiles = this.getBodyUploadFiles(data); this.$fileUpload("/api/definition/create", null, bodyFiles, data, () => { @@ -296,7 +306,7 @@ }, saveTestCase(row) { if (this.api.saved) { - this.saveApi(row); + this.addModule(row); } else { this.saveCase(row); }