CommentController.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Threading.Tasks;
  2. using GxPress.Auth;
  3. using GxPress.Common.Page;
  4. using GxPress.Repository.Interface;
  5. using GxPress.Request.Comment;
  6. using GxPress.Result.Comment;
  7. using Microsoft.AspNetCore.Mvc;
  8. using GxPress.Common.Exceptions;
  9. namespace GxPress.Api.AppControllers
  10. {
  11. /// <summary>
  12. /// 评论
  13. /// </summary>
  14. [Route("api/app/comment")]
  15. [ApiController]
  16. public class CommentController : ControllerBase
  17. {
  18. private readonly ICommentRepository _commentRepository;
  19. private readonly ILoginContext _loginContext;
  20. public CommentController(ICommentRepository commentRepository, ILoginContext loginContext)
  21. {
  22. _commentRepository = commentRepository;
  23. _loginContext = loginContext;
  24. }
  25. /// <summary>
  26. /// 添加评论
  27. /// </summary>
  28. /// <param name="request"></param>
  29. /// <returns></returns>
  30. [HttpPost("add")]
  31. public async Task<bool> Add([FromBody] CommentInRequest request)
  32. {
  33. // request.Content = StringUtils.RemoveEmoji(request.Content);
  34. request.UserId = _loginContext.AccountId;
  35. if (string.IsNullOrWhiteSpace(request.Content))
  36. throw new BusinessException("评论内容为空");
  37. return await _commentRepository.CommentInAsync(request) > 0;
  38. }
  39. /// <summary>
  40. /// 分页显示数据
  41. /// </summary>
  42. /// <param name="request"></param>
  43. /// <returns></returns>
  44. [HttpPost("list")]
  45. public async Task<PagedList<CommentPageResult>> GetPagedList([FromBody] CommentSearchPageRequest request)
  46. {
  47. request.UserId = _loginContext.AccountId;
  48. return await _commentRepository.GetPagedList(request);
  49. }
  50. /// <summary>
  51. /// 删除
  52. /// </summary>
  53. /// <param name="request"></param>
  54. /// <returns></returns>
  55. [HttpDelete("delete")]
  56. public async Task<bool> Delete([FromBody] CommentDeleteRequest request)
  57. {
  58. return await _commentRepository.DeleteCommentAsync(request);
  59. }
  60. }
  61. }