|
@@ -7,6 +7,7 @@ import jakarta.validation.constraints.NotBlank;
|
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
|
import jakarta.validation.constraints.NotNull;
|
|
import jakarta.validation.constraints.NotNull;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import space.anyi.serve.entity.PageVo;
|
|
import space.anyi.serve.entity.PageVo;
|
|
|
import space.anyi.serve.entity.Response;
|
|
import space.anyi.serve.entity.Response;
|
|
@@ -42,6 +43,7 @@ public class UserController {
|
|
|
* @param pageSize
|
|
* @param pageSize
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@GetMapping
|
|
@GetMapping
|
|
|
public Response<PageVo<List<UserVo>>> queryByPage(
|
|
public Response<PageVo<List<UserVo>>> queryByPage(
|
|
|
@NotNull @RequestParam(defaultValue = "") String account,
|
|
@NotNull @RequestParam(defaultValue = "") String account,
|
|
@@ -65,6 +67,7 @@ public class UserController {
|
|
|
* @param id 主键
|
|
* @param id 主键
|
|
|
* @return 单条数据
|
|
* @return 单条数据
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasAnyRole('ROLE_admin', 'ROLE_user')")
|
|
|
@GetMapping("{id}")
|
|
@GetMapping("{id}")
|
|
|
public Response<UserVo> queryById(@NotBlank(message = "用户ID不能为空") @PathVariable String id) {
|
|
public Response<UserVo> queryById(@NotBlank(message = "用户ID不能为空") @PathVariable String id) {
|
|
|
User user = this.userService.queryById(Long.valueOf(id));
|
|
User user = this.userService.queryById(Long.valueOf(id));
|
|
@@ -77,6 +80,7 @@ public class UserController {
|
|
|
* @param userDto 实体
|
|
* @param userDto 实体
|
|
|
* @return 新增结果
|
|
* @return 新增结果
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@PostMapping
|
|
@PostMapping
|
|
|
public Response<Boolean> add(@Valid@RequestBody UserDto userDto) {
|
|
public Response<Boolean> add(@Valid@RequestBody UserDto userDto) {
|
|
|
User user = new User();
|
|
User user = new User();
|
|
@@ -90,6 +94,7 @@ public class UserController {
|
|
|
* @param userDto 实体
|
|
* @param userDto 实体
|
|
|
* @return 编辑结果
|
|
* @return 编辑结果
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@PutMapping
|
|
@PutMapping
|
|
|
public Response<Boolean> edit(@Valid@RequestBody UserDto userDto) {
|
|
public Response<Boolean> edit(@Valid@RequestBody UserDto userDto) {
|
|
|
User user = new User();
|
|
User user = new User();
|
|
@@ -104,6 +109,7 @@ public class UserController {
|
|
|
* @param ids 主键
|
|
* @param ids 主键
|
|
|
* @return 删除是否成功
|
|
* @return 删除是否成功
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@DeleteMapping
|
|
@DeleteMapping
|
|
|
public Response<Boolean> deleteById(@NotEmpty(message = "ID列表不能为空") @RequestParam List<String> ids) {
|
|
public Response<Boolean> deleteById(@NotEmpty(message = "ID列表不能为空") @RequestParam List<String> ids) {
|
|
|
List<Long> list = ids.stream().map(Long::valueOf).toList();
|
|
List<Long> list = ids.stream().map(Long::valueOf).toList();
|
|
@@ -115,6 +121,7 @@ public class UserController {
|
|
|
* @param dto
|
|
* @param dto
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@PutMapping("/updateStatus")
|
|
@PutMapping("/updateStatus")
|
|
|
public Response updateUserStatus(@Valid@RequestBody UpdateUserStatusDto dto){
|
|
public Response updateUserStatus(@Valid@RequestBody UpdateUserStatusDto dto){
|
|
|
User user = new User();
|
|
User user = new User();
|
|
@@ -128,6 +135,7 @@ public class UserController {
|
|
|
* @param dto
|
|
* @param dto
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasAnyRole('ROLE_admin', 'ROLE_user')")
|
|
|
@PutMapping("/updateAvatar")
|
|
@PutMapping("/updateAvatar")
|
|
|
public Response updateUserAvatar(@Valid@RequestBody UpdateUserAvatarDto dto){
|
|
public Response updateUserAvatar(@Valid@RequestBody UpdateUserAvatarDto dto){
|
|
|
User user = new User();
|
|
User user = new User();
|
|
@@ -141,6 +149,7 @@ public class UserController {
|
|
|
* @param dto
|
|
* @param dto
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @PreAuthorize("hasAnyRole('ROLE_admin', 'ROLE_user')")
|
|
|
@PutMapping("/updatePassword")
|
|
@PutMapping("/updatePassword")
|
|
|
public Response updatePassword(@Valid @RequestBody UpdateUserPasswordDto dto){
|
|
public Response updatePassword(@Valid @RequestBody UpdateUserPasswordDto dto){
|
|
|
User user = new User();
|
|
User user = new User();
|