From 5346226da7fbbfadc63ffa5f8ab44bd703cdc72a Mon Sep 17 00:00:00 2001 From: moec42frf <3378620026@qq.com> Date: Sun, 30 Apr 2023 09:20:45 +0800 Subject: [PATCH] ADD file via upload --- .../controller/admin/UserManaController.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 blogserver/src/main/java/org/sang/controller/admin/UserManaController.java diff --git a/blogserver/src/main/java/org/sang/controller/admin/UserManaController.java b/blogserver/src/main/java/org/sang/controller/admin/UserManaController.java new file mode 100644 index 0000000..c07183e --- /dev/null +++ b/blogserver/src/main/java/org/sang/controller/admin/UserManaController.java @@ -0,0 +1,63 @@ +package org.sang.controller.admin; + +import org.sang.bean.RespBean; +import org.sang.bean.Role; +import org.sang.bean.User; +import org.sang.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + + +@RestController +@RequestMapping("/admin") +public class UserManaController { + @Autowired + UserService userService; + + @RequestMapping(value = "/user", method = RequestMethod.GET) + public List getUserByNickname(String nickname) { + return userService.getUserByNickname(nickname); + } + + @RequestMapping(value = "/user/{id}", method = RequestMethod.GET) + public User getUserById(@PathVariable Long id) { + return userService.getUserById(id); + } + + @RequestMapping(value = "/roles", method = RequestMethod.GET) + public List getAllRole() { + return userService.getAllRole(); + } + + @RequestMapping(value = "/user/enabled", method = RequestMethod.PUT) + public RespBean updateUserEnabled(Boolean enabled, Long uid) { + if (userService.updateUserEnabled(enabled, uid) == 1) { + return new RespBean("success", "更新成功!"); + } else { + return new RespBean("error", "更新失败!"); + } + } + + @RequestMapping(value = "/user/{uid}", method = RequestMethod.DELETE) + public RespBean deleteUserById(@PathVariable Long uid) { + if (userService.deleteUserById(uid) == 1) { + return new RespBean("success", "删除成功!"); + } else { + return new RespBean("error", "删除失败!"); + } + } + + @RequestMapping(value = "/user/role", method = RequestMethod.PUT) + public RespBean updateUserRoles(Long[] rids, Long id) { + if (userService.updateUserRoles(rids, id) == rids.length) { + return new RespBean("success", "更新成功!"); + } else { + return new RespBean("error", "更新失败!"); + } + } +}