refactor(用例管理): 功能用例接口优化
This commit is contained in:
parent
3ea9341d46
commit
58a5d95e80
|
@ -75,7 +75,8 @@ public class FunctionalCaseController {
|
|||
@Operation(summary = "功能用例-查看用例详情")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
|
||||
public FunctionalCaseDetailDTO getFunctionalCaseDetail(@PathVariable String id) {
|
||||
return functionalCaseService.getFunctionalCaseDetail(id);
|
||||
String userId = SessionUtils.getUserId();
|
||||
return functionalCaseService.getFunctionalCaseDetail(id, userId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,14 +100,6 @@ public class FunctionalCaseController {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("/follower/{id}")
|
||||
@Operation(summary = "功能用例-获取用例关注人")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
|
||||
public List<String> getFollower(@PathVariable @NotBlank(message = "{functional_case.id.not_blank}") String id) {
|
||||
return functionalCaseService.getFollower(id);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/version/{id}")
|
||||
@Operation(summary = "功能用例-版本信息(用例是否存在多版本)")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
|
||||
|
|
|
@ -79,4 +79,7 @@ public class FunctionalCaseDetailDTO implements Serializable {
|
|||
|
||||
@Schema(description = "附件信息")
|
||||
private List<FunctionalCaseAttachmentDTO> attachments;
|
||||
|
||||
@Schema(description = "关注标识")
|
||||
private Boolean followFlag;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.functional.mapper.FunctionalCaseFollowerMapper;
|
|||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||
import io.metersphere.functional.request.*;
|
||||
import io.metersphere.functional.result.FunctionalCaseResultCode;
|
||||
import io.metersphere.project.mapper.ExtProjectVersionMapper;
|
||||
import io.metersphere.project.service.ProjectTemplateService;
|
||||
import io.metersphere.sdk.constants.ApplicationNumScope;
|
||||
import io.metersphere.sdk.constants.FunctionalCaseExecuteResult;
|
||||
|
@ -73,6 +74,9 @@ public class FunctionalCaseService {
|
|||
@Resource
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
@Resource
|
||||
private ExtProjectVersionMapper extProjectVersionMapper;
|
||||
|
||||
public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List<MultipartFile> files, String userId) {
|
||||
String caseId = IDGenerator.nextStr();
|
||||
//添加功能用例
|
||||
|
@ -107,8 +111,7 @@ public class FunctionalCaseService {
|
|||
functionalCase.setCreateUser(userId);
|
||||
functionalCase.setCreateTime(System.currentTimeMillis());
|
||||
functionalCase.setUpdateTime(System.currentTimeMillis());
|
||||
//TODO v1.0不能固定 后续换成版本接口提供默认版本id
|
||||
functionalCase.setVersionId(StringUtils.defaultIfBlank(request.getVersionId(), "v1.0.0"));
|
||||
functionalCase.setVersionId(StringUtils.defaultIfBlank(request.getVersionId(), extProjectVersionMapper.getDefaultVersion(request.getProjectId())));
|
||||
functionalCaseMapper.insertSelective(functionalCase);
|
||||
//附属表
|
||||
FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob();
|
||||
|
@ -140,7 +143,7 @@ public class FunctionalCaseService {
|
|||
* @param functionalCaseId
|
||||
* @return
|
||||
*/
|
||||
public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId) {
|
||||
public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId) {
|
||||
FunctionalCase functionalCase = checkFunctionalCase(functionalCaseId);
|
||||
FunctionalCaseDetailDTO functionalCaseDetailDTO = new FunctionalCaseDetailDTO();
|
||||
BeanUtils.copyBean(functionalCaseDetailDTO, functionalCase);
|
||||
|
@ -150,6 +153,11 @@ public class FunctionalCaseService {
|
|||
//模板校验 获取自定义字段
|
||||
functionalCaseDetailDTO = checkTemplateCustomField(functionalCaseDetailDTO, functionalCase);
|
||||
|
||||
//是否关注用例
|
||||
Boolean isFollow = checkIsFollowCase(functionalCase.getId(), userId);
|
||||
functionalCaseDetailDTO.setFollowFlag(isFollow);
|
||||
|
||||
|
||||
//获取附件信息
|
||||
functionalCaseAttachmentService.getAttachmentInfo(functionalCaseDetailDTO);
|
||||
|
||||
|
@ -157,6 +165,13 @@ public class FunctionalCaseService {
|
|||
|
||||
}
|
||||
|
||||
private Boolean checkIsFollowCase(String caseId, String userId) {
|
||||
FunctionalCaseFollowerExample example = new FunctionalCaseFollowerExample();
|
||||
example.createCriteria().andCaseIdEqualTo(caseId).andUserIdEqualTo(userId);
|
||||
return functionalCaseFollowerMapper.countByExample(example) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验用例是否存在
|
||||
*
|
||||
|
@ -282,25 +297,6 @@ public class FunctionalCaseService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用例关注人
|
||||
*
|
||||
* @param functionalCaseId
|
||||
* @return
|
||||
*/
|
||||
public List<String> getFollower(String functionalCaseId) {
|
||||
checkFunctionalCase(functionalCaseId);
|
||||
FunctionalCaseFollowerExample example = new FunctionalCaseFollowerExample();
|
||||
example.createCriteria().andCaseIdEqualTo(functionalCaseId);
|
||||
List<FunctionalCaseFollower> caseFollowers = functionalCaseFollowerMapper.selectByExample(example);
|
||||
List<String> followers = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(caseFollowers)) {
|
||||
followers = caseFollowers.stream().map(FunctionalCaseFollower::getUserId).distinct().collect(Collectors.toList());
|
||||
}
|
||||
return followers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除用例
|
||||
*
|
||||
|
|
|
@ -41,7 +41,6 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
public static final String FUNCTIONAL_CASE_DETAIL_URL = "/functional/case/detail/";
|
||||
public static final String FUNCTIONAL_CASE_UPDATE_URL = "/functional/case/update";
|
||||
public static final String FUNCTIONAL_CASE_EDIT_FOLLOWER_URL = "/functional/case/edit/follower";
|
||||
public static final String FUNCTIONAL_CASE_FOLLOWER_URL = "/functional/case/follower/";
|
||||
public static final String FUNCTIONAL_CASE_DELETE_URL = "/functional/case/delete";
|
||||
public static final String FUNCTIONAL_CASE_LIST_URL = "/functional/case/page";
|
||||
public static final String FUNCTIONAL_CASE_BATCH_DELETE_URL = "/functional/case/batch/delete-to-gc";
|
||||
|
@ -235,22 +234,12 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
//获取关注人
|
||||
MvcResult followerMvcResult = this.requestGetWithOkAndReturn(FUNCTIONAL_CASE_FOLLOWER_URL + "TEST_FUNCTIONAL_CASE_ID");
|
||||
String followerReturnData = followerMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder followerResultHolder = JSON.parseObject(followerReturnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(followerResultHolder);
|
||||
|
||||
//取消关注
|
||||
MvcResult editMvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_EDIT_FOLLOWER_URL, functionalCaseFollowerRequest);
|
||||
String editReturnData = editMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder editResultHolder = JSON.parseObject(editReturnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(editResultHolder);
|
||||
//获取关注人
|
||||
MvcResult editFollowerMvcResult = this.requestGetWithOkAndReturn(FUNCTIONAL_CASE_FOLLOWER_URL + "TEST_FUNCTIONAL_CASE_ID");
|
||||
String editFollowerReturnData = editFollowerMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder editFollowerResultHolder = JSON.parseObject(editFollowerReturnData, ResultHolder.class);
|
||||
Assertions.assertNotNull(editFollowerResultHolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -344,9 +333,10 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
FunctionalCaseBatchMoveRequest request = new FunctionalCaseBatchMoveRequest();
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setModuleId("TEST_MOVE_MODULE_ID");
|
||||
request.setSelectIds(Arrays.asList("TEST"));
|
||||
request.setSelectAll(false);
|
||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
||||
request.setSelectIds(Arrays.asList("TEST"));
|
||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
||||
request.setSelectIds(new ArrayList<>());
|
||||
request.setSelectAll(true);
|
||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package io.metersphere.project.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface ExtProjectVersionMapper {
|
||||
|
||||
String getDefaultVersion(@Param("projectId") String projectId);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.project.mapper.ExtProjectVersionMapper">
|
||||
|
||||
<select id="getDefaultVersion" resultType="java.lang.String">
|
||||
select id from project_version where project_id = #{projectId} and status = 'open' and latest = TRUE LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue