NoticeController.cs 4.9 KB

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