feat:完成评论功能搭建

This commit is contained in:
陈淳
2023-03-23 18:15:30 +08:00
parent 8213f6f8d7
commit 4babe3e05d
24 changed files with 219 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.BBS.Application.Contracts.Exhibition.Dtos.Argee
{
public class ArgeeDto
{
public ArgeeDto(bool isArgee)
{
IsArgee = isArgee;
if (isArgee)
{
Message = "点赞成功,点赞+1";
}
else
{
Message = "取消点赞,点赞-1";
}
}
public bool IsArgee { get; set; }
public string Message { get; set; }
}
}

View File

@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cike.AutoWebApi.Setting;
using Yi.BBS.Application.Contracts.Exhibition.Dtos.Argee;
using Yi.BBS.Domain.Exhibition.Entities;
using Yi.BBS.Domain.Forum.Entities;
using Yi.Framework.Core.CurrentUsers;
using Yi.Framework.Ddd.Repositories;
using Yi.Framework.Ddd.Services;
using Yi.Framework.Ddd.Services.Abstract;
using Yi.Framework.Uow;
namespace Yi.BBS.Application.Exhibition
{
/// <summary>
/// 点赞功能
/// </summary>
[AppService]
public class AgreeService : ApplicationService, IApplicationService, IAutoApiService
{
[Autowired]
private IRepository<AgreeEntity> _repository { get; set; }
[Autowired]
private IRepository<DiscussEntity> _discssRepository { get; set; }
[Autowired]
private ICurrentUser _currentUser { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
/// <summary>
/// 点赞,返回true为点赞+1返回false为点赞-1
/// </summary>
/// <returns></returns>
public async Task<ArgeeDto> PostOperateAsync(long discussId)
{
var entity = await _repository.GetFirstAsync(x => x.DiscussId == discussId && x.CreatorId == _currentUser.Id);
//判断是否已经点赞过
if (entity is null)
{
using (var uow = _unitOfWorkManager.CreateContext())
{
//没点赞过,添加记录即可,,修改总点赞数量
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);
uow.Commit();
}
return new ArgeeDto(true);
}
else
{
using (var uow = _unitOfWorkManager.CreateContext())
{
//点赞过,删除即可,修改总点赞数量
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);
uow.Commit();
}
return new ArgeeDto(false);
}
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using Yi.Framework.Data.Auditing;
using Yi.Framework.Data.Entities;
using Yi.Framework.Ddd.Entities;
namespace Yi.BBS.Domain.Exhibition.Entities
{
[SugarTable("Agree")]
public class AgreeEntity : IEntity<long>, ICreationAuditedObject
{
public AgreeEntity()
{
}
public AgreeEntity(long discussId)
{
DiscussId = discussId;
}
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; } = SnowflakeHelper.NextId;
public DateTime CreationTime { get; set; }
/// <summary>
/// 主题id
/// </summary>
public long DiscussId { get; set; }
/// <summary>
/// 创建者
/// </summary>
public long? CreatorId { get; set; }
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB