feat(测试计划): 补充接口分享查看链接接口

--story=1016179 --user=宋昌昌 【接口测试】接口文档 https://www.tapd.cn/55049933/s/1589978
This commit is contained in:
song-cc-rock 2024-10-12 17:15:10 +08:00 committed by Craftsman
parent 2738398318
commit 258178f369
4 changed files with 54 additions and 3 deletions

View File

@ -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);
}
}

View File

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

View File

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

View File

@ -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());