NoticeController.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Repository.Interface;
  6. using GxPress.Request.Notice;
  7. using GxPress.Result.Notice;
  8. using GxPress.Service.Interface.Notice;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. namespace GxPress.Api.AppControllers
  12. {
  13. /// <summary>
  14. /// 通知
  15. /// </summary>
  16. [Route("api/app/notice")]
  17. [ApiController]
  18. [Authorize]
  19. public class NoticeController : ControllerBase
  20. {
  21. private readonly INoticeRepository _noticeRepository;
  22. private readonly INoticeService _noticeService;
  23. private readonly ILoginContext _loginContext;
  24. public NoticeController(INoticeRepository noticeRepository, INoticeService noticeService, ILoginContext loginContext)
  25. {
  26. _noticeRepository = noticeRepository;
  27. _noticeService = noticeService;
  28. _loginContext = loginContext;
  29. }
  30. /// <summary>
  31. /// 添加通知
  32. /// </summary>
  33. /// <param name="request"></param>
  34. /// <returns></returns>
  35. [HttpPut("add")]
  36. public async Task<bool> Insert(NoticeInRequest request)
  37. {
  38. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  39. // request.Content = StringUtils.RemoveEmoji(request.Content);
  40. request.UserId = _loginContext.AccountId;
  41. var boolValue = await _noticeService.InsertAsync(request);
  42. return boolValue;
  43. }
  44. /// <summary>
  45. /// 自己删除
  46. /// </summary>
  47. /// <param name="request"></param>
  48. /// <returns></returns>
  49. [HttpDelete("delete")]
  50. public async Task<bool> Delete(NoticeDeRequest request)
  51. {
  52. return await _noticeRepository.DeleteAsync(request);
  53. }
  54. /// <summary>
  55. /// 获取通知详情
  56. /// </summary>
  57. /// <param name="id"></param>
  58. /// <returns></returns>
  59. [HttpGet("app-detail/{id}")]
  60. public async Task<Result.Notice.NoticeDetailResult> GetNoticeDetailResult(int id)
  61. {
  62. return await _noticeService.GetNoticeDetailAsync(id, _loginContext.AccountId);
  63. }
  64. /// <summary>
  65. /// app通知分页列表
  66. /// </summary>
  67. /// <param name="request"></param>
  68. /// <returns></returns>
  69. [HttpPost("list-page")]
  70. public async Task<PagedList<NoticeListPageResult>> GetNoticeListPage(NoticePageSearchRequest request)
  71. {
  72. request.UserId = _loginContext.AccountId;
  73. return await _noticeService.GetNoticeListPageAsync(request);
  74. }
  75. /// <summary>
  76. /// 恢复删除通知
  77. /// </summary>
  78. /// <param name="request"></param>
  79. /// <returns></returns>
  80. [HttpPost("recover")]
  81. public async Task<bool> RecoverDelete(NoticeDeRequest request)
  82. {
  83. return await _noticeRepository.RecoverDeleteAsync(request);
  84. }
  85. /// <summary>
  86. /// 详情
  87. /// </summary>
  88. /// <param name="id"></param>
  89. /// <returns></returns>
  90. [HttpGet("detail/{id}")]
  91. public async Task<NoticeEditDetailResult> Detail(int id)
  92. {
  93. return await _noticeService.NoticeEditDetailAsync(id);
  94. }
  95. /// <summary>
  96. /// 详情 web专属
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <returns></returns>
  100. [HttpGet("web-detail/{id}")]
  101. [AllowAnonymous]
  102. public async Task<NoticeEditDetailResult> WebDetail(int id)
  103. {
  104. return await _noticeService.NoticeEditDetailAsync(id);
  105. }
  106. /// <summary>
  107. /// 修改详情
  108. /// </summary>
  109. /// <param name="request"></param>
  110. /// <returns></returns>
  111. [HttpPost("edit")]
  112. public async Task<bool> Edit([FromBody] NoticeUpRequest request)
  113. {
  114. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  115. // request.Content = StringUtils.RemoveEmoji(request.Content);
  116. request.UserId = _loginContext.AccountId;
  117. return await _noticeService.NoticeUpAsync(request);
  118. }
  119. /// <summary>
  120. /// 查询通知已读未读信息
  121. /// </summary>
  122. /// <param name="request"></param>
  123. /// <returns></returns>
  124. [HttpPost("read")]
  125. public async Task<IEnumerable<NoticeReadListResult>> NoticeReadList(NoticeReadListRequest request)
  126. {
  127. return await _noticeService.NoticeReadListAsync(request);
  128. }
  129. /// <summary>
  130. /// 撤销通知
  131. /// </summary>
  132. /// <param name="id"></param>
  133. /// <returns></returns>
  134. [HttpPut("recall/{id}")]
  135. public async Task<bool> RecallAsync(int id)
  136. {
  137. return await _noticeService.RecallAsync(id);
  138. }
  139. }
  140. }