86941f311e4b3a66c49589525c41608d34b1e337
[institute/sw-backend.git] /
1 package com.supwisdom.institute.backend.admin.bff.api.v1.controller.open;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.util.MimeTypeUtils;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RequestMethod;
10 import org.springframework.web.bind.annotation.RequestParam;
11 import org.springframework.web.bind.annotation.RestController;
12
13 import com.supwisdom.institute.backend.admin.bff.api.v1.model.base.Role;
14 import com.supwisdom.institute.backend.admin.bff.api.v1.model.open.SyncRoleModel;
15 import com.supwisdom.institute.backend.admin.bff.api.v1.service.base.AuthnService;
16 import com.supwisdom.institute.backend.admin.bff.api.v1.vo.open.response.data.OpenSyncRolesResponseData;
17 import com.supwisdom.institute.backend.common.framework.vo.response.DefaultApiResponse;
18
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.ApiOperation;
21
22 @Api(value = "BFFOpen", tags = { "open" }, description = "公开接口")
23 @RestController
24 @RequestMapping(value = "/api/v1/open/sync")
25 public class OpenSyncController {
26
27   @Autowired
28   private AuthnService authnService;
29
30   @ApiOperation(
31       tags = { "open" },
32       value = "获取角色", notes = "获取角色", nickname = "openRoles"
33   )
34   @RequestMapping(method = RequestMethod.GET, path = "/roles", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
35   public DefaultApiResponse<OpenSyncRolesResponseData> roles(
36       @RequestParam(name = "applicationId", required = true) String applicationId) {
37     
38     List<SyncRoleModel> syncRoleModels = new ArrayList<>();
39
40     List<Role> systemRoles = authnService.roles();
41     for (Role systemRole : systemRoles) {
42       SyncRoleModel syncRoleModel = new SyncRoleModel(
43           systemRole.getId(), 
44           systemRole.getCode(),
45           systemRole.getName(),
46           systemRole.getMemo());
47       syncRoleModels.add(syncRoleModel);
48     }
49     
50     OpenSyncRolesResponseData data = OpenSyncRolesResponseData.of(applicationId, syncRoleModels);
51     return new DefaultApiResponse<OpenSyncRolesResponseData>(data);
52   }
53   
54
55 }