| | |
| | | package com.dji.sample.manage.controller; |
| | | |
| | | import com.dji.sample.common.model.CustomClaim; |
| | | import com.dji.sample.common.model.PaginationData; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.manage.model.dto.UserListDTO; |
| | | import com.dji.sample.manage.service.IUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | @Autowired |
| | | private IUserService userService; |
| | | |
| | | /** |
| | | * Query the information of the current user. |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @GetMapping("/current") |
| | | public ResponseResult getCurrentUserInfo(HttpServletRequest request) { |
| | | CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM); |
| | | return userService.getUserByUsername(customClaim.getUsername(), customClaim.getWorkspaceId()); |
| | | } |
| | | |
| | | /** |
| | | * Paging to query all users in a workspace. |
| | | * @param page current page |
| | | * @param pageSize |
| | | * @param workspaceId |
| | | * @return |
| | | */ |
| | | @GetMapping("/{workspace_id}/users") |
| | | public ResponseResult<PaginationData<UserListDTO>> getUsers(@RequestParam(defaultValue = "1") Long page, |
| | | @RequestParam(value = "page_size", defaultValue = "50") Long pageSize, |
| | | @PathVariable("workspace_id") String workspaceId) { |
| | | PaginationData<UserListDTO> paginationData = userService.getUsersByWorkspaceId(page, pageSize, workspaceId); |
| | | return ResponseResult.success(paginationData); |
| | | } |
| | | |
| | | /** |
| | | * Modify user information. Only mqtt account information is included, nothing else can be modified. |
| | | * @param user |
| | | * @param workspaceId |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @PutMapping("/{workspace_id}/users/{user_id}") |
| | | public ResponseResult updateUser(@RequestBody UserListDTO user, |
| | | @PathVariable("workspace_id") String workspaceId, |
| | | @PathVariable("user_id") String userId) { |
| | | |
| | | userService.updateUser(workspaceId, userId, user); |
| | | return ResponseResult.success(); |
| | | } |
| | | } |