-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhongbo
committed
Aug 6, 2024
1 parent
b197b8e
commit 89d5740
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
survey-common/src/main/java/com/xiaojusurvey/engine/common/enums/SurveyPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/CollaboratorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
45 changes: 45 additions & 0 deletions
45
survey-server/src/main/java/com/xiaojusurvey/engine/controller/CollaboratorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...y-server/src/test/java/com/xiaojusurvey/engine/controller/CollaboratorControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |