321
This commit is contained in:
parent
66b28bbe72
commit
98dddd684b
|
|
@ -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,18 +76,10 @@ 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.Title = request.Title;
|
||||
}
|
||||
|
||||
// 更新内容
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user