Skip to content

Commit

Permalink
[Feature]:新增获取权限列表接口及单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongbo committed Aug 6, 2024
1 parent b197b8e commit 89d5740
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xiaojusurvey.engine.common.enums;

import lombok.Getter;

/**
* @author zhongbo
*/

@Getter
public enum SurveyPermission {
SURVEY_CONF_MANAGE("SURVEY_CONF_MANAGE"),
SURVEY_RESPONSE_MANAGE("SURVEY_RESPONSE_MANAGE"),
SURVEY_COOPERATION_MANAGE("SURVEY_COOPERATION_MANAGE");

private final String permissionDescription;

SurveyPermission(String permissionDescription) {
this.permissionDescription = permissionDescription;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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.SurveyPermission;
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", SurveyPermission.SURVEY_CONF_MANAGE);

JSONObject surveyResManage = new JSONObject();
surveyResManage.put("name", "问卷分析管理");
surveyResManage.put("value", SurveyPermission.SURVEY_RESPONSE_MANAGE);

JSONObject surveyCoManage = new JSONObject();
surveyCoManage.put("name", "协作者管理");
surveyCoManage.put("value", SurveyPermission.SURVEY_COOPERATION_MANAGE);

jsonArray.add(surveyConfManage);
jsonArray.add(surveyResManage);
jsonArray.add(surveyCoManage);

return RpcResultUtil.createSuccessResult(jsonArray);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 89d5740

Please sign in to comment.