build-flow.api/src/modules/im/Application/Chat/Handlers/DeleteGroupCommandHandler.cs
xiangning 3b13099378 refactor(domain): 重构领域实体结构并更新枚举命名
- 将通用 Entities 命名空间拆分为具体业务实体子目录
- 更新所有实体类型引用为具体的 Entity 后缀类型
- 将 ModelType、ModelProvider、GroupMemberRole 等枚举重命名为 Enum 后缀
- 重构 AiModel 相关配置和映射逻辑适配新的实体结构
- 更新测试代码中的实体类型引用和枚举使用
- 调整应用层处理器中的实体创建和查询逻辑
- 修改 appsettings.json 中的基础设施主机配置为动态占位符模式
2026-07-19 14:02:32 +08:00

29 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BuildFlow.Shared.Domain.Exceptions;
using IM.Application.Chat.Commands;
using IM.Infrastructure.Persistence;
using MediatR;
namespace IM.Application.Chat.Handlers;
/// <summary>
/// 解散群组处理器。仅群主可操作,级联软删群与会话。
/// </summary>
public class DeleteGroupCommandHandler(ImDbContext db) : IRequestHandler<DeleteGroupCommand, Unit>
{
public async Task<Unit> Handle(DeleteGroupCommand request, CancellationToken ct)
{
var group = await db.Groups.FindAsync([request.GroupId], ct)
?? throw new NotFoundException("群组不存在");
// 解散群组是高危操作,仅限群主本人;管理员亦无此权限
if (group.OwnerId != request.OperatorId)
throw new BusinessException("只有群主才能解散群组");
// GroupEntity 配置了软删除(ISoftDelete),Remove 会被 AuditInterceptor 改写为 IsDeleted=true,
// 关联的 ConversationEntity/GroupMemberEntity 因级联策略同步处理
db.Groups.Remove(group);
await db.SaveChangesAsync(ct);
return Unit.Value;
}
}