AdminThesaurusController.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using GxPress.Common.Page;
  5. using GxPress.Entity;
  6. using GxPress.Repository.Interface;
  7. using GxPress.Request.Thesaurus;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. namespace GxPress.Api.AdminControllers
  11. {
  12. /// <summary>
  13. /// 词库 热词 冷词
  14. /// </summary>
  15. [Route("api/admin/thesaurus")]
  16. [ApiController]
  17. [Authorize]
  18. public class AdminThesaurusController : ControllerBase
  19. {
  20. private readonly IThesaurusRepository _thesaurusRepository;
  21. public AdminThesaurusController(IThesaurusRepository thesaurusRepository)
  22. {
  23. _thesaurusRepository = thesaurusRepository;
  24. }
  25. /// <summary>
  26. /// 添加
  27. /// </summary>
  28. /// <param name="request">参数</param>
  29. /// <returns></returns>
  30. [HttpPut("add")]
  31. public async Task<bool> InThesaurus([FromBody] ThesaurusInRequest request)
  32. {
  33. if (!string.IsNullOrEmpty(request.ThesaurusName) && request.ThesaurusName.Length > 500)
  34. {
  35. throw new Exception("保存失败,字符数不能超出16字");
  36. }
  37. var appVersion = new Thesaurus { ThesaurusType = request.ThesaurusType, ThesaurusName = request.ThesaurusName };
  38. return await _thesaurusRepository.InsertAsync(appVersion);
  39. }
  40. /// <summary>
  41. /// 分页查询列表
  42. /// </summary>
  43. /// <param name="request"></param>
  44. /// <returns></returns>
  45. [HttpPost("page")]
  46. public async Task<PagedList<Thesaurus>> GetPagedList([FromBody] ThesaurusPageSearchRequest request)
  47. {
  48. return await _thesaurusRepository.GetPageList(request);
  49. }
  50. /// <summary>
  51. /// 删除
  52. /// </summary>
  53. /// <param name="id"></param>
  54. /// <returns></returns>
  55. [HttpDelete("{id}")]
  56. public async Task<bool> Delete(int id)
  57. {
  58. return await _thesaurusRepository.DeleteAsync(id);
  59. }
  60. /// <summary>
  61. /// 删除
  62. /// </summary>
  63. /// <param name="ids"></param>
  64. /// <returns></returns>
  65. [HttpDelete("delete")]
  66. public async Task<bool> Deletes(List<int> ids)
  67. {
  68. return await _thesaurusRepository.DeleteAsync(ids);
  69. }
  70. /// <summary>
  71. /// 详情
  72. /// </summary>
  73. /// <param name="id"></param>
  74. /// <returns></returns>
  75. [HttpGet("{id}")]
  76. public async Task<Thesaurus> Get(int id)
  77. {
  78. return await _thesaurusRepository.GetDetailAsync(id);
  79. }
  80. /// <summary>
  81. /// 修改
  82. /// </summary>
  83. /// <param name="id"></param>
  84. /// <param name="request"></param>
  85. /// <returns></returns>
  86. [HttpPut("{id}")]
  87. public async Task<bool> Update(int id, [FromBody] ThesaurusUpdateRequest request)
  88. {
  89. if (!string.IsNullOrEmpty(request.ThesaurusName) && request.ThesaurusName.Length > 500)
  90. {
  91. throw new Exception("保存失败,字符数不能超出16字");
  92. }
  93. return await _thesaurusRepository.UpdateAsync(id, request);
  94. }
  95. }
  96. }