diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java index eea9f8847e..10f50dcbc1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java @@ -88,6 +88,7 @@ public class ApiDocShareService { docShare.setCreateTime(System.currentTimeMillis()); docShare.setUpdateUser(currentUser); docShare.setUpdateTime(System.currentTimeMillis()); + docShare.setInvalidTime(request.getInvalidTime() == 0 ? Long.MAX_VALUE : request.getInvalidTime()); apiDocShareMapper.insert(docShare); return docShare; } @@ -104,6 +105,7 @@ public class ApiDocShareService { BeanUtils.copyBean(docShare, request); docShare.setUpdateUser(currentUser); docShare.setUpdateTime(System.currentTimeMillis()); + docShare.setInvalidTime(request.getInvalidTime() == 0 ? Long.MAX_VALUE : request.getInvalidTime()); apiDocShareMapper.updateByPrimaryKeySelective(docShare); return docShare; } @@ -138,7 +140,7 @@ public class ApiDocShareService { public ApiDocShareDetail detail(String id) { ApiDocShare docShare = checkExit(id); ApiDocShareDetail detail = ApiDocShareDetail.builder().allowExport(docShare.getAllowExport()).isPrivate(docShare.getIsPrivate()).build(); - if (docShare.getInvalidTime() == null || docShare.getInvalidTime() == 0) { + if (docShare.getInvalidTime() == null || docShare.getInvalidTime() == Long.MAX_VALUE) { detail.setInvalid(false); } else { detail.setInvalid(docShare.getInvalidTime() < System.currentTimeMillis()); @@ -210,6 +212,9 @@ public class ApiDocShareService { List distinctUpdateUserIds = docShares.stream().map(ApiDocShareDTO::getUpdateUser).distinct().toList(); Map userMap = userToolService.getUserMapByIds(ListUtils.union(distinctCreateUserIds, distinctUpdateUserIds)); docShares.forEach(docShare -> { + if (docShare.getInvalidTime() == Long.MAX_VALUE) { + docShare.setInvalidTime(0L); + } docShare.setInvalid(docShare.getInvalidTime() != null && docShare.getInvalidTime() != 0 && docShare.getInvalidTime() < System.currentTimeMillis()); docShare.setApiShareNum(countApiShare(docShare)); docShare.setCreateUserName(userMap.get(docShare.getCreateUser())); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java index e9bcd2ca87..a3a1dc5f35 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDocShareControllerTests.java @@ -54,6 +54,7 @@ public class ApiDocShareControllerTests extends BaseTest { request.setIsPrivate(false); request.setPassword("123456"); request.setAllowExport(false); + request.setInvalidTime(0L); MvcResult mvcResult = this.requestPostWithOk(ADD, request).andReturn(); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);