1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-04 22:41:24 +08:00

Added role management

This commit is contained in:
2023-05-15 08:32:16 +08:00
parent e491e21f88
commit 292ea5dad6
33 changed files with 752 additions and 55 deletions

View File

@@ -1,7 +1,14 @@
package com.cfive.pinnacle.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cfive.pinnacle.entity.Role;
import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
@@ -15,4 +22,45 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/role")
public class RoleController {
private IRoleService roleService;
@Autowired
public void setRoleService(IRoleService roleService) {
this.roleService = roleService;
}
@GetMapping
public ResponseResult getAllRole() {
List<Role> roles = roleService.getAllRole();
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", roles);
}
@PostMapping
public ResponseResult addRole(@RequestBody Role role) {
if (roleService.addRole(role)) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
}
}
@DeleteMapping("/{id}")
public ResponseResult deleteRole(@PathVariable Long id) {
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Role::getId, id);
if (roleService.remove(wrapper)) {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
}
}
@PutMapping()
public ResponseResult modifyRole(@RequestBody Role role) {
if (roleService.modifyRole(role)) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
}
}
}