AdminArticleController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Threading.Tasks;
  3. using GxPress.Common.Page;
  4. using GxPress.Repository.Interface;
  5. using GxPress.Request.Admin.Article;
  6. using GxPress.Request.Article;
  7. using GxPress.Result.Article;
  8. using GxPress.Service.Interface.Article;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. namespace GxPress.Api.AdminControllers
  12. {
  13. /// <summary>
  14. /// 审批文章
  15. /// </summary>
  16. [Route("api/admin/article")]
  17. [ApiController]
  18. [Authorize]
  19. public class AdminArticleController : ControllerBase
  20. {
  21. private readonly IArticleRepository _articleRepository;
  22. private readonly IArticleService _articleService;
  23. public AdminArticleController(IArticleRepository articleRepository, IArticleService articleService)
  24. {
  25. _articleRepository = articleRepository;
  26. _articleService = articleService;
  27. }
  28. /// <summary>
  29. /// 添加文章
  30. /// </summary>
  31. /// <param name="request"></param>
  32. /// <returns></returns>
  33. [HttpPost]
  34. public async Task<ArticleResult> Add([FromBody] ArticleAddRequest request)
  35. {
  36. if (!string.IsNullOrEmpty(request.Summary) && request.Summary.Length > 500)
  37. {
  38. throw new Exception("保存失败,字符数不能超出500");
  39. }
  40. return await _articleService.AddAsync(request);
  41. }
  42. /// <summary>
  43. /// 修改文章
  44. /// </summary>
  45. /// <param name="request"></param>
  46. /// <returns></returns>
  47. [HttpPut]
  48. public async Task<ArticleResult> Edit([FromBody] ArticleEditRequest request)
  49. {
  50. if (!string.IsNullOrEmpty(request.Summary) && request.Summary.Length > 500)
  51. {
  52. throw new Exception("保存失败,字符数不能超出500");
  53. }
  54. return await _articleService.EditAsync(request);
  55. }
  56. /// <summary>
  57. /// 列表
  58. /// </summary>
  59. /// <returns></returns>
  60. [HttpGet("")]
  61. [AllowAnonymous]
  62. public async Task<PagedList<ArticleResult>> GetList([FromQuery] ArticleSearchRequest request)
  63. {
  64. var pagedList = await _articleRepository.GetListAsync(request.Keyword, request);
  65. return pagedList;
  66. }
  67. /// <summary>
  68. /// 文章
  69. /// </summary>
  70. /// <returns></returns>
  71. [HttpGet("{id}")]
  72. [AllowAnonymous]
  73. public async Task<ArticleResult> Get(int id)
  74. {
  75. var article= await _articleService.GetAsync(id,0);
  76. return article;
  77. }
  78. /// <summary>
  79. /// 删除文章
  80. /// </summary>
  81. /// <param name="id"></param>
  82. /// <returns></returns>
  83. [HttpDelete("{id}")]
  84. public async Task<bool> Delete(int id)
  85. {
  86. return await _articleRepository.DeleteAsync(id);
  87. }
  88. ///// <summary>
  89. ///// 文章 点赞 收藏 转发
  90. ///// </summary>
  91. ///// <returns></returns>
  92. //[HttpPost("analyze")]
  93. //[AllowAnonymous]
  94. //public async Task<bool> AddArticleAnalyze([FromBody] ArticleAnalyzeRequest request)
  95. //{
  96. // return await _articleAnalyzeRepository.SetArticleAnalyzeAsync(request);
  97. //}
  98. /// <summary>
  99. /// 克隆文章
  100. /// </summary>
  101. /// <param name="request"></param>
  102. /// <returns></returns>
  103. [HttpPost("clone")]
  104. public async Task<bool> CloneArticle(CloneArticleRequest request)
  105. {
  106. return await _articleRepository.CloneArticleAsync(request);
  107. }
  108. }
  109. }