Explorar o código

fix: 补充createChild必填字段校验

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
User hai 5 meses
pai
achega
ea60587825

+ 8 - 1
zxyj-backend/src/main/java/com/zxyj/service/UserService.java

@@ -621,10 +621,17 @@ private WechatService wechatService;
             return null;
         }
 
+        if (dto.getNickname() == null || dto.getNickname().trim().isEmpty()) {
+            throw new IllegalArgumentException("孩子昵称不能为空");
+        }
+        if (dto.getAge() == null || dto.getAge() < 1 || dto.getAge() > 18) {
+            throw new IllegalArgumentException("请输入有效的年龄(1-18岁)");
+        }
+
         Child child = new Child();
         child.setUserId(userId);
         child.setFamilyId(user.getFamilyId());
-        child.setNickname(dto.getNickname());
+        child.setNickname(dto.getNickname().trim());
         child.setAge(dto.getAge());
         child.setBirthday(dto.getBirthday());
         child.setGender(dto.getGender());