feat(缺陷管理): 缺陷关注功能

This commit is contained in:
song-cc-rock 2023-11-07 18:33:23 +08:00 committed by 刘瑞斌
parent 4eac5632f7
commit 2a7d4a38e5
4 changed files with 78 additions and 17 deletions

View File

@ -102,4 +102,18 @@ public class BugController {
public void batchUpdate(@Validated @RequestBody BugBatchUpdateRequest request) { public void batchUpdate(@Validated @RequestBody BugBatchUpdateRequest request) {
bugService.batchUpdate(request); bugService.batchUpdate(request);
} }
@GetMapping("/follow/{id}")
@Operation(summary = "缺陷管理-关注缺陷")
@RequiresPermissions(PermissionConstants.BUG_UPDATE)
public void follow(@PathVariable String id) {
bugService.follow(id, SessionUtils.getUserId());
}
@GetMapping("/unfollow/{id}")
@Operation(summary = "缺陷管理-取消关注缺陷")
@RequiresPermissions(PermissionConstants.BUG_UPDATE)
public void unfollow(@PathVariable String id) {
bugService.unfollow(id, SessionUtils.getUserId());
}
} }

View File

@ -87,6 +87,8 @@ public class BugService {
private FileService fileService; private FileService fileService;
@Resource @Resource
private BaseTemplateService baseTemplateService; private BaseTemplateService baseTemplateService;
@Resource
private BugFollowerMapper bugFollowerMapper;
/** /**
* 缺陷列表查询 * 缺陷列表查询
@ -314,6 +316,31 @@ public class BugService {
} }
} }
/**
* 关注缺陷
* @param id 缺陷ID
* @param currentUser 当前用户
*/
public void follow(String id, String currentUser) {
checkBugExist(id);
BugFollower bugFollower = new BugFollower();
bugFollower.setBugId(id);
bugFollower.setUserId(currentUser);
bugFollowerMapper.insert(bugFollower);
}
/**
* 取消关注缺陷
* @param id 缺陷ID
* @param currentUser 当前用户
*/
public void unfollow(String id, String currentUser) {
checkBugExist(id);
BugFollowerExample example = new BugFollowerExample();
example.createCriteria().andBugIdEqualTo(id).andUserIdEqualTo(currentUser);
bugFollowerMapper.deleteByExample(example);
}
/** /**
* 处理保存缺陷基础信息 * 处理保存缺陷基础信息
* *

View File

@ -2,7 +2,7 @@
{ {
"id": "BUG", "id": "BUG",
"name": "permission.bug.name", "name": "permission.bug.name",
"type": "BUG", "type": "PROJECT",
"children": [ "children": [
{ {
"id": "BUG", "id": "BUG",

View File

@ -41,11 +41,13 @@ public class BugControllerTests extends BaseTest {
public static final String BUG_TEMPLATE_DETAIL = "/bug/template"; public static final String BUG_TEMPLATE_DETAIL = "/bug/template";
public static final String BUG_BATCH_DELETE = "/bug/batch-delete"; public static final String BUG_BATCH_DELETE = "/bug/batch-delete";
public static final String BUG_BATCH_UPDATE = "/bug/batch-update"; public static final String BUG_BATCH_UPDATE = "/bug/batch-update";
public static final String BUG_FOLLOW = "/bug/follow";
public static final String BUG_UN_FOLLOW = "/bug/unfollow";
@Test @Test
@Order(0) @Order(0)
@Sql(scripts = {"/dml/init_bug.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @Sql(scripts = {"/dml/init_bug.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void testBugPageSuccess() throws Exception { void testBugPageSuccess() throws Exception {
BugPageRequest bugRequest = new BugPageRequest(); BugPageRequest bugRequest = new BugPageRequest();
bugRequest.setCurrent(1); bugRequest.setCurrent(1);
bugRequest.setPageSize(10); bugRequest.setPageSize(10);
@ -86,7 +88,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(1) @Order(1)
public void testBugPageEmptySuccess() throws Exception { void testBugPageEmptySuccess() throws Exception {
BugPageRequest bugPageRequest = new BugPageRequest(); BugPageRequest bugPageRequest = new BugPageRequest();
bugPageRequest.setCurrent(1); bugPageRequest.setCurrent(1);
bugPageRequest.setPageSize(10); bugPageRequest.setPageSize(10);
@ -157,7 +159,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(2) @Order(2)
public void testBugPageError() throws Exception { void testBugPageError() throws Exception {
// 页码有误 // 页码有误
BugPageRequest bugPageRequest = new BugPageRequest(); BugPageRequest bugPageRequest = new BugPageRequest();
bugPageRequest.setCurrent(0); bugPageRequest.setCurrent(0);
@ -172,7 +174,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
public void testAddBugSuccess() throws Exception { void testAddBugSuccess() throws Exception {
BugEditRequest request = buildRequest(false); BugEditRequest request = buildRequest(false);
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath();
File file = new File(filePath); File file = new File(filePath);
@ -182,7 +184,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(4) @Order(4)
public void testAddBugError() throws Exception { void testAddBugError() throws Exception {
BugEditRequest request = buildRequest(false); BugEditRequest request = buildRequest(false);
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath();
File file = new File(filePath); File file = new File(filePath);
@ -214,7 +216,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(5) @Order(5)
public void testUpdateBugSuccess() throws Exception { void testUpdateBugSuccess() throws Exception {
BugEditRequest request = buildRequest(true); BugEditRequest request = buildRequest(true);
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath();
File file = new File(filePath); File file = new File(filePath);
@ -229,7 +231,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(6) @Order(6)
public void testUpdateBugError() throws Exception { void testUpdateBugError() throws Exception {
BugEditRequest request = buildRequest(true); BugEditRequest request = buildRequest(true);
request.setId("default-bug-id-not-exist"); request.setId("default-bug-id-not-exist");
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath();
@ -240,7 +242,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(7) @Order(7)
public void testUpdateBugWithEmptyField() throws Exception { void testUpdateBugWithEmptyField() throws Exception {
BugEditRequest request = buildRequest(true); BugEditRequest request = buildRequest(true);
request.setCustomFieldMap(null); request.setCustomFieldMap(null);
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath();
@ -251,7 +253,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(8) @Order(8)
public void testGetBugTemplateOption() throws Exception { void testGetBugTemplateOption() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(BUG_TEMPLATE_OPTION + "?projectId=default-project-for-bug"); MvcResult mvcResult = this.requestGetWithOkAndReturn(BUG_TEMPLATE_OPTION + "?projectId=default-project-for-bug");
String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(sortData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(sortData, ResultHolder.class);
@ -262,7 +264,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(9) @Order(9)
public void testGetBugTemplateDetailSuccess() throws Exception { void testGetBugTemplateDetailSuccess() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(BUG_TEMPLATE_DETAIL + "/default-bug-template-id" + "?projectId=default-project-for-bug"); MvcResult mvcResult = this.requestGetWithOkAndReturn(BUG_TEMPLATE_DETAIL + "/default-bug-template-id" + "?projectId=default-project-for-bug");
String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String sortData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(sortData, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(sortData, ResultHolder.class);
@ -280,7 +282,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(10) @Order(10)
public void testBatchUpdateBugSuccess() throws Exception { void testBatchUpdateBugSuccess() throws Exception {
BugBatchUpdateRequest request = new BugBatchUpdateRequest(); BugBatchUpdateRequest request = new BugBatchUpdateRequest();
request.setProjectId("default-project-for-bug"); request.setProjectId("default-project-for-bug");
// 全选, 编辑所有数据 // 全选, 编辑所有数据
@ -318,7 +320,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(11) @Order(11)
public void testBatchUpdateEmptyBugSuccess() throws Exception { void testBatchUpdateEmptyBugSuccess() throws Exception {
BugBatchUpdateRequest request = new BugBatchUpdateRequest(); BugBatchUpdateRequest request = new BugBatchUpdateRequest();
request.setProjectId("default-project-for-bug"); request.setProjectId("default-project-for-bug");
request.setCombine(buildRequestCombine()); request.setCombine(buildRequestCombine());
@ -337,7 +339,7 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(12) @Order(12)
public void testDeleteBugSuccess() throws Exception { void testDeleteBugSuccess() throws Exception {
this.requestGet(BUG_DELETE + "/default-bug-id", status().isOk()); this.requestGet(BUG_DELETE + "/default-bug-id", status().isOk());
// 非Local缺陷 // 非Local缺陷
this.requestGet(BUG_DELETE + "/default-bug-id-tapd1", status().isOk()); this.requestGet(BUG_DELETE + "/default-bug-id-tapd1", status().isOk());
@ -345,13 +347,13 @@ public class BugControllerTests extends BaseTest {
@Test @Test
@Order(13) @Order(13)
public void testDeleteBugError() throws Exception { void testDeleteBugError() throws Exception {
this.requestGet(BUG_DELETE + "/default-bug-id-not-exist", status().is5xxServerError()); this.requestGet(BUG_DELETE + "/default-bug-id-not-exist", status().is5xxServerError());
} }
@Test @Test
@Order(14) @Order(14)
public void testBatchDeleteEmptyBugSuccess() throws Exception { void testBatchDeleteEmptyBugSuccess() throws Exception {
BugBatchRequest request = new BugBatchRequest(); BugBatchRequest request = new BugBatchRequest();
request.setProjectId("default-project-for-bug"); request.setProjectId("default-project-for-bug");
request.setCombine(buildRequestCombine()); request.setCombine(buildRequestCombine());
@ -363,9 +365,27 @@ public class BugControllerTests extends BaseTest {
this.requestPost(BUG_BATCH_DELETE, request, status().is5xxServerError()); this.requestPost(BUG_BATCH_DELETE, request, status().is5xxServerError());
} }
@Test
@Order(15)
void testFollowBug() throws Exception {
// 关注的缺陷存在
this.requestGet(BUG_FOLLOW + "/default-bug-id-single", status().isOk());
// 关注的缺陷不存在
this.requestGet(BUG_FOLLOW + "/default-bug-id-not-exist", status().is5xxServerError());
}
@Test
@Order(16)
void testUnFollowBug() throws Exception {
// 取消关注的缺陷存在
this.requestGet(BUG_UN_FOLLOW + "/default-bug-id-single", status().isOk());
// 取消关注的缺陷不存在
this.requestGet(BUG_UN_FOLLOW + "/default-bug-id-not-exist", status().is5xxServerError());
}
@Test @Test
@Order(20) @Order(20)
public void testBatchDeleteBugSuccess() throws Exception { void testBatchDeleteBugSuccess() throws Exception {
BugBatchRequest request = new BugBatchRequest(); BugBatchRequest request = new BugBatchRequest();
request.setProjectId("default-project-for-bug"); request.setProjectId("default-project-for-bug");
// 全选, 删除所有 // 全选, 删除所有