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

Added GroupManagement. Fixed some errors in RoleManagement.

This commit is contained in:
2023-05-16 00:19:14 +08:00
parent a385938cd7
commit b6649df71f
13 changed files with 552 additions and 55 deletions

View File

@@ -1,7 +1,15 @@
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.Group;
import com.cfive.pinnacle.entity.common.ResponseCode;
import com.cfive.pinnacle.entity.common.ResponseResult;
import com.cfive.pinnacle.service.IGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
@@ -14,5 +22,51 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/group")
public class GroupController {
private IGroupService groupService;
@Autowired
public void setGroupService(IGroupService groupService) {
this.groupService = groupService;
}
@GetMapping
public ResponseResult getAllGroup() {
List<Group> groups = groupService.getAllGroup();
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", groups);
}
@PostMapping
public ResponseResult addGroup(@RequestBody Group group) {
if (!StringUtils.hasText(group.getName())) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Name cannot be empty", null);
}
if (groupService.addGroup(group)) {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
}
}
@DeleteMapping("/{id}")
public ResponseResult deleteGroup(@PathVariable Long id) {
LambdaQueryWrapper<Group> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Group::getId, id);
if (groupService.remove(wrapper)) {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
}
}
@PutMapping
public ResponseResult modifyGroup(@RequestBody Group group) {
if (!StringUtils.hasText(group.getName())) {
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Name cannot be empty", null);
}
if (groupService.modifyGroup(group)) {
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_OK, "success", null);
} else {
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
}
}
}