diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java index 9da65498f0..583b84de9b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java @@ -4,6 +4,7 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.domain.ApiDocShare; import io.metersphere.api.dto.definition.ApiDocShareDTO; +import io.metersphere.api.dto.definition.ApiDocShareDetail; import io.metersphere.api.dto.definition.request.ApiDocShareCheckRequest; import io.metersphere.api.dto.definition.request.ApiDocShareEditRequest; import io.metersphere.api.dto.definition.request.ApiDocSharePageRequest; @@ -84,4 +85,11 @@ public class ApiDocShareController { public Boolean delete(@Validated @RequestBody ApiDocShareCheckRequest request) { return apiDocShareService.check(request); } + + @GetMapping("/detail/{id}") + @Operation(summary = "接口测试-接口管理-查看链接") + @Parameter(name = "id", description = "分享ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) + public ApiDocShareDetail detail(@PathVariable String id) { + return apiDocShareService.detail(id); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDetail.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDetail.java new file mode 100644 index 0000000000..c778e33d61 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDetail.java @@ -0,0 +1,22 @@ +package io.metersphere.api.dto.definition; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author song-cc-rock + */ +@Data +@Builder +public class ApiDocShareDetail implements Serializable { + + @Schema(title = "是否失效") + private Boolean invalid; + @Schema(title = "是否公开") + private Boolean isPublic; + @Schema(title = "是否允许导出") + private Boolean allowExport; +} 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 b19e5ed972..20eb9f1052 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 @@ -2,6 +2,7 @@ package io.metersphere.api.service.definition; import io.metersphere.api.domain.ApiDocShare; import io.metersphere.api.dto.definition.ApiDocShareDTO; +import io.metersphere.api.dto.definition.ApiDocShareDetail; import io.metersphere.api.dto.definition.request.ApiDocShareCheckRequest; import io.metersphere.api.dto.definition.request.ApiDocShareEditRequest; import io.metersphere.api.dto.definition.request.ApiDocSharePageRequest; @@ -91,14 +92,30 @@ public class ApiDocShareService { * @return 是否正确 */ public Boolean check(ApiDocShareCheckRequest request) { - checkExit(request.getDocShareId()); - ApiDocShare docShare = apiDocShareMapper.selectByPrimaryKey(request.getDocShareId()); + ApiDocShare docShare = checkExit(request.getDocShareId()); if (StringUtils.isBlank(docShare.getPassword())) { return true; } return StringUtils.equals(docShare.getPassword(), request.getPassword()); } + /** + * 获取分享详情 + * @param id 分享ID + * @return 分享详情 + */ + public ApiDocShareDetail detail(String id) { + ApiDocShare docShare = checkExit(id); + ApiDocShareDetail detail = ApiDocShareDetail.builder().allowExport(docShare.getAllowExport()).isPublic(docShare.getIsPublic()).build(); + if (docShare.getInvalidTime() == null || StringUtils.isBlank(docShare.getInvalidUnit())) { + detail.setInvalid(false); + } else { + Long deadline = calculateDeadline(docShare.getInvalidTime(), docShare.getInvalidUnit(), docShare.getCreateTime()); + detail.setInvalid(deadline < System.currentTimeMillis()); + } + return detail; + } + /** * 构建分享额外信息 * @param docShares 分享列表 @@ -169,10 +186,11 @@ public class ApiDocShareService { * 是否存在 * @param id 分享ID */ - private void checkExit(String id) { + private ApiDocShare checkExit(String id) { ApiDocShare docShare = apiDocShareMapper.selectByPrimaryKey(id); if (docShare == null) { throw new MSException(Translator.get("api_doc_share.not_exist")); } + return docShare; } } 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 025bad7f20..f5e008ae18 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 @@ -31,6 +31,7 @@ public class ApiDocShareControllerTests extends BaseTest { private final static String DELETE = BASE_PATH + "delete/"; private final static String PAGE = BASE_PATH + "page"; private final static String CHECK = BASE_PATH + "check"; + private final static String DETAIL = BASE_PATH + "detail/"; @Order(1) @Test @@ -51,6 +52,7 @@ public class ApiDocShareControllerTests extends BaseTest { checkRequest.setDocShareId(docShare.getId()); checkRequest.setPassword("123456"); this.requestPostWithOk(CHECK, checkRequest); + this.requestGetWithOk(DETAIL + docShare.getId()); request.setId(docShare.getId()); request.setName("share-2"); request.setPassword(StringUtils.EMPTY); @@ -60,6 +62,7 @@ public class ApiDocShareControllerTests extends BaseTest { request.setInvalidUnit("HOUR"); this.requestPostWithOk(UPDATE, request); this.requestPostWithOk(CHECK, checkRequest); + this.requestGetWithOk(DETAIL + docShare.getId()); this.requestGetWithOk(DELETE + docShare.getId()); // 不存在的ID this.requestGet(DELETE + "not-exist-id").andExpect(status().is5xxServerError());