评论建表

This commit is contained in:
陈淳
2022-12-01 13:38:06 +08:00
parent a2ca897fca
commit e9bcd29e36
9 changed files with 184 additions and 11 deletions

View File

@@ -12,17 +12,17 @@ namespace Yi.Framework.Service
/// 点赞操作
/// </summary>
/// <returns></returns>
public async Task<bool> OperateAsync(long articleId, long userId)
public async Task<bool> OperateAsync(long articleOrCommentId, long userId)
{
var _articleRepositoty = _repository.ChangeRepository<Repository<ArticleEntity>>();
var article = await _articleRepositoty.GetByIdAsync(articleId);
if (await _repository.IsAnyAsync(u => u.UserId == userId && u.ArticleId == articleId))
var article = await _articleRepositoty.GetByIdAsync(articleOrCommentId);
if (await _repository.IsAnyAsync(u => u.UserId == userId && u.ArticleOrCommentId == articleOrCommentId))
{
//已点赞,取消点赞
await _repository.UseTranAsync(async () =>
{
await _repository.DeleteAsync(u => u.UserId == userId && u.ArticleId == articleId);
await _articleRepositoty.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum - 1 });
await _repository.DeleteAsync(u => u.UserId == userId && u.ArticleOrCommentId == articleOrCommentId);
await _articleRepositoty.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleOrCommentId, AgreeNum = article.AgreeNum - 1 });
});
return false;
@@ -32,8 +32,8 @@ namespace Yi.Framework.Service
//未点赞,添加点赞记录
await _repository.UseTranAsync(async () =>
{
await _repository.InsertReturnSnowflakeIdAsync(new AgreeEntity { UserId = userId, ArticleId = articleId });
await _articleRepositoty.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum + 1 });
await _repository.InsertReturnSnowflakeIdAsync(new AgreeEntity { UserId = userId, ArticleOrCommentId = articleOrCommentId });
await _articleRepositoty.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleOrCommentId, AgreeNum = article.AgreeNum + 1 });
});
return true;
}

View File

@@ -0,0 +1,14 @@
using SqlSugar;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
namespace Yi.Framework.Service
{
public partial class CommentService : BaseService<CommentEntity>, ICommentService
{
public CommentService(IRepository<CommentEntity> repository) : base(repository)
{
}
}
}