From fcfa12d577668ab7f4f63d474ec3f5e7d3c13829 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 15 May 2023 10:30:34 +0800 Subject: [PATCH] Added backend role name null validation --- .../cfive/pinnacle/controller/RoleController.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Pinnacle/src/main/java/com/cfive/pinnacle/controller/RoleController.java b/Pinnacle/src/main/java/com/cfive/pinnacle/controller/RoleController.java index b701c83..16c3a1d 100644 --- a/Pinnacle/src/main/java/com/cfive/pinnacle/controller/RoleController.java +++ b/Pinnacle/src/main/java/com/cfive/pinnacle/controller/RoleController.java @@ -6,6 +6,7 @@ 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.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -37,10 +38,13 @@ public class RoleController { @PostMapping 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)) { return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null); } 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() 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)) { - return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null); + return ResponseResult.build(ResponseCode.DATABASE_UPDATE_OK, "success", null); } else { - return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null); + return ResponseResult.build(ResponseCode.DATABASE_UPDATE_ERROR, "error", null); } } }