1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-05 06:51:23 +08:00

Added UserManagement

This commit is contained in:
2023-05-17 15:39:28 +08:00
parent e1bdb21756
commit e5a3cb83be
13 changed files with 656 additions and 58 deletions

View File

@@ -1,14 +1,13 @@
package com.cfive.pinnacle.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cfive.pinnacle.entity.User;
import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -32,13 +31,54 @@ public class UserController {
@GetMapping
public ResponseResult getAllUser() {
List<User> users = userService.getBasicInfo();
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", users);
List<User> users = userService.getAllUser();
return ResponseResult.databaseSelectSuccess(users);
}
@GetMapping("/{id}")
public ResponseResult getUser(@PathVariable int id) {
User user = userService.getBasicInfo(id);
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", user);
public ResponseResult getUser(@PathVariable Long id) {
User user = userService.getUser(id);
return ResponseResult.databaseSelectSuccess(user);
}
@PostMapping
public ResponseResult addUser(@RequestBody User user) {
if (!StringUtils.hasText(user.getUsername())) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Username cannot be empty", null);
}
if (!StringUtils.hasText(user.getPasswd())) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Password cannot be empty", null);
}
if (userService.addUser(user)) {
return ResponseResult.databaseSaveSuccess(user);
} else {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
}
}
@DeleteMapping("/{id}")
public ResponseResult deleteRole(@PathVariable Long id) {
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getId, id);
if (userService.remove(wrapper)) {
return ResponseResult.databaseDeleteSuccess();
} else {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
}
}
@PutMapping()
public ResponseResult modifyRole(@RequestBody User user) {
if (!StringUtils.hasText(user.getUsername())) {
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Username cannot be empty", null);
}
if (!StringUtils.hasText(user.getPasswd())) {
user.setPasswd(null);
}
if (userService.modifyUser(user)) {
return ResponseResult.databaseUpdateSuccess(user);
} else {
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
}
}
}