[Feature]:新增获取权限列表接口及单元测试 (#387)

Co-authored-by: zhongbo <zb123456789>
This commit is contained in:
SingerDracula 2024-08-07 13:20:48 +08:00 committed by GitHub
parent a6ff240369
commit 58bf3e38b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package com.xiaojusurvey.engine.common.enums;
import lombok.Getter;
/**
* @author zhongbo
*/
@Getter
public enum SurveyPermissionEnum {
SURVEY_CONF_MANAGE("SURVEY_CONF_MANAGE"),
SURVEY_RESPONSE_MANAGE("SURVEY_RESPONSE_MANAGE"),
SURVEY_COOPERATION_MANAGE("SURVEY_COOPERATION_MANAGE");
private final String permissionDescription;
SurveyPermissionEnum(String permissionDescription) {
this.permissionDescription = permissionDescription;
}
}

View File

@ -0,0 +1,8 @@
package com.xiaojusurvey.engine.core.survey;
import com.xiaojusurvey.engine.common.entity.survey.SurveyMeta;
import com.xiaojusurvey.engine.core.reslut.IdResult;
public interface CollaboratorService {
IdResult createSurvey(SurveyMeta surveyMeta);
}

View File

@ -0,0 +1,45 @@
package com.xiaojusurvey.engine.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaojusurvey.engine.common.enums.SurveyPermissionEnum;
import com.xiaojusurvey.engine.common.rpc.RpcResult;
import com.xiaojusurvey.engine.common.util.RpcResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author zhongbo
*/
@RequestMapping("/api/collaborator")
@RestController
@Slf4j
public class CollaboratorController {
/**
* 获取权限列表
*/
@GetMapping("/getPermissionList")
public RpcResult<JSONArray> getPermissionList() {
JSONArray jsonArray = new JSONArray();
JSONObject surveyConfManage = new JSONObject();
surveyConfManage.put("name", "问卷配置管理");
surveyConfManage.put("value", SurveyPermissionEnum.SURVEY_CONF_MANAGE);
JSONObject surveyResManage = new JSONObject();
surveyResManage.put("name", "问卷分析管理");
surveyResManage.put("value", SurveyPermissionEnum.SURVEY_RESPONSE_MANAGE);
JSONObject surveyCoManage = new JSONObject();
surveyCoManage.put("name", "协作者管理");
surveyCoManage.put("value", SurveyPermissionEnum.SURVEY_COOPERATION_MANAGE);
jsonArray.add(surveyConfManage);
jsonArray.add(surveyResManage);
jsonArray.add(surveyCoManage);
return RpcResultUtil.createSuccessResult(jsonArray);
}
}

View File

@ -0,0 +1,38 @@
package com.xiaojusurvey.engine.controller;
import com.alibaba.fastjson.JSONArray;
import com.xiaojusurvey.engine.common.entity.user.User;
import com.xiaojusurvey.engine.common.rpc.RpcResult;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.servlet.http.HttpServletRequest;
@RunWith(SpringJUnit4ClassRunner.class)
public class CollaboratorControllerTest {
@InjectMocks
CollaboratorController collaboratorController;
private HttpServletRequest httpServletRequest;
@Before
public void initBean() {
httpServletRequest = new MockHttpServletRequest();
User user = new User();
user.setId("123");
user.setUsername("maple");
httpServletRequest.setAttribute("user", user);
}
@Test
public void getPermissionList() {
RpcResult<JSONArray> permissionListResult = collaboratorController.getPermissionList();
Assert.assertTrue(permissionListResult.getSuccess());
Assert.assertEquals(new Integer(200), permissionListResult.getCode());
}
}