Files
Yi.Admin/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/ForumManager.cs

78 lines
3.3 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Domain.Services;
2024-01-11 18:51:53 +08:00
using Yi.Framework.Bbs.Domain.Entities.Forum;
2023-12-30 02:42:12 +08:00
using Yi.Framework.Bbs.Domain.Managers.ArticleImport;
using Yi.Framework.Bbs.Domain.Shared.Enums;
using Yi.Framework.Bbs.Domain.Shared.Model;
2023-12-11 09:55:12 +08:00
using Yi.Framework.SqlSugarCore.Abstractions;
2023-04-15 22:44:33 +08:00
2023-12-11 09:55:12 +08:00
namespace Yi.Framework.Bbs.Domain.Managers
2023-04-15 22:44:33 +08:00
{
/// <summary>
/// 论坛模块的领域服务
/// </summary>
2023-12-11 09:55:12 +08:00
public class ForumManager : DomainService
2023-04-15 22:44:33 +08:00
{
2024-05-22 14:35:08 +08:00
public readonly ISqlSugarRepository<DiscussAggregateRoot, Guid> _discussRepository;
public readonly ISqlSugarRepository<PlateAggregateRoot, Guid> _plateEntityRepository;
public readonly ISqlSugarRepository<CommentAggregateRoot, Guid> _commentRepository;
public readonly ISqlSugarRepository<ArticleAggregateRoot, Guid> _articleRepository;
public ForumManager(ISqlSugarRepository<DiscussAggregateRoot, Guid> discussRepository, ISqlSugarRepository<PlateAggregateRoot, Guid> plateEntityRepository, ISqlSugarRepository<CommentAggregateRoot, Guid> commentRepository, ISqlSugarRepository<ArticleAggregateRoot, Guid> articleRepository)
2023-04-15 22:44:33 +08:00
{
_discussRepository = discussRepository;
_plateEntityRepository = plateEntityRepository;
_commentRepository = commentRepository;
2023-12-30 02:42:12 +08:00
_articleRepository = articleRepository;
2023-04-15 22:44:33 +08:00
}
//主题是不能直接创建的,需要由领域服务统一创建
2024-05-22 14:35:08 +08:00
public async Task<DiscussAggregateRoot> CreateDiscussAsync(DiscussAggregateRoot entity)
2023-04-15 22:44:33 +08:00
{
entity.CreationTime = DateTime.Now;
entity.AgreeNum = 0;
entity.SeeNum = 0;
return await _discussRepository.InsertReturnEntityAsync(entity);
}
2024-05-22 14:35:08 +08:00
public async Task<CommentAggregateRoot> CreateCommentAsync(Guid discussId, Guid parentId, Guid rootId, string content)
2023-04-15 22:44:33 +08:00
{
2024-05-22 14:35:08 +08:00
var entity = new CommentAggregateRoot(discussId);
2023-04-15 22:44:33 +08:00
entity.Content = content;
entity.ParentId = parentId;
entity.RootId = rootId;
return await _commentRepository.InsertReturnEntityAsync(entity);
}
/// <summary>
/// 导入文章
/// </summary>
/// <param name="discussId"></param>
/// <param name="articleParentId"></param>
/// <param name="fileObjs"></param>
/// <param name="importType"></param>
/// <returns></returns>
public async Task PostImportAsync(Guid discussId,Guid articleParentId, List<FileObject> fileObjs, ArticleImportTypeEnum importType)
{
2023-12-30 02:42:12 +08:00
AbstractArticleImport abstractArticleImport = default;
switch (importType)
{
2024-01-05 09:46:29 +08:00
case ArticleImportTypeEnum.Default:
2023-12-30 02:42:12 +08:00
abstractArticleImport = new DefaultArticleImport();
break;
case ArticleImportTypeEnum.VuePress:
abstractArticleImport = new VuePressArticleImport();
break;
default: abstractArticleImport = new DefaultArticleImport(); break;
}
2024-01-05 09:44:34 +08:00
abstractArticleImport.SetLogger(LoggerFactory);
var articleHandled = abstractArticleImport.Import(discussId, articleParentId, fileObjs);
2023-12-30 02:42:12 +08:00
2024-01-04 10:42:20 +08:00
await _articleRepository.InsertManyAsync(articleHandled);
2023-12-30 02:42:12 +08:00
}
2023-04-15 22:44:33 +08:00
}
}