This commit is contained in:
zpc 2026-02-08 01:43:11 +08:00
parent 66b28bbe72
commit 98dddd684b

View File

@ -15,12 +15,6 @@ public class DanyeService : IDanyeService
private readonly HoneyBoxDbContext _dbContext;
private readonly ILogger<DanyeService> _logger;
/// <summary>
/// 标题不可编辑的ID范围2-20
/// </summary>
private const int TitleEditableMinId = 2;
private const int TitleEditableMaxId = 20;
public DanyeService(
HoneyBoxDbContext dbContext,
ILogger<DanyeService> logger)
@ -62,7 +56,7 @@ public class DanyeService : IDanyeService
Title = danye.Title,
Content = danye.Content,
IsImageOptimizer = danye.IsImageOptimizer == 1,
IsTitleEditable = !IsTitleProtected(danye.Id)
IsTitleEditable = true // 所有单页标题都可编辑
};
}
@ -82,19 +76,11 @@ public class DanyeService : IDanyeService
throw new BusinessException(BusinessErrorCodes.ValidationFailed, "内容不能为空");
}
// 更新标题仅当ID不在2-20范围内且提供了标题时
// 更新标题
if (!string.IsNullOrWhiteSpace(request.Title))
{
if (IsTitleProtected(id))
{
_logger.LogWarning("尝试修改受保护的单页标题: Id={Id}", id);
// 不抛出异常,只是忽略标题更新
}
else
{
danye.Title = request.Title;
}
}
// 更新内容
danye.Content = request.Content;
@ -156,12 +142,6 @@ public class DanyeService : IDanyeService
throw new BusinessException(BusinessErrorCodes.NotFound, "单页不存在");
}
// 系统预设单页ID 2-20不允许删除
if (IsTitleProtected(id))
{
throw new BusinessException(BusinessErrorCodes.ValidationFailed, "系统预设单页不允许删除");
}
_dbContext.Danyes.Remove(danye);
var result = await _dbContext.SaveChangesAsync() > 0;
@ -172,14 +152,6 @@ public class DanyeService : IDanyeService
#region Private Helper Methods
/// <summary>
/// 判断标题是否受保护ID 2-20 的单页标题不可编辑)
/// </summary>
private static bool IsTitleProtected(int id)
{
return id >= TitleEditableMinId && id <= TitleEditableMaxId;
}
/// <summary>
/// Unix时间戳转DateTime
/// </summary>