TopicController.cs 9.8 KB

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