TopicController.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using GxPress.Auth;
  5. using GxPress.Common.Page;
  6. using GxPress.Entity.Topic;
  7. using GxPress.Repository.Interface;
  8. using GxPress.Repository.Interface.Topic;
  9. using GxPress.Request.App.Topic;
  10. using GxPress.Result.App.Topic;
  11. using GxPress.Service.Interface.Middle;
  12. using GxPress.Service.Interface.Topic;
  13. using Microsoft.AspNetCore.Authorization;
  14. using Microsoft.AspNetCore.Mvc;
  15. using Microsoft.Extensions.Logging;
  16. namespace GxPress.Api.AppControllers
  17. {
  18. /// <summary>
  19. /// APP话题
  20. /// </summary>
  21. [Route("api/app/topic")]
  22. [ApiController]
  23. [Authorize]
  24. public class TopicController : ControllerBase
  25. {
  26. private readonly ILogger<TopicController> _logger;
  27. private readonly ITopicRepository _topicRepository;
  28. private readonly ILoginContext _loginContext;
  29. private readonly ITopicService _topicService;
  30. private readonly ITopicGroupRepository _topicGroupRepository;
  31. private readonly ITopicGroupUserRepository _topicGroupUserRepository;
  32. private readonly ITopicAnalyzeRepository _topicAnalyzeRepository;
  33. private readonly ITopicCommentRepository _topicCommentRepository;
  34. private readonly IMiddleService _middleService;
  35. public TopicController(ILogger<TopicController> logger, ITopicRepository repository, ILoginContext loginContext,
  36. ITopicService topicService, ITopicGroupRepository topicGroupRepository,
  37. ITopicGroupUserRepository topicGroupUserRepository, ITopicAnalyzeRepository topicAnalyzeRepository,
  38. ITopicCommentRepository topicCommentRepository, IMiddleService middleService)
  39. {
  40. _logger = logger;
  41. _topicRepository = repository;
  42. _loginContext = loginContext;
  43. _topicService = topicService;
  44. _topicGroupRepository = topicGroupRepository;
  45. _topicGroupUserRepository = topicGroupUserRepository;
  46. _topicAnalyzeRepository = topicAnalyzeRepository;
  47. _topicCommentRepository = topicCommentRepository;
  48. _middleService = middleService;
  49. }
  50. /// <summary>
  51. /// 添加
  52. /// </summary>
  53. /// <param name="request"></param>
  54. /// <returns></returns>
  55. [HttpPost("add")]
  56. public async Task<bool> Insert(TopicInRequest request)
  57. {
  58. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  59. // request.Content = StringUtils.RemoveEmoji(request.Content);
  60. // request.Title = StringUtils.RemoveEmoji(request.Title);
  61. request.UserId = _loginContext.AccountId;
  62. return await _topicService.InsertTopicAsync(request);
  63. }
  64. /// <summary>
  65. /// 获取话题详情
  66. /// </summary>
  67. /// <param name="request"></param>
  68. /// <returns></returns>
  69. [HttpPost("app-detail")]
  70. public async Task<TopicDetailResult> GetTopicDetailResult(TopicDetailRequest request)
  71. {
  72. request.UserId = _loginContext.AccountId;
  73. var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
  74. return topicDetail;
  75. }
  76. /// <summary>
  77. /// 获取话题详情 web专属
  78. /// </summary>
  79. /// <param name="request"></param>
  80. /// <returns></returns>
  81. [HttpPost("web-app-detail")]
  82. [AllowAnonymous]
  83. public async Task<TopicDetailResult> GetWebTopicDetailResult(TopicDetailRequest request)
  84. {
  85. var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
  86. return topicDetail;
  87. }
  88. /// <summary>
  89. /// app话题分页列表
  90. /// </summary>
  91. /// <param name="request"></param>
  92. /// <returns></returns>
  93. [HttpPost("list-page")]
  94. public async Task<PagedList<TopicListPageResult>> GetTopicListPage(TopicPageSearchRequest request)
  95. {
  96. request.UserId = _loginContext.AccountId;
  97. return await _topicService.GetTopicPageAsync(request);
  98. }
  99. /// <summary>
  100. /// 获取用户话题分组
  101. /// </summary>
  102. /// <returns></returns>
  103. [HttpPost("group")]
  104. public async Task<IEnumerable<TopicGroup>> GetTopicGroups()
  105. {
  106. return await _topicGroupRepository.GetTopicGroupsAsync(_loginContext.AccountId);
  107. }
  108. /// <summary>
  109. /// 添加话题分组
  110. /// </summary>
  111. /// <param name="request"></param>
  112. /// <returns></returns>
  113. [HttpPut("add-group")]
  114. public async Task<bool> InsertTopicGroup(TopicGroupInRequest request)
  115. {
  116. var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
  117. return await _topicGroupRepository.InsertAsync(topicGroup);
  118. }
  119. /// <summary>
  120. /// 修改分组名称
  121. /// </summary>
  122. /// <param name="request"></param>
  123. /// <returns></returns>
  124. [HttpPut("update-group")]
  125. public async Task<bool> UpdateGroup(TopicGroupInRequest request)
  126. {
  127. return await _topicGroupRepository.UpdateAsync(request);
  128. }
  129. /// <summary>
  130. /// 根据话题分组Id删除数据
  131. /// </summary>
  132. /// <param name="request"></param>
  133. /// <returns></returns>
  134. [HttpDelete("delete_group")]
  135. public async Task<bool> DeleteTopicGroup([FromBody] TopicGroupDeRequest request)
  136. {
  137. return await _topicService.DeleteTopicGroupAsync(request.Ids);
  138. }
  139. /// <summary>
  140. /// 根据分组ID查询用户
  141. /// </summary>
  142. /// <param name="id"></param>
  143. /// <returns></returns>
  144. [HttpGet("{id}")]
  145. public async Task<PagedList<TopicGroupUserResult>> GetTopicGroupUserById(int id)
  146. {
  147. return await _topicGroupUserRepository.GetTopicGroupUserById(id);
  148. }
  149. /// <summary>
  150. /// 添加话题小组成员
  151. /// </summary>
  152. /// <param name="request"></param>
  153. /// <returns></returns>
  154. [HttpPost("add-group-user")]
  155. public async Task<bool> InsertAsync([FromBody]TopicGroupUserInRequest request)
  156. {
  157. return await _topicService.InsertTopicGroupUserAsync(request.UserIds.Distinct().ToList(), request.TopicGroupId);
  158. }
  159. /// <summary>
  160. /// 根据ID删除话题分组成员
  161. /// </summary>
  162. /// <param name="request"></param>
  163. /// <returns></returns>
  164. [HttpDelete("group-user")]
  165. public async Task<bool> DeleteUser(TopicGroupDeRequest request)
  166. {
  167. return await _topicService.DeleteTopicGroupUserAsync(request.Ids);
  168. }
  169. /// <summary>
  170. /// 排序
  171. /// </summary>
  172. /// <param name="request"></param>
  173. /// <returns></returns>
  174. [HttpPut("sort")]
  175. public async Task<bool> MoveSort(TopicMoveSortRequest request)
  176. {
  177. return await _topicGroupRepository.MoveSortAsync(request.FirstId, request.SecondId, _loginContext.AccountId);
  178. }
  179. /// <summary>
  180. /// 移动到
  181. /// </summary>
  182. /// <param name="request"></param>
  183. /// <returns></returns>
  184. [HttpPut("move")]
  185. public async Task<bool> MoveToGroup(MoveToGroupRequest request)
  186. {
  187. return await _topicService.MoveToGroupAsync(request);
  188. }
  189. /// <summary>
  190. /// 根据分组ID和姓名查询用户
  191. /// </summary>
  192. /// <param name="request"></param>
  193. /// <returns></returns>
  194. [HttpPost("search")]
  195. public async Task<PagedList<TopicGroupUserResult>> SearchTopicGroupUsers(SearchTopicGroupUsersRequest request)
  196. {
  197. return await _topicGroupUserRepository.SearchTopicGroupUsersAsync(request);
  198. }
  199. /// <summary>
  200. /// 删除话题
  201. /// </summary>
  202. /// <param name="id"></param>
  203. /// <returns></returns>
  204. [HttpDelete("{id}")]
  205. public async Task<bool> Delete(int id)
  206. {
  207. return await _topicService.DeleteAsync(id);
  208. }
  209. /// <summary>
  210. /// 修改话题
  211. /// </summary>
  212. /// <param name="request"></param>
  213. /// <returns></returns>
  214. [HttpPut("update")]
  215. public async Task<bool> Update(TopicUpdateRequest request)
  216. {
  217. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  218. // request.Content = StringUtils.RemoveEmoji(request.Content);
  219. // request.Title = StringUtils.RemoveEmoji(request.Title);
  220. request.UserId = _loginContext.AccountId;
  221. return await _topicService.UpdateAsync(request);
  222. }
  223. }
  224. }