feat:全基础流程跑通
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Helper;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Domain
|
||||
{
|
||||
/// <summary>
|
||||
/// 论坛模块的领域服务
|
||||
/// </summary>
|
||||
public class ForumManager:ITransient
|
||||
{
|
||||
private readonly IRepository<DiscussEntity> _discussRepository;
|
||||
private readonly IRepository<PlateEntity> _plateEntityRepository;
|
||||
private readonly IRepository<CommentEntity> _commentRepository;
|
||||
public ForumManager(IRepository<DiscussEntity> discussRepository, IRepository<PlateEntity> plateEntityRepository, IRepository<CommentEntity> commentRepository)
|
||||
{
|
||||
_discussRepository = discussRepository;
|
||||
_plateEntityRepository = plateEntityRepository;
|
||||
_commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
//主题是不能直接创建的,需要由领域服务统一创建
|
||||
public async Task<DiscussEntity> CreateDiscussAsync(DiscussEntity entity)
|
||||
{
|
||||
entity.Id = SnowflakeHelper.NextId;
|
||||
entity.CreationTime = DateTime.Now;
|
||||
entity.AgreeNum = 0;
|
||||
entity.SeeNum = 0;
|
||||
return await _discussRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
|
||||
public async Task<CommentEntity> CreateCommentAsync(long discussId, long parentId, long rootId, string content)
|
||||
{
|
||||
var entity = new CommentEntity(discussId);
|
||||
entity.Id = SnowflakeHelper.NextId;
|
||||
entity.Content = content;
|
||||
entity.ParentId = parentId;
|
||||
entity.RootId = rootId;
|
||||
return await _commentRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Furion.EventBus;
|
||||
using Microsoft.AspNetCore.Mvc.Diagnostics;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
using Yi.Furion.Core.Bbs.Etos;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Event
|
||||
{
|
||||
public class SeeDiscussEventHandler : IEventSubscriber, ISingleton
|
||||
{
|
||||
private IRepository<DiscussEntity> _repository;
|
||||
public SeeDiscussEventHandler(IRepository<DiscussEntity> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
//[EventSubscribe(nameof(LoginEventSource))]
|
||||
public async Task HandlerAsync(EventHandlerExecutingContext context)
|
||||
{
|
||||
var eventData = (SeeDiscussEventArgs)context.Source.Payload;
|
||||
var entity = await _repository.GetByIdAsync(eventData.DiscussId);
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.SeeNum += 1;
|
||||
await _repository.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Article;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Article服务抽象
|
||||
/// </summary>
|
||||
public interface IArticleService : ICrudAppService<ArticleGetOutputDto, ArticleGetListOutputDto, long, ArticleGetListInputVo, ArticleCreateInputVo, ArticleUpdateInputVo>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Banner;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Banner抽象
|
||||
/// </summary>
|
||||
public interface IBannerService : ICrudAppService<BannerGetOutputDto, BannerGetListOutputDto, long, BannerGetListInputVo, BannerCreateInputVo, BannerUpdateInputVo>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Comment;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Comment服务抽象
|
||||
/// </summary>
|
||||
public interface ICommentService : ICrudAppService<CommentGetOutputDto, CommentGetListOutputDto, long, CommentGetListInputVo, CommentCreateInputVo, CommentUpdateInputVo>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Discuss;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Discuss服务抽象
|
||||
/// </summary>
|
||||
public interface IDiscussService : ICrudAppService<DiscussGetOutputDto, DiscussGetListOutputDto, long, DiscussGetListInputVo, DiscussCreateInputVo, DiscussUpdateInputVo>
|
||||
{
|
||||
Task VerifyDiscussPermissionAsync(long discussId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.MyType;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Label服务抽象
|
||||
/// </summary>
|
||||
public interface ILabelService : ICrudAppService<MyTypeOutputDto, MyTypeGetListOutputDto, long, MyTypeGetListInputVo, MyTypeCreateInputVo, MyTypeUpdateInputVo>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Plate;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Plate服务抽象
|
||||
/// </summary>
|
||||
public interface IPlateService : ICrudAppService<PlateGetOutputDto, PlateGetListOutputDto, long, PlateGetListInputVo, PlateCreateInputVo, PlateUpdateInputVo>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Setting应用抽象
|
||||
/// </summary>
|
||||
public interface ISettingService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取配置标题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<string> GetTitleAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services.Abstract;
|
||||
using Yi.Framework.Infrastructure.Exceptions;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Argee;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// 点赞功能
|
||||
/// </summary>
|
||||
public class AgreeService : ApplicationService, IApplicationService, IDynamicApiController, ITransient
|
||||
{
|
||||
public AgreeService(IRepository<AgreeEntity> repository, IRepository<DiscussEntity> discssRepository, ICurrentUser currentUser)
|
||||
{
|
||||
_repository = repository;
|
||||
_currentUser = currentUser;
|
||||
_discssRepository = discssRepository;
|
||||
}
|
||||
|
||||
private IRepository<AgreeEntity> _repository { get; set; }
|
||||
|
||||
private IRepository<DiscussEntity> _discssRepository { get; set; }
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 点赞,返回true为点赞+1,返回false为点赞-1
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnitOfWork]
|
||||
public async Task<AgreeDto> PostOperateAsync(long discussId)
|
||||
{
|
||||
var entity = await _repository.GetFirstAsync(x => x.DiscussId == discussId && x.CreatorId == _currentUser.Id);
|
||||
//判断是否已经点赞过
|
||||
if (entity is null)
|
||||
{
|
||||
|
||||
//没点赞过,添加记录即可,,修改总点赞数量
|
||||
await _repository.InsertAsync(new AgreeEntity(discussId));
|
||||
var discussEntity = await _discssRepository.GetByIdAsync(discussId);
|
||||
if (discussEntity is null)
|
||||
{
|
||||
throw new UserFriendlyException("主题为空");
|
||||
}
|
||||
discussEntity.AgreeNum += 1;
|
||||
await _discssRepository.UpdateAsync(discussEntity);
|
||||
|
||||
return new AgreeDto(true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//点赞过,删除即可,修改总点赞数量
|
||||
await _repository.DeleteByIdAsync(entity.Id);
|
||||
var discussEntity = await _discssRepository.GetByIdAsync(discussId);
|
||||
if (discussEntity is null)
|
||||
{
|
||||
throw new UserFriendlyException("主题为空");
|
||||
}
|
||||
discussEntity.AgreeNum -= 1;
|
||||
await _discssRepository.UpdateAsync(discussEntity);
|
||||
|
||||
return new AgreeDto(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Exceptions;
|
||||
using Yi.Furion.Core.Bbs.Consts;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Article;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
using Yi.Furion.Core.Rbac.Consts;
|
||||
using Yi.Furion.Sqlsugar.Core.Repositories;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Article服务实现
|
||||
/// </summary>
|
||||
|
||||
public class ArticleService : CrudAppService<ArticleEntity, ArticleGetOutputDto, ArticleGetListOutputDto, long, ArticleGetListInputVo, ArticleCreateInputVo, ArticleUpdateInputVo>,
|
||||
IArticleService, IDynamicApiController, ITransient
|
||||
{
|
||||
public ArticleService(IArticleRepository articleRepository,
|
||||
IRepository<DiscussEntity> discussRepository,
|
||||
ICurrentUser currentUser,
|
||||
IDiscussService discussService)
|
||||
{
|
||||
|
||||
_articleRepository = articleRepository;
|
||||
_currentUser = currentUser;
|
||||
_discussRepository = discussRepository;
|
||||
_discussService = discussService;
|
||||
|
||||
|
||||
}
|
||||
private IArticleRepository _articleRepository { get; set; }
|
||||
private IRepository<DiscussEntity> _discussRepository { get; set; }
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
private IDiscussService _discussService { get; set; }
|
||||
/// <summary>
|
||||
/// 获取文章全部平铺信息
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
[Route("/api/article/all/discuss-id/{discussId}")]
|
||||
public async Task<List<ArticleAllOutputDto>> GetAllAsync([FromRoute] long discussId)
|
||||
{
|
||||
await _discussService.VerifyDiscussPermissionAsync(discussId);
|
||||
|
||||
|
||||
var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId);
|
||||
//var result = entities.Tile();
|
||||
var items = _mapper.Map<List<ArticleAllOutputDto>>(entities);
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async Task<List<ArticleGetListOutputDto>> GetDiscussIdAsync([FromRoute] long discussId)
|
||||
{
|
||||
if (!await _discussRepository.IsAnyAsync(x => x.Id == discussId))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
|
||||
var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId);
|
||||
var items = await MapToGetListOutputDtosAsync(entities);
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发表文章
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async override Task<ArticleGetOutputDto> CreateAsync(ArticleCreateInputVo input)
|
||||
{
|
||||
var discuss = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId);
|
||||
if (discuss is null)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
if (input.ParentId != 0 && !await _repository.IsAnyAsync(x => x.Id == input.ParentId))
|
||||
{
|
||||
throw new UserFriendlyException(ArticleConst.文章不存在);
|
||||
}
|
||||
await VerifyDiscussCreateIdAsync(discuss.CreatorId);
|
||||
return await base.CreateAsync(input);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 效验创建权限
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task VerifyDiscussCreateIdAsync(long? userId)
|
||||
{
|
||||
//只有文章是特殊的,不能在其他主题下创建
|
||||
//主题的创建者不是当前用户,同时,没有权限或者超级管理
|
||||
|
||||
//false & true & false ,三个条件任意满意一个,即可成功使用||,最后取反,一个都不满足
|
||||
//
|
||||
if (userId != _currentUser.Id && !UserConst.Admin.Equals(_currentUser.UserName) && !_currentUser.Permission.Contains("bbs:discuss:add"))
|
||||
{
|
||||
throw new UserFriendlyException("无权限在其他用户主题中创建子文章");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Banner;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Banner服务实现
|
||||
/// </summary>
|
||||
public class BannerService : CrudAppService<BannerEntity, BannerGetOutputDto, BannerGetListOutputDto, long, BannerGetListInputVo, BannerCreateInputVo, BannerUpdateInputVo>,
|
||||
IBannerService,IDynamicApiController,ITransient
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Exceptions;
|
||||
using Yi.Furion.Application.Bbs.Domain;
|
||||
using Yi.Furion.Core.Bbs.Consts;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Comment;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// 评论
|
||||
/// </summary>
|
||||
public class CommentService : CrudAppService<CommentEntity, CommentGetOutputDto, CommentGetListOutputDto, long, CommentGetListInputVo, CommentCreateInputVo, CommentUpdateInputVo>,
|
||||
ICommentService, IDynamicApiController, ITransient
|
||||
{
|
||||
|
||||
public CommentService(ForumManager forumManager, ICurrentUser currentUser, IRepository<DiscussEntity> discussRepository, IDiscussService discussService)
|
||||
{
|
||||
_forumManager = forumManager;
|
||||
_currentUser = currentUser;
|
||||
_discussRepository = discussRepository;
|
||||
_discussService=discussService;
|
||||
}
|
||||
|
||||
private ForumManager _forumManager { get; set; }
|
||||
|
||||
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
|
||||
private IRepository<DiscussEntity> _discussRepository { get; set; }
|
||||
|
||||
private IDiscussService _discussService { get; set; }
|
||||
/// <summary>
|
||||
/// 获取改主题下的评论,结构为二维列表,该查询无分页
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedResultDto<CommentGetListOutputDto>> GetDiscussIdAsync([FromRoute] long discussId, [FromQuery] CommentGetListInputVo input)
|
||||
{
|
||||
await _discussService.VerifyDiscussPermissionAsync(discussId);
|
||||
|
||||
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content))
|
||||
.Where(x => x.DiscussId == discussId)
|
||||
.Includes(x => x.CreateUser)
|
||||
.ToListAsync();
|
||||
|
||||
//结果初始值,第一层等于全部根节点
|
||||
var outPut = entities.Where(x => x.ParentId == 0).OrderByDescending(x => x.CreationTime).ToList();
|
||||
|
||||
//将全部数据进行hash
|
||||
var dic = entities.ToDictionary(x => x.Id);
|
||||
|
||||
|
||||
foreach (var comment in entities)
|
||||
{
|
||||
//不是根节点,需要赋值 被评论者用户信息等
|
||||
if (comment.ParentId != 0)
|
||||
{
|
||||
var parentComment = dic[comment.ParentId];
|
||||
comment.CommentedUser = parentComment.CreateUser;
|
||||
}
|
||||
|
||||
//root或者parent id,根节点都是等于0的
|
||||
var id = comment.RootId;
|
||||
if (id is not 0)
|
||||
{
|
||||
dic[id].Children.Add(comment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//子类需要排序
|
||||
outPut.ForEach(x =>
|
||||
{
|
||||
x.Children = x.Children.OrderByDescending(x => x.CreationTime).ToList();
|
||||
|
||||
});
|
||||
|
||||
//获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
|
||||
List<CommentGetListOutputDto> items = await MapToGetListOutputDtosAsync(outPut);
|
||||
return new PagedResultDto<CommentGetListOutputDto>(entities.Count(), items);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发表评论
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public override async Task<CommentGetOutputDto> CreateAsync(CommentCreateInputVo input)
|
||||
{
|
||||
if (!await _discussRepository.IsAnyAsync(x => x.Id == input.DiscussId))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId, input.RootId, input.Content);
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using Furion.EventBus;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Exceptions;
|
||||
using Yi.Furion.Application.Bbs.Domain;
|
||||
using Yi.Furion.Core.Bbs.Consts;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Discuss;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
using Yi.Furion.Core.Bbs.Enums;
|
||||
using Yi.Furion.Core.Bbs.Etos;
|
||||
using Yi.Furion.Core.Rbac.Dtos.User;
|
||||
using Yi.Furion.Core.Rbac.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Discuss应用服务实现,用于参数效验、领域服务业务组合、日志记录、事务处理、账户信息
|
||||
/// </summary>
|
||||
public class DiscussService : CrudAppService<DiscussEntity, DiscussGetOutputDto, DiscussGetListOutputDto, long, DiscussGetListInputVo, DiscussCreateInputVo, DiscussUpdateInputVo>,
|
||||
IDiscussService,IDynamicApiController,ITransient
|
||||
{
|
||||
public DiscussService(ICurrentUser currentUser, ForumManager forumManager, IRepository<PlateEntity> plateEntityRepository, IEventPublisher eventPublisher)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_forumManager = forumManager;
|
||||
_plateEntityRepository= plateEntityRepository;
|
||||
_eventPublisher= eventPublisher;
|
||||
}
|
||||
|
||||
private ForumManager _forumManager { get; set; }
|
||||
|
||||
|
||||
private IRepository<PlateEntity> _plateEntityRepository { get; set; }
|
||||
|
||||
private IEventPublisher _eventPublisher { get; set; }
|
||||
|
||||
|
||||
//[Autowired]
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
/// <summary>
|
||||
/// 单查
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async override Task<DiscussGetOutputDto> GetAsync(long id)
|
||||
{
|
||||
|
||||
//查询主题发布 浏览主题 事件,浏览数+1
|
||||
var item = await _DbQueryable.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
||||
.Select((discuss, user) => new DiscussGetOutputDto
|
||||
{
|
||||
User = new UserGetListOutputDto() { UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
||||
}, true).SingleAsync(discuss => discuss.Id == id);
|
||||
|
||||
await VerifyDiscussPermissionAsync(item.Id);
|
||||
|
||||
if (item is not null)
|
||||
{
|
||||
_eventPublisher.PublishAsync(new SeeDiscussEventSource(new SeeDiscussEventArgs { DiscussId = item.Id, OldSeeNum = item.SeeNum }));
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public override async Task<PagedResultDto<DiscussGetListOutputDto>> GetListAsync([FromQuery] DiscussGetListInputVo input)
|
||||
{
|
||||
//需要关联创建者用户
|
||||
RefAsync<int> total = 0;
|
||||
var items = await _DbQueryable
|
||||
.WhereIF(!string.IsNullOrEmpty(input.Title), x => x.Title.Contains(input.Title))
|
||||
.WhereIF(input.PlateId is not null, x => x.PlateId == input.PlateId)
|
||||
.Where(x => x.IsTop == input.IsTop)
|
||||
|
||||
.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.New, discuss => discuss.CreationTime, OrderByType.Desc)
|
||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.Host, discuss => discuss.SeeNum, OrderByType.Desc)
|
||||
.OrderByIF(input.Type == QueryDiscussTypeEnum.Suggest, discuss => discuss.AgreeNum, OrderByType.Desc)
|
||||
.Select((discuss, user) => new DiscussGetListOutputDto
|
||||
{
|
||||
Id = discuss.Id,
|
||||
IsAgree = SqlFunc.Subqueryable<AgreeEntity>().Where(x => x.CreatorId == _currentUser.Id && x.DiscussId == discuss.Id).Any(),
|
||||
|
||||
User = new UserGetListOutputDto() { Id = user.Id, UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
||||
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageNum, input.PageSize, total);
|
||||
|
||||
//查询完主题之后,要过滤一下私有的主题信息
|
||||
items.ApplyPermissionTypeFilter(_currentUser.Id);
|
||||
return new PagedResultDto<DiscussGetListOutputDto>(total, items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建主题
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<DiscussGetOutputDto> CreateAsync(DiscussCreateInputVo input)
|
||||
{
|
||||
if (!await _plateEntityRepository.IsAnyAsync(x => x.Id == input.PlateId))
|
||||
{
|
||||
throw new UserFriendlyException(PlateConst.板块不存在);
|
||||
}
|
||||
var entity = await _forumManager.CreateDiscussAsync(await MapToEntityAsync(input));
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 效验主题查询权限
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async Task VerifyDiscussPermissionAsync(long discussId)
|
||||
{
|
||||
var discuss = await _repository.GetFirstAsync(x => x.Id == discussId);
|
||||
if (discuss is null)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.Oneself)
|
||||
{
|
||||
if (discuss.CreatorId != _currentUser.Id)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.私密);
|
||||
}
|
||||
}
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.User)
|
||||
{
|
||||
if (discuss.CreatorId != _currentUser.Id && !discuss.PermissionUserIds.Contains(_currentUser.Id))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.私密);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Data.Filters;
|
||||
using Yi.Framework.Infrastructure.Ddd.Dtos;
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Framework.Infrastructure.Helper;
|
||||
using Yi.Furion.Core.Bbs.Dtos.MyType;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Label服务实现
|
||||
/// </summary>
|
||||
public class MyTypeService : CrudAppService<MyTypeEntity, MyTypeOutputDto, MyTypeGetListOutputDto, long, MyTypeGetListInputVo, MyTypeCreateInputVo, MyTypeUpdateInputVo>,
|
||||
ILabelService, IDynamicApiController, ITransient
|
||||
{
|
||||
public MyTypeService(ICurrentUser currentUser, IDataFilter dataFilter)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_dataFilter = dataFilter;
|
||||
}
|
||||
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
|
||||
private IDataFilter _dataFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户的主题类型
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<PagedResultDto<MyTypeGetListOutputDto>> GetListCurrentAsync(MyTypeGetListInputVo input)
|
||||
{
|
||||
|
||||
_dataFilter.AddFilter<MyTypeEntity>(x => x.UserId == _currentUser.Id);
|
||||
return base.GetListAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<MyTypeOutputDto> CreateAsync(MyTypeCreateInputVo input)
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.Id = SnowflakeHelper.NextId;
|
||||
entity.UserId = _currentUser.Id;
|
||||
entity.IsDeleted = false;
|
||||
var outputEntity = await _repository.InsertReturnEntityAsync(entity);
|
||||
return await MapToGetOutputDtoAsync(outputEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
using Yi.Furion.Core.Bbs.Dtos.Plate;
|
||||
using Yi.Furion.Core.Bbs.Entities;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Plate服务实现
|
||||
/// </summary>
|
||||
public class PlateService : CrudAppService<PlateEntity, PlateGetOutputDto, PlateGetListOutputDto, long, PlateGetListInputVo, PlateCreateInputVo, PlateUpdateInputVo>,
|
||||
IPlateService,IDynamicApiController,ITransient
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Yi.Framework.Infrastructure.Ddd.Services;
|
||||
|
||||
namespace Yi.Furion.Application.Bbs.Services.Impl
|
||||
{
|
||||
/// <summary>
|
||||
/// Setting服务实现
|
||||
/// </summary>
|
||||
public class SettingService : ApplicationService,
|
||||
ISettingService,IDynamicApiController,ITransient
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取配置标题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task<string> GetTitleAsync()
|
||||
{
|
||||
return Task.FromResult("你好世界");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user