feat:完成评论功能
This commit is contained in:
@@ -24,6 +24,71 @@
|
||||
Comment输入创建对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.Content">
|
||||
<summary>
|
||||
评论id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.DiscussId">
|
||||
<summary>
|
||||
主题id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.RootId">
|
||||
<summary>
|
||||
第一层评论id,第一层为0
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId,第一层为0
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto">
|
||||
<summary>
|
||||
评论多反
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.DiscussId">
|
||||
<summary>
|
||||
主题id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.CreateUser">
|
||||
<summary>
|
||||
用户,评论人用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.CommentedUser">
|
||||
<summary>
|
||||
被评论的用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.Children">
|
||||
<summary>
|
||||
这个不是一个树形,而是存在一个二维数组,该Children只有在顶级时候,只有一层
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto">
|
||||
<summary>
|
||||
单返回,返回单条评论即可
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.User">
|
||||
<summary>
|
||||
用户id联表为用户对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.RootId">
|
||||
<summary>
|
||||
根节点的评论id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.Discuss.DiscussCreateInputVo">
|
||||
<summary>
|
||||
Discuss输入创建对象
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Forum.CommentService">
|
||||
<summary>
|
||||
Comment服务实现
|
||||
评论
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.CommentService.GetDiscussIdAsync(System.Int64,Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListInputVo)">
|
||||
<summary>
|
||||
获取改主题下的评论
|
||||
获取改主题下的评论,结构为二维列表,该查询无分页
|
||||
</summary>
|
||||
<param name="discussId"></param>
|
||||
<param name="input"></param>
|
||||
|
||||
@@ -21,6 +21,31 @@
|
||||
<param name="entities"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Domain.Forum.Entities.CommentEntity">
|
||||
<summary>
|
||||
评论表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Domain.Forum.Entities.CommentEntity.#ctor">
|
||||
<summary>
|
||||
采用二维数组方式,不使用树形方式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.CreateUser">
|
||||
<summary>
|
||||
用户,评论人用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.CommentedUser">
|
||||
<summary>
|
||||
被评论的用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Domain.Forum.ForumManager">
|
||||
<summary>
|
||||
论坛模块的领域服务
|
||||
|
||||
Binary file not shown.
@@ -24,6 +24,71 @@
|
||||
Comment输入创建对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.Content">
|
||||
<summary>
|
||||
评论id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.DiscussId">
|
||||
<summary>
|
||||
主题id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.RootId">
|
||||
<summary>
|
||||
第一层评论id,第一层为0
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentCreateInputVo.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId,第一层为0
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto">
|
||||
<summary>
|
||||
评论多反
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.DiscussId">
|
||||
<summary>
|
||||
主题id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.CreateUser">
|
||||
<summary>
|
||||
用户,评论人用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.CommentedUser">
|
||||
<summary>
|
||||
被评论的用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListOutputDto.Children">
|
||||
<summary>
|
||||
这个不是一个树形,而是存在一个二维数组,该Children只有在顶级时候,只有一层
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto">
|
||||
<summary>
|
||||
单返回,返回单条评论即可
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.User">
|
||||
<summary>
|
||||
用户id联表为用户对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.RootId">
|
||||
<summary>
|
||||
根节点的评论id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetOutputDto.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Contracts.Forum.Dtos.Discuss.DiscussCreateInputVo">
|
||||
<summary>
|
||||
Discuss输入创建对象
|
||||
|
||||
@@ -13,17 +13,23 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
public class CommentCreateInputVo
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 评论id
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主题id
|
||||
/// </summary>
|
||||
public long DiscussId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 根节点的评论id,这里也可根据树形查询获取到根节点,但是不够优雅,前端是二维数组,选择前端传值即可,如果是根,传0,如果不是
|
||||
/// 第一层评论id,第一层为0
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被回复的CommentId
|
||||
/// 被回复的CommentId,第一层为0
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
}
|
||||
|
||||
@@ -19,10 +19,6 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>id
|
||||
@@ -31,16 +27,21 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
|
||||
public long ParentId { get; set; }
|
||||
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <20>û<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// <20>û<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
||||
/// </summary>
|
||||
public UserGetOutputDto User { get; set; }
|
||||
public UserGetOutputDto CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><DBB5>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
||||
/// </summary>
|
||||
public UserGetOutputDto CommentedUser { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD>飬<EFBFBD><E9A3AC>Childrenֻ<6E><D6BB>һ<EFBFBD><D2BB>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD>飬<EFBFBD><E9A3AC>Childrenֻ<6E><D6BB><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public List<CommentGetListOutputDto> Children { get; set; } = new List<CommentGetListOutputDto>();
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Forum.CommentService">
|
||||
<summary>
|
||||
Comment服务实现
|
||||
评论
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.CommentService.GetDiscussIdAsync(System.Int64,Yi.BBS.Application.Contracts.Forum.Dtos.CommentGetListInputVo)">
|
||||
<summary>
|
||||
获取改主题下的评论
|
||||
获取改主题下的评论,结构为二维列表,该查询无分页
|
||||
</summary>
|
||||
<param name="discussId"></param>
|
||||
<param name="input"></param>
|
||||
|
||||
@@ -46,24 +46,36 @@ namespace Yi.BBS.Application.Forum
|
||||
|
||||
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();
|
||||
|
||||
//获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
|
||||
List<CommentGetListOutputDto>? items = await MapToGetListOutputDtosAsync(entities);
|
||||
//结果初始值,第一层等于全部根节点
|
||||
var outPut = entities.Where(x => x.ParentId == 0).ToList();
|
||||
|
||||
//这里就是dto的处理啦
|
||||
//将全部数据进行hash
|
||||
var dic = entities.ToDictionary(x => x.Id);
|
||||
|
||||
//获取根节点
|
||||
var rootDic = items.Where(x => x.ParentId != 0).ToDictionary(x => x.Id);
|
||||
|
||||
foreach (var comment in items)
|
||||
foreach (var comment in entities)
|
||||
{
|
||||
//不是根节点,需要赋值 被评论者用户信息等
|
||||
if (comment.ParentId != 0)
|
||||
{
|
||||
rootDic[comment.Id].Children.Add(comment);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
return new PagedResultDto<CommentGetListOutputDto>(0, items);
|
||||
//获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
|
||||
List<CommentGetListOutputDto>? items = await MapToGetListOutputDtosAsync(outPut);
|
||||
return new PagedResultDto<CommentGetListOutputDto>(0, items);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +91,7 @@ namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.Content);
|
||||
var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId,input.RootId, input.Content);
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,31 @@
|
||||
<param name="entities"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Domain.Forum.Entities.CommentEntity">
|
||||
<summary>
|
||||
评论表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Domain.Forum.Entities.CommentEntity.#ctor">
|
||||
<summary>
|
||||
采用二维数组方式,不使用树形方式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.ParentId">
|
||||
<summary>
|
||||
被回复的CommentId
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.CreateUser">
|
||||
<summary>
|
||||
用户,评论人用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Yi.BBS.Domain.Forum.Entities.CommentEntity.CommentedUser">
|
||||
<summary>
|
||||
被评论的用户信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Domain.Forum.ForumManager">
|
||||
<summary>
|
||||
论坛模块的领域服务
|
||||
|
||||
@@ -33,27 +33,34 @@ namespace Yi.BBS.Domain.Forum.Entities
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public long DiscussId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根节点的评论id
|
||||
/// </summary>
|
||||
public long RootId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被回复的CommentId
|
||||
/// </summary>
|
||||
public long ParentId { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
public long RootId { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<CommentEntity> Children { get; set; } = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户,评论人用户信息
|
||||
/// </summary>
|
||||
[Navigate(NavigateType.OneToOne, nameof(CreatorId))]
|
||||
public UserEntity User { get; set; }
|
||||
public UserEntity CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被评论的用户信息
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public UserEntity CommentedUser { get; set; }
|
||||
|
||||
public long? CreatorId { get; set; }
|
||||
|
||||
public long? LastModifierId { get; set; }
|
||||
|
||||
@@ -40,11 +40,13 @@ namespace Yi.BBS.Domain.Forum
|
||||
return await _discussRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
|
||||
public async Task<CommentEntity> CreateCommentAsync(long discussId, string content)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user