mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-16 06:26:38 +08:00
feat;添加评论
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
@@ -11,7 +12,19 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
/// </summary>
|
||||
public class CommentCreateInputVo
|
||||
{
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
public long DiscussId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根节点的评论id,这里也可根据树形查询获取到根节点,但是不够优雅,前端是二维数组,选择前端传值即可,如果是根,传0,如果不是
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被回复的CommentId
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
|
||||
namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
public class CommentGetListInputVo : PagedAndSortedResultRequestDto
|
||||
public class CommentGetListInputVo
|
||||
{
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public string? Content { get; set; }
|
||||
|
||||
//应该选择具体莫个主题查询
|
||||
public long? DiscussId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,45 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
|
||||
namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
/// <summary>
|
||||
/// 评论多反
|
||||
/// </summary>
|
||||
public class CommentGetListOutputDto : IEntityDto<long>
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根节点的评论id
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主题id
|
||||
/// </summary>
|
||||
public long DiscussId { get; set; }
|
||||
public long UserId { get; set; }
|
||||
|
||||
public long ParentId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户,评论人用户信息,被评论的用户信息,是他的上一个节点评论
|
||||
/// </summary>
|
||||
public UserGetOutputDto User { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 这个不是一个树形,而是存在一个二维数组,该Children只有一层
|
||||
/// </summary>
|
||||
public List<CommentGetListOutputDto> Children { get; set; } = new List<CommentGetListOutputDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,39 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
||||
|
||||
namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
/// <summary>
|
||||
/// 单返回,返回单条评论即可
|
||||
/// </summary>
|
||||
public class CommentGetOutputDto : IEntityDto<long>
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public long DiscussId { get; set; }
|
||||
public long UserId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户id联表为用户对象
|
||||
/// </summary>
|
||||
|
||||
public UserGetOutputDto User { get; set; }
|
||||
/// <summary>
|
||||
/// 根节点的评论id
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被回复的CommentId
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
public class CommentUpdateInputVo
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
public string Content { get; set; }
|
||||
public long DiscussId { get; set; }
|
||||
public long UserId { get; set; }
|
||||
|
||||
//更新不能将评论转移
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,16 @@ using Yi.Framework.Ddd.Repositories;
|
||||
using Yi.BBS.Domain.Shared.Forum.ConstClasses;
|
||||
using Yi.BBS.Application.Contracts.Forum.Dtos.Discuss;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using SqlSugar;
|
||||
using System.Security.AccessControl;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
/// <summary>
|
||||
/// Comment服务实现
|
||||
/// 评论
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class CommentService : CrudAppService<CommentEntity, CommentGetOutputDto, CommentGetListOutputDto, long, CommentGetListInputVo, CommentCreateInputVo, CommentUpdateInputVo>,
|
||||
@@ -31,18 +36,34 @@ namespace Yi.BBS.Application.Forum
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取改主题下的评论
|
||||
/// 获取改主题下的评论,结构为二维列表,该查询无分页
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public async Task<PagedResultDto<CommentGetListOutputDto>> GetDiscussIdAsync([FromRoute] long discussId, [FromQuery] CommentGetListInputVo input)
|
||||
{
|
||||
var entities = await _repository.GetPageListAsync(x => x.DiscussId == discussId, input);
|
||||
var items = await MapToGetListOutputDtosAsync(entities);
|
||||
var total = await _repository.CountAsync(x => x.IsDeleted == false);
|
||||
return new PagedResultDto<CommentGetListOutputDto>(total, items);
|
||||
|
||||
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content))
|
||||
.Where(x => x.DiscussId == discussId)
|
||||
.ToListAsync();
|
||||
|
||||
//获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
|
||||
List<CommentGetListOutputDto>? items = await MapToGetListOutputDtosAsync(entities);
|
||||
|
||||
//这里就是dto的处理啦
|
||||
|
||||
//获取根节点
|
||||
var rootDic = items.Where(x => x.ParentId != 0).ToDictionary(x => x.Id);
|
||||
|
||||
foreach (var comment in items)
|
||||
{
|
||||
if (comment.ParentId != 0)
|
||||
{
|
||||
rootDic[comment.Id].Children.Add(comment);
|
||||
}
|
||||
}
|
||||
return new PagedResultDto<CommentGetListOutputDto>(0, items);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,16 +75,11 @@ namespace Yi.BBS.Application.Forum
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public override async Task<CommentGetOutputDto> CreateAsync(CommentCreateInputVo input)
|
||||
{
|
||||
//if (_currentUser.Id == default(long))
|
||||
//{
|
||||
// throw new UserFriendlyException("用户不存在");
|
||||
//}
|
||||
if (!await _discussRepository.IsAnyAsync(x => x.Id == input.DiscussId))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
|
||||
}
|
||||
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, _currentUser.Id, input.Content);
|
||||
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.Content);
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,30 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Data.Auditing;
|
||||
using Yi.Framework.Data.Entities;
|
||||
using Yi.Framework.Ddd.Entities;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.BBS.Domain.Forum.Entities
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 评论表
|
||||
/// </summary>
|
||||
[SugarTable("Comment")]
|
||||
public class CommentEntity : IEntity<long>, ISoftDelete
|
||||
public class CommentEntity : IEntity<long>, ISoftDelete,IAuditedObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 采用二维数组方式,不使用树形方式
|
||||
/// </summary>
|
||||
public CommentEntity()
|
||||
{
|
||||
}
|
||||
|
||||
internal CommentEntity(long discussId, long userId)
|
||||
internal CommentEntity(long discussId)
|
||||
{
|
||||
DiscussId= discussId;
|
||||
UserId = userId;
|
||||
}
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
@@ -30,6 +38,26 @@ namespace Yi.BBS.Domain.Forum.Entities
|
||||
public string Content { get; set; }
|
||||
|
||||
public long DiscussId { get; set; }
|
||||
public long UserId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根节点的评论id
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被回复的CommentId
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
|
||||
[Navigate(NavigateType.OneToOne, nameof(CreatorId))]
|
||||
public UserEntity User { get; set; }
|
||||
public long? CreatorId { get; set; }
|
||||
|
||||
public long? LastModifierId { get; set; }
|
||||
|
||||
public DateTime? LastModificationTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,11 @@ namespace Yi.BBS.Domain.Forum
|
||||
return await _discussRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
|
||||
public async Task<CommentEntity> CreateCommentAsync(long discussId, long userId, string content)
|
||||
public async Task<CommentEntity> CreateCommentAsync(long discussId, string content)
|
||||
{
|
||||
var entity = new CommentEntity(discussId, userId);
|
||||
var entity = new CommentEntity(discussId);
|
||||
entity.Id = SnowflakeHelper.NextId;
|
||||
entity.Content = content;
|
||||
entity.CreateTime = DateTime.Now;
|
||||
return await _commentRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user