mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-04 22:41:24 +08:00
Added backend role name null validation
This commit is contained in:
@@ -6,6 +6,7 @@ import com.cfive.pinnacle.entity.common.ResponseCode;
|
|||||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||||
import com.cfive.pinnacle.service.IRoleService;
|
import com.cfive.pinnacle.service.IRoleService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,10 +38,13 @@ public class RoleController {
|
|||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseResult addRole(@RequestBody Role role) {
|
public ResponseResult addRole(@RequestBody Role role) {
|
||||||
|
if (!StringUtils.hasText(role.getName())) {
|
||||||
|
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "Name cannot be empty", null);
|
||||||
|
}
|
||||||
if (roleService.addRole(role)) {
|
if (roleService.addRole(role)) {
|
||||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
|
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
|
||||||
} else {
|
} else {
|
||||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
return ResponseResult.build(ResponseCode.DATABASE_SAVE_ERROR, "error", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,10 +61,13 @@ public class RoleController {
|
|||||||
|
|
||||||
@PutMapping()
|
@PutMapping()
|
||||||
public ResponseResult modifyRole(@RequestBody Role role) {
|
public ResponseResult modifyRole(@RequestBody Role role) {
|
||||||
|
if (!StringUtils.hasText(role.getName())) {
|
||||||
|
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "Name cannot be empty", null);
|
||||||
|
}
|
||||||
if (roleService.modifyRole(role)) {
|
if (roleService.modifyRole(role)) {
|
||||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
|
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_OK, "success", null);
|
||||||
} else {
|
} else {
|
||||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user