using Yi.BBS.Application.Contracts.Forum;
using Cike.AutoWebApi.Setting;
using Yi.BBS.Application.Contracts.Forum.Dtos;
using Yi.BBS.Domain.Forum.Entities;
using Yi.Framework.Ddd.Services;
using Microsoft.AspNetCore.Mvc;
using Yi.BBS.Domain.Forum;
using Yi.Framework.Core.CurrentUsers;
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;
namespace Yi.BBS.Application.Forum
{
///
/// Comment服务实现
///
[AppService]
public class CommentService : CrudAppService,
ICommentService, IAutoApiService
{
[Autowired]
private ForumManager _forumManager { get; set; }
[Autowired]
private ICurrentUser _currentUser { get; set; }
[Autowired]
private IRepository _discussRepository { get; set; }
///
/// 获取改主题下的评论
///
///
///
///
public async Task> 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(total, items);
}
///
/// 发表评论
///
///
///
///
public override async Task 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);
return await MapToGetOutputDtoAsync(entity);
}
}
}