MissiveController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Common.Tools;
  6. using GxPress.Repository.Interface.Missive;
  7. using GxPress.Request.App.Missive;
  8. using GxPress.Result.App.Missive;
  9. using GxPress.Service.Interface.Missive;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using System.Linq;
  13. using System;
  14. namespace GxPress.Api.AppControllers
  15. {
  16. /// <summary>
  17. /// 站内信
  18. /// </summary>
  19. [Route("api/app/missive")]
  20. [ApiController]
  21. [Authorize]
  22. public class MissiveController : ControllerBase
  23. {
  24. private readonly IMissiveRepository _missiveRepository;
  25. private readonly IMissiveAnalyzeRepository _missiveAnalyzeRepository;
  26. private readonly IMissiveService _missiveService;
  27. private readonly ILoginContext _loginContext;
  28. public MissiveController(IMissiveRepository missiveRepository, IMissiveService missiveService,
  29. ILoginContext loginContext, IMissiveAnalyzeRepository missiveAnalyzeRepository)
  30. {
  31. _missiveRepository = missiveRepository;
  32. _missiveService = missiveService;
  33. _loginContext = loginContext;
  34. _missiveAnalyzeRepository = missiveAnalyzeRepository;
  35. }
  36. /// <summary>
  37. /// 根据站内信ID获取详情
  38. /// </summary>
  39. /// <param name="missiveId"></param>
  40. /// <returns></returns>
  41. [HttpGet("get/{missiveId}")]
  42. public async Task<MissiveInfoResult> GetMissiveInfo(int missiveId)
  43. {
  44. return await _missiveService.GetMissiveInfoAsync(missiveId, _loginContext.AccountId);
  45. }
  46. /// <summary>
  47. /// 添加/修改站内信
  48. /// </summary>
  49. /// <param name="request"></param>
  50. /// <returns></returns>
  51. [HttpPut("add")]
  52. public async Task<bool> Insert(MissiveInRequest request)
  53. {
  54. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  55. // request.Content = StringUtils.RemoveEmoji(request.Content);
  56. // request.Title = StringUtils.RemoveEmoji(request.Title);
  57. request.UserId = _loginContext.AccountId;
  58. request.MissiveAddresseeUserIds.Remove(request.UserId);
  59. request.MissiveCcUserIds.Remove(request.UserId);
  60. return await _missiveService.InsertOrUpdateAsync(request);
  61. }
  62. /// <summary>
  63. /// 获取站内信列表
  64. /// </summary>
  65. /// <param name="request"></param>
  66. /// <returns></returns>
  67. [HttpPost("search")]
  68. public async Task<PagedList<MissiveSearchResult>> GetMissiveSearchResult(MissiveSearchRequest request)
  69. {
  70. request.UserId = _loginContext.AccountId;
  71. return await _missiveService.GetMissiveSearchResultAsync(request);
  72. }
  73. /// <summary>
  74. /// 文章点赞 评论点赞 文章收藏 文章转发 已废弃
  75. /// </summary>
  76. /// <returns></returns>
  77. [HttpPost("analyze")]
  78. public async Task<bool> AddMissiveAnalyze([FromBody] MissiveAnalyzeRequest request)
  79. {
  80. request.UserId = _loginContext.AccountId;
  81. return await _missiveAnalyzeRepository.SetMissiveAnalyzeAsync(request);
  82. }
  83. /// <summary>
  84. /// 获取站内信详情
  85. /// </summary>
  86. /// <param name="id"></param>
  87. /// <returns></returns>
  88. [HttpGet("{id}")]
  89. public async Task<MissiveDetailResult> GetMissiveDetail(int id)
  90. {
  91. return await _missiveService.GetMissiveDetailAsync(id);
  92. }
  93. /// <summary>
  94. /// 获取站内信详情-web专属
  95. /// </summary>
  96. /// <param name="id"></param>
  97. /// <returns></returns>
  98. [HttpGet("web/{id}")]
  99. [AllowAnonymous]
  100. public async Task<MissiveInfoResult> GetWebMissiveDetail(int id)
  101. {
  102. var missiveInfos = await _missiveService.GetMissiveInfoAsync(id, 0);
  103. missiveInfos.Items = missiveInfos.Items.OrderByDescending(n => Convert.ToDateTime(n.CreatedDate)).ToList();
  104. return missiveInfos;
  105. }
  106. /// <summary>
  107. /// 获取站内信已读未读数据
  108. /// </summary>
  109. /// <param name="request"></param>
  110. /// <returns></returns>
  111. [HttpPost("read")]
  112. public async Task<IEnumerable<MissiveReadListResult>> GetMissiveReadListAsync(MissiveReadListRequest request)
  113. {
  114. return await _missiveService.GetMissiveReadListAsync(request);
  115. }
  116. /// <summary>
  117. /// 站内信撤回
  118. /// </summary>
  119. /// <param name="missiveId"></param>
  120. /// <returns></returns>
  121. [HttpPut("recall/{missiveId}")]
  122. public async Task<bool> RecallAsync(int missiveId)
  123. {
  124. return await _missiveService.RecallAsync(missiveId);
  125. }
  126. }
  127. }