From 4ac32d7c174646f41959e68c3c818dbf339de879 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Tue, 2 Jun 2020 15:15:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?API=E6=B5=8B=E8=AF=95=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=8D=E8=83=BD=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/APITestService.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index a9a4952f03..9cd229e026 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -1,7 +1,6 @@ package io.metersphere.api.service; import io.metersphere.api.dto.APITestResult; -import io.metersphere.api.dto.DeleteAPITestRequest; import io.metersphere.api.dto.QueryAPITestRequest; import io.metersphere.api.dto.SaveAPITestRequest; import io.metersphere.api.jmeter.JMeterService; @@ -11,6 +10,7 @@ import io.metersphere.base.mapper.ApiTestMapper; import io.metersphere.base.mapper.ext.ExtApiTestMapper; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; import io.metersphere.service.FileService; @@ -19,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Resource; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.List; @@ -26,8 +27,6 @@ import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; -import javax.annotation.Resource; - @Service @Transactional(rollbackFor = Exception.class) public class APITestService { @@ -46,6 +45,7 @@ public class APITestService { private APIReportService apiReportService; public List list(QueryAPITestRequest request) { + request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); return extApiTestMapper.list(request); } @@ -150,10 +150,22 @@ public class APITestService { test.setUpdateTime(System.currentTimeMillis()); test.setStatus(APITestStatus.Saved.name()); test.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId()); + checkApiTestPlanExist(test); apiTestMapper.insert(test); return test; } + private void checkApiTestPlanExist(ApiTest apiTest) { + if (apiTest.getName() != null) { + ApiTestExample example = new ApiTestExample(); + example.createCriteria() + .andNameEqualTo(apiTest.getName()); + if (apiTestMapper.selectByExample(example).size() > 0) { + MSException.throwException(Translator.get("api_test_name_already_exists")); + } + } + } + private void saveFile(String testId, List files) { files.forEach(file -> { final FileMetadata fileMetadata = fileService.saveFile(file); From ffaefb398592cf3af0d43df83eb39143764349f0 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Tue, 2 Jun 2020 15:20:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9API=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=90=8D=E7=A7=B0=E4=B8=8D=E8=83=BD=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/APITestService.java | 1 + .../components/api/test/ApiTestList.vue | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 9cd229e026..561c80052a 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -130,6 +130,7 @@ public class APITestService { test.setScenarioDefinition(request.getScenarioDefinition()); test.setUpdateTime(System.currentTimeMillis()); test.setStatus(APITestStatus.Saved.name()); + checkApiTestPlanExist(test); apiTestMapper.updateByPrimaryKeySelective(test); return test; } diff --git a/frontend/src/business/components/api/test/ApiTestList.vue b/frontend/src/business/components/api/test/ApiTestList.vue index e3cb18c6aa..44fe26faf9 100644 --- a/frontend/src/business/components/api/test/ApiTestList.vue +++ b/frontend/src/business/components/api/test/ApiTestList.vue @@ -7,7 +7,8 @@ :title="$t('commons.test')" @create="create" :createTip="$t('load_test.create')"/> - +