fix: 优化工作人员重复信息提示
This commit is contained in:
@@ -205,7 +205,15 @@ func GetByIdentity[T any](ctx *gin.Context) {
|
||||
infra.Response.Success(ctx, ProtectPreciseLocation(ctx, new(T), response))
|
||||
}
|
||||
|
||||
// UpdateAllowedByIdentity 按白名单更新资源,并保持原有数据库错误响应行为。
|
||||
func UpdateAllowedByIdentity(ctx *gin.Context, model any, values map[string]any, allowedFields []string) {
|
||||
UpdateAllowedByIdentityWithError(ctx, model, values, allowedFields, nil)
|
||||
}
|
||||
|
||||
// UpdateAllowedByIdentityWithError 按白名单更新资源,并允许调用方转换数据库写入错误。
|
||||
// 参数:transformError 为空时保持原有错误响应,非空时仅转换数据库更新错误。
|
||||
// 返回值:无,处理结果通过统一 HTTP 响应写入。
|
||||
func UpdateAllowedByIdentityWithError(ctx *gin.Context, model any, values map[string]any, allowedFields []string, transformError func(error) error) {
|
||||
values = FilterFields(values, allowedFields)
|
||||
if len(values) == 0 {
|
||||
infra.Response.Success(ctx, gin.H{"updated": false})
|
||||
@@ -214,6 +222,9 @@ func UpdateAllowedByIdentity(ctx *gin.Context, model any, values map[string]any,
|
||||
|
||||
result := ActiveRecords(impl.DBService.Model(model)).Where("identity = ?", ctx.Param("identity")).Updates(values)
|
||||
if result.Error != nil {
|
||||
if transformError != nil {
|
||||
result.Error = transformError(result.Error)
|
||||
}
|
||||
infra.Response.Error(ctx, result.Error)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user