MissiveController.cs 4.8 KB

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