NoticeController.cs 5.0 KB

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