refactor(接口定义): 优化接口调试模块树显示
This commit is contained in:
parent
1a5d69840c
commit
701f5e3b5b
|
@ -26,11 +26,11 @@ public class ApiDebugModuleController {
|
|||
@Resource
|
||||
private ApiDebugModuleService apiDebugModuleService;
|
||||
|
||||
@GetMapping("/tree/{protocol}")
|
||||
@GetMapping("/tree")
|
||||
@Operation(summary = "接口测试-接口调试-模块-查找模块")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEBUG_READ)
|
||||
public List<BaseTreeNode> getTree(@PathVariable String protocol) {
|
||||
return apiDebugModuleService.getTree(protocol, SessionUtils.getUserId());
|
||||
public List<BaseTreeNode> getTree() {
|
||||
return apiDebugModuleService.getTree(SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package io.metersphere.api.dto.debug;
|
||||
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -13,11 +11,6 @@ public class ApiDebugRequest {
|
|||
@Schema(description = "模块ID(根据模块树查询时要把当前节点以及子节点都放在这里。)")
|
||||
private List<@NotBlank String> moduleIds;
|
||||
|
||||
@Schema(description = "协议", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{api_debug_module.protocol.not_blank}")
|
||||
@Size(min = 1, max = 20, message = "{api_debug.protocol.length_range}")
|
||||
private String protocol = ModuleConstants.NODE_PROTOCOL_HTTP;
|
||||
|
||||
@Schema(description = "关键字")
|
||||
private String keyword;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
public interface ExtApiDebugModuleMapper {
|
||||
List<BaseTreeNode> selectBaseByProtocolAndUser(String protocol, String userId);
|
||||
List<BaseTreeNode> selectBaseByProtocolAndUser(String userId);
|
||||
|
||||
List<BaseTreeNode> selectIdAndParentIdByProtocolAndUserId(String protocol, String userId);
|
||||
List<BaseTreeNode> selectIdAndParentIdByProtocolAndUserId(String userId);
|
||||
|
||||
List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds);
|
||||
|
||||
|
@ -29,7 +29,7 @@ public interface ExtApiDebugModuleMapper {
|
|||
|
||||
BaseModule selectModuleByParentIdAndPosOperator(NodeSortQueryParam nodeSortQueryParam);
|
||||
|
||||
List<ApiTreeNode> selectApiDebugByProtocolAndUser(String protocol, String userId);
|
||||
List<ApiTreeNode> selectApiDebugByProtocolAndUser(String userId);
|
||||
|
||||
List<ModuleCountDTO> countModuleIdByKeywordAndProtocol(@Param("request") ApiDebugRequest request, @Param("userId") String userId);
|
||||
}
|
||||
|
|
|
@ -110,9 +110,6 @@
|
|||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="request.protocol != null and request.protocol != ''">
|
||||
AND f.protocol = #{request.protocol}
|
||||
</if>
|
||||
|
||||
</where>
|
||||
</sql>
|
||||
|
|
|
@ -56,10 +56,15 @@ public class DocumentAssertionConverter extends ResponseBodyTypeAssertionConvert
|
|||
|
||||
private void conditions(List<MsDocumentAssertionElement> dataList, Map<String, ElementCondition> conditionMap) {
|
||||
dataList.forEach(item -> {
|
||||
ElementCondition elementCondition = new ElementCondition(item.getInclude(), item.getTypeVerification(), item.getArrayVerification(), new LinkedList<Condition>() {{
|
||||
ElementCondition elementCondition =
|
||||
ElementCondition.builder()
|
||||
.include(item.getInclude())
|
||||
.typeVerification(item.getTypeVerification())
|
||||
.arrayVerification(item.getArrayVerification())
|
||||
.type(item.getType())
|
||||
.conditions(new LinkedList<Condition>() {{
|
||||
this.add(new Condition(item.getCondition(), item.getExpectedResult()));
|
||||
}});
|
||||
elementCondition.setType(item.getType());
|
||||
}}).build();
|
||||
conditionMap.put(item.getId(), elementCondition);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(item.getChildren())) {
|
||||
|
|
|
@ -59,10 +59,10 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
@Resource
|
||||
private ApiFileResourceService apiFileResourceService;
|
||||
|
||||
public List<BaseTreeNode> getTree(String protocol, String userId) {
|
||||
List<BaseTreeNode> fileModuleList = extApiDebugModuleMapper.selectBaseByProtocolAndUser(protocol, userId);
|
||||
public List<BaseTreeNode> getTree(String userId) {
|
||||
List<BaseTreeNode> fileModuleList = extApiDebugModuleMapper.selectBaseByProtocolAndUser(userId);
|
||||
List<BaseTreeNode> baseTreeNodes = super.buildTreeAndCountResource(fileModuleList, true, Translator.get(UNPLANNED));
|
||||
List<ApiTreeNode> apiTreeNodeList = extApiDebugModuleMapper.selectApiDebugByProtocolAndUser(protocol, userId);
|
||||
List<ApiTreeNode> apiTreeNodeList = extApiDebugModuleMapper.selectApiDebugByProtocolAndUser(userId);
|
||||
return getBaseTreeNodes(apiTreeNodeList, baseTreeNodes);
|
||||
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
baseTreeNode.setType(apiTreeNode.getType());
|
||||
if (StringUtils.equals(apiTreeNode.getProtocol(), ModuleConstants.NODE_PROTOCOL_HTTP)) {
|
||||
baseTreeNode.putAttachInfo(METHOD, apiTreeNode.getMethod());
|
||||
baseTreeNode.putAttachInfo(PROTOCOL, apiTreeNode.getProtocol());
|
||||
} else {
|
||||
baseTreeNode.putAttachInfo(PROTOCOL, apiTreeNode.getProtocol());
|
||||
}
|
||||
|
@ -103,9 +104,9 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
return baseTreeNodes;
|
||||
}
|
||||
|
||||
public List<BaseTreeNode> getTreeOnlyIdsAndResourceCount(String protocol, String userId, List<ModuleCountDTO> moduleCountDTOList) {
|
||||
public List<BaseTreeNode> getTreeOnlyIdsAndResourceCount(String userId, List<ModuleCountDTO> moduleCountDTOList) {
|
||||
//节点内容只有Id和parentId
|
||||
List<BaseTreeNode> fileModuleList = extApiDebugModuleMapper.selectIdAndParentIdByProtocolAndUserId(protocol, userId);
|
||||
List<BaseTreeNode> fileModuleList = extApiDebugModuleMapper.selectIdAndParentIdByProtocolAndUserId(userId);
|
||||
return super.buildTreeAndCountResource(fileModuleList, moduleCountDTOList, true, Translator.get(UNPLANNED));
|
||||
}
|
||||
|
||||
|
@ -160,15 +161,6 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
example.clear();
|
||||
}
|
||||
|
||||
private String getRootNodeId(ApiDebugModule module) {
|
||||
if (StringUtils.equals(module.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
|
||||
return module.getId();
|
||||
} else {
|
||||
ApiDebugModule parentModule = apiDebugModuleMapper.selectByPrimaryKey(module.getParentId());
|
||||
return this.getRootNodeId(parentModule);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ModuleUpdateRequest request, String userId, String projectId) {
|
||||
ApiDebugModule module = checkModuleExist(request.getId());
|
||||
ApiDebugModule updateModule = new ApiDebugModule();
|
||||
|
@ -258,9 +250,9 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
/**
|
||||
* 查找当前项目下模块每个节点对应的资源统计
|
||||
*/
|
||||
public Map<String, Long> getModuleCountMap(String protocol, String userId, List<ModuleCountDTO> moduleCountDTOList) {
|
||||
public Map<String, Long> getModuleCountMap(String userId, List<ModuleCountDTO> moduleCountDTOList) {
|
||||
//构建模块树,并计算每个节点下的所有数量(包含子节点)
|
||||
List<BaseTreeNode> treeNodeList = this.getTreeOnlyIdsAndResourceCount(protocol, userId, moduleCountDTOList);
|
||||
List<BaseTreeNode> treeNodeList = this.getTreeOnlyIdsAndResourceCount(userId, moduleCountDTOList);
|
||||
return super.getIdCountMapByBreadth(treeNodeList);
|
||||
}
|
||||
|
||||
|
@ -294,7 +286,7 @@ public class ApiDebugModuleService extends ModuleTreeService {
|
|||
request.setModuleIds(null);
|
||||
List<ModuleCountDTO> moduleCountDTOList = extApiDebugModuleMapper.countModuleIdByKeywordAndProtocol(request, operator);
|
||||
long allCount = getAllCount(moduleCountDTOList);
|
||||
Map<String, Long> moduleCountMap = getModuleCountMap(request.getProtocol(), operator, moduleCountDTOList);
|
||||
Map<String, Long> moduleCountMap = getModuleCountMap(operator, moduleCountDTOList);
|
||||
moduleCountMap.put(DEBUG_MODULE_COUNT_ALL, allCount);
|
||||
return moduleCountMap;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ApiDebugModuleControllerTests extends BaseTest {
|
|||
private static final String URL_MODULE_ADD = "/api/debug/module/add";
|
||||
private static final String URL_MODULE_UPDATE = "/api/debug/module/update";
|
||||
private static final String URL_MODULE_DELETE = "/api/debug/module/delete/%s";
|
||||
private static final String URL_MODULE_TREE = "/api/debug/module/tree/%s";
|
||||
private static final String URL_MODULE_TREE = "/api/debug/module/tree";
|
||||
private static final String URL_MODULE_MOVE = "/api/debug/module/move";
|
||||
private static final String URL_FILE_MODULE_COUNT = "/api/debug/module/count";
|
||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||
|
@ -748,9 +748,7 @@ public class ApiDebugModuleControllerTests extends BaseTest {
|
|||
@Order(8)
|
||||
public void TestModuleCountSuccess() throws Exception {
|
||||
this.preliminaryData();
|
||||
ApiDebugRequest request = new ApiDebugRequest() {{
|
||||
this.setProtocol(ApiConstants.HTTP_PROTOCOL);
|
||||
}};
|
||||
ApiDebugRequest request = new ApiDebugRequest();
|
||||
MvcResult moduleCountMvcResult = this.requestPostWithOkAndReturn(URL_FILE_MODULE_COUNT, request);
|
||||
Map<String, Integer> moduleCountResult = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(moduleCountMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
|
@ -760,15 +758,6 @@ public class ApiDebugModuleControllerTests extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void TestModuleCountError() throws Exception {
|
||||
ApiDebugRequest request = new ApiDebugRequest();
|
||||
request.setProtocol(null);
|
||||
this.requestPost(URL_FILE_MODULE_COUNT, request).andExpect(BAD_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void deleteModuleTestSuccess() throws Exception {
|
||||
|
@ -801,10 +790,10 @@ public class ApiDebugModuleControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
private List<BaseTreeNode> getDebugModuleTreeNode() throws Exception {
|
||||
MvcResult result = this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, ModuleConstants.NODE_PROTOCOL_HTTP));
|
||||
MvcResult result = this.requestGetWithOkAndReturn(URL_MODULE_TREE);
|
||||
String returnData = result.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
this.requestGetWithOkAndReturn(String.format(URL_MODULE_TREE, "TCP"));
|
||||
this.requestGetWithOkAndReturn(URL_MODULE_TREE);
|
||||
return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.metersphere.api.controller;
|
|||
|
||||
import io.metersphere.api.constants.ApiConstants;
|
||||
import io.metersphere.api.domain.*;
|
||||
import io.metersphere.api.dto.debug.ApiDebugRequest;
|
||||
import io.metersphere.api.dto.debug.ModuleCreateRequest;
|
||||
import io.metersphere.api.dto.debug.ModuleUpdateRequest;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
|
@ -825,15 +824,6 @@ public class ApiDefinitionModuleControllerTests extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void TestModuleCountError() throws Exception {
|
||||
ApiDebugRequest request = new ApiDebugRequest();
|
||||
request.setProtocol(null);
|
||||
this.requestPost(URL_FILE_MODULE_COUNT, request).andExpect(BAD_REQUEST_MATCHER);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void deleteModuleTestSuccess() throws Exception {
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
package io.metersphere.project.api.assertion.body;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Condition {
|
||||
private String key;
|
||||
private Object value;
|
||||
|
||||
public Condition() {
|
||||
|
||||
}
|
||||
|
||||
public Condition(String key, Object value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package io.metersphere.project.api.assertion.body;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ElementCondition {
|
||||
private boolean include;
|
||||
private boolean typeVerification;
|
||||
|
@ -12,11 +14,4 @@ public class ElementCondition {
|
|||
private String type;
|
||||
|
||||
List<Condition> conditions;
|
||||
|
||||
public ElementCondition(boolean include, boolean typeVerification, boolean arrayVerification, List<Condition> conditions) {
|
||||
this.include = include;
|
||||
this.typeVerification = typeVerification;
|
||||
this.arrayVerification = arrayVerification;
|
||||
this.conditions = conditions;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue