refactor: 优化提交字段校验

This commit is contained in:
wintel
2025-05-11 00:22:54 +08:00
parent 9b78b9e6c7
commit eddb32c6b6

View File

@@ -100,7 +100,7 @@ namespace OpenAuth.App
return result;
}
public string Add(AddOrUpdateBuilderTableReq req)
public void Check(AddOrUpdateBuilderTableReq req)
{
if (string.IsNullOrEmpty(req.TableName))
{
@@ -112,11 +112,18 @@ namespace OpenAuth.App
throw new Exception("模块名称不能为空");
}
if (string.IsNullOrEmpty(req.Namespace))
if(!string.IsNullOrEmpty(req.ParentTableId))
{
throw new Exception("命名空间不能为空");
if(string.IsNullOrEmpty(req.ForeignKey))
{
throw new Exception("当前表为子表时,外键不能为空");
}
}
}
public string Add(AddOrUpdateBuilderTableReq req)
{
Check(req);
var obj = AddTableAndColumns(req.MapTo<BuilderTable>());
UnitWork.Save();
@@ -176,6 +183,7 @@ namespace OpenAuth.App
public void Update(AddOrUpdateBuilderTableReq obj)
{
Check(obj);
var user = _auth.GetCurrentUser().User;
UnitWork.Update<BuilderTable>(u => u.Id == obj.Id, u => new BuilderTable
{