using System.Threading.Tasks; using GxPress.Auth; using GxPress.Common.Page; using GxPress.Repository.Interface; using GxPress.Request.Comment; using GxPress.Result.Comment; using Microsoft.AspNetCore.Mvc; using GxPress.Common.Exceptions; namespace GxPress.Api.AppControllers { /// /// 评论 /// [Route("api/app/comment")] [ApiController] public class CommentController : ControllerBase { private readonly ICommentRepository _commentRepository; private readonly ILoginContext _loginContext; public CommentController(ICommentRepository commentRepository, ILoginContext loginContext) { _commentRepository = commentRepository; _loginContext = loginContext; } /// /// 添加评论 /// /// /// [HttpPost("add")] public async Task Add([FromBody] CommentInRequest request) { // request.Content = StringUtils.RemoveEmoji(request.Content); request.UserId = _loginContext.AccountId; if (string.IsNullOrWhiteSpace(request.Content)) throw new BusinessException("评论内容为空"); return await _commentRepository.CommentInAsync(request) > 0; } /// /// 分页显示数据 /// /// /// [HttpPost("list")] public async Task> GetPagedList([FromBody] CommentSearchPageRequest request) { request.UserId = _loginContext.AccountId; return await _commentRepository.GetPagedList(request); } /// /// 删除 /// /// /// [HttpDelete("delete")] public async Task Delete([FromBody] CommentDeleteRequest request) { return await _commentRepository.DeleteCommentAsync(request); } } }