From c6a981e965c1040cb152e11401085353304e85e8 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 24 Nov 2020 10:42:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=8F=E8=AE=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/ApiDefinitionResult.java | 2 - .../definition/SaveApiDefinitionRequest.java | 2 + .../api/service/ApiDefinitionService.java | 16 ++++-- .../base/domain/ApiDefinition.java | 2 + .../base/domain/ApiDefinitionExample.java | 6 +++ .../base/mapper/ApiDefinitionMapper.xml | 18 ++++--- .../api/definition/ApiDefinition.vue | 2 + .../api/definition/components/ApiCaseList.vue | 10 ++-- .../api/definition/components/ApiConfig.vue | 20 ++++--- .../api/definition/components/ApiList.vue | 11 ++-- .../api/definition/components/ApiModule.vue | 2 +- .../{AddBasisHttpApi.vue => AddBasisApi.vue} | 52 ++++++++++++------- .../complete/AddCompleteHttpApi.vue | 11 ++-- .../api/definition/model/JsonData.js | 4 +- 14 files changed, 100 insertions(+), 58 deletions(-) rename frontend/src/business/components/api/definition/components/basis/{AddBasisHttpApi.vue => AddBasisApi.vue} (76%) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionResult.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionResult.java index fcb345c504..f129c5b161 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionResult.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionResult.java @@ -11,8 +11,6 @@ public class ApiDefinitionResult extends ApiDefinition { private String projectName; - private String url; - private String userName; private String caseTotal; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java index 542974134e..05adc44e30 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/SaveApiDefinitionRequest.java @@ -20,6 +20,8 @@ public class SaveApiDefinitionRequest { private String name; + private String path; + private String protocol; private String moduleId; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 8eb7fdde22..2f093fdaa1 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.APIReportResult; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.scenario.request.RequestType; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.jmeter.TestResult; import io.metersphere.base.domain.*; @@ -141,9 +142,16 @@ public class ApiDefinitionService { private void checkNameExist(SaveApiDefinitionRequest request) { ApiDefinitionExample example = new ApiDefinitionExample(); - example.createCriteria().andProtocolEqualTo(request.getProtocol()).andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId()); - if (apiDefinitionMapper.countByExample(example) > 0) { - MSException.throwException(Translator.get("api_definition_url_not_repeating")); + if (request.getProtocol().equals(RequestType.HTTP)) { + example.createCriteria().andProtocolEqualTo(request.getProtocol()).andPathEqualTo(request.getPath()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId()); + if (apiDefinitionMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("api_definition_url_not_repeating")); + } + } else { + example.createCriteria().andProtocolEqualTo(request.getProtocol()).andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId()); + if (apiDefinitionMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("load_test_already_exists")); + } } } @@ -153,6 +161,7 @@ public class ApiDefinitionService { final ApiDefinition test = new ApiDefinition(); test.setId(request.getId()); test.setName(request.getName()); + test.setPath(request.getPath()); test.setProjectId(request.getProjectId()); test.setRequest(JSONObject.toJSONString(request.getRequest())); test.setUpdateTime(System.currentTimeMillis()); @@ -177,6 +186,7 @@ public class ApiDefinitionService { test.setName(request.getName()); test.setProtocol(request.getProtocol()); test.setMethod(request.getMethod()); + test.setPath(request.getPath()); test.setModuleId(request.getModuleId()); test.setProjectId(request.getProjectId()); test.setRequest(JSONObject.toJSONString(request.getRequest())); diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java index 571c80d57c..718db66998 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java @@ -14,6 +14,8 @@ public class ApiDefinition implements Serializable { private String method; + private String path; + private String protocol; private String environmentId; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java index 17185c26be..22b966e3a4 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java @@ -264,6 +264,12 @@ public class ApiDefinitionExample { return (Criteria) this; } + public Criteria andPathEqualTo(String value) { + addCriterion("path =", value, "path"); + return (Criteria) this; + } + + public Criteria andProtocolEqualTo(String value) { addCriterion("protocol =", value, "protocol"); return (Criteria) this; diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml index bdb1cffcf5..a41f2ca464 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml @@ -8,6 +8,7 @@ + @@ -80,7 +81,7 @@ - id, project_id, name,module_id,module_path,protocol ,method ,description, status, user_id, create_time, update_time + id, project_id, name,module_id,module_path,protocol ,path,method ,description, status, user_id, create_time, update_time request @@ -204,7 +205,7 @@