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 @@