TopicController.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 IMiddleService _middleService;
  33. public TopicController(ILogger<TopicController> logger, ITopicRepository repository, ILoginContext loginContext,
  34. ITopicService topicService, ITopicGroupRepository topicGroupRepository,
  35. ITopicGroupUserRepository topicGroupUserRepository, IMiddleService middleService)
  36. {
  37. _logger = logger;
  38. _topicRepository = repository;
  39. _loginContext = loginContext;
  40. _topicService = topicService;
  41. _topicGroupRepository = topicGroupRepository;
  42. _topicGroupUserRepository = topicGroupUserRepository;
  43. _middleService = middleService;
  44. }
  45. /// <summary>
  46. /// 添加
  47. /// </summary>
  48. /// <param name="request"></param>
  49. /// <returns></returns>
  50. [HttpPost("add")]
  51. public async Task<bool> Insert(TopicInRequest 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. return await _topicService.InsertTopicAsync(request);
  58. }
  59. /// <summary>
  60. /// 获取话题详情
  61. /// </summary>
  62. /// <param name="request"></param>
  63. /// <returns></returns>
  64. [HttpPost("app-detail")]
  65. public async Task<TopicDetailResult> GetTopicDetailResult(TopicDetailRequest request)
  66. {
  67. request.UserId = _loginContext.AccountId;
  68. var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
  69. return topicDetail;
  70. }
  71. /// <summary>
  72. /// 获取话题详情 web专属
  73. /// </summary>
  74. /// <param name="request"></param>
  75. /// <returns></returns>
  76. [HttpPost("web-app-detail")]
  77. [AllowAnonymous]
  78. public async Task<TopicDetailResult> GetWebTopicDetailResult(TopicDetailRequest request)
  79. {
  80. var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
  81. return topicDetail;
  82. }
  83. /// <summary>
  84. /// app笔记话题分页列表
  85. /// </summary>
  86. /// <param name="request"></param>
  87. /// <returns></returns>
  88. [HttpPost("list-page")]
  89. public async Task<PagedList<TopicListPageResult>> GetTopicListPage(TopicPageSearchRequest request)
  90. {
  91. request.UserId = _loginContext.AccountId;
  92. return await _topicService.GetTopicPageAsync(request);
  93. }
  94. /// <summary>
  95. /// 获取用户话题分组
  96. /// </summary>
  97. /// <returns></returns>
  98. [HttpPost("group")]
  99. public async Task<IEnumerable<TopicGroup>> GetTopicGroups()
  100. {
  101. return await _topicGroupRepository.GetTopicGroupsAsync(_loginContext.AccountId);
  102. }
  103. /// <summary>
  104. /// 添加话题分组
  105. /// </summary>
  106. /// <param name="request"></param>
  107. /// <returns></returns>
  108. [HttpPut("add-group")]
  109. public async Task<bool> InsertTopicGroup(TopicGroupInRequest request)
  110. {
  111. var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
  112. return await _topicGroupRepository.InsertAsync(topicGroup);
  113. }
  114. /// <summary>
  115. /// 修改分组名称
  116. /// </summary>
  117. /// <param name="request"></param>
  118. /// <returns></returns>
  119. [HttpPut("update-group")]
  120. public async Task<bool> UpdateGroup(TopicGroupInRequest request)
  121. {
  122. return await _topicGroupRepository.UpdateAsync(request);
  123. }
  124. /// <summary>
  125. /// 根据话题分组Id删除数据
  126. /// </summary>
  127. /// <param name="request"></param>
  128. /// <returns></returns>
  129. [HttpDelete("delete_group")]
  130. public async Task<bool> DeleteTopicGroup([FromBody] TopicGroupDeRequest request)
  131. {
  132. return await _topicService.DeleteTopicGroupAsync(request.Ids);
  133. }
  134. /// <summary>
  135. /// 根据分组ID查询用户
  136. /// </summary>
  137. /// <param name="id"></param>
  138. /// <returns></returns>
  139. [HttpGet("{id}")]
  140. public async Task<PagedList<TopicGroupUserResult>> GetTopicGroupUserById(int id)
  141. {
  142. return await _topicGroupUserRepository.GetTopicGroupUserById(id);
  143. }
  144. /// <summary>
  145. /// 添加话题小组成员
  146. /// </summary>
  147. /// <param name="request"></param>
  148. /// <returns></returns>
  149. [HttpPost("add-group-user")]
  150. public async Task<bool> InsertAsync([FromBody] TopicGroupUserInRequest request)
  151. {
  152. return await _topicService.InsertTopicGroupUserAsync(request.UserIds.Distinct().ToList(), request.TopicGroupId);
  153. }
  154. /// <summary>
  155. /// 根据ID删除话题分组成员
  156. /// </summary>
  157. /// <param name="request"></param>
  158. /// <returns></returns>
  159. [HttpDelete("group-user")]
  160. public async Task<bool> DeleteUser(TopicGroupDeRequest request)
  161. {
  162. return await _topicService.DeleteTopicGroupUserAsync(request.Ids);
  163. }
  164. /// <summary>
  165. /// 排序
  166. /// </summary>
  167. /// <param name="request"></param>
  168. /// <returns></returns>
  169. [HttpPut("sort")]
  170. public async Task<bool> MoveSort(TopicMoveSortRequest request)
  171. {
  172. return await _topicGroupRepository.MoveSortAsync(request.FirstId, request.SecondId, _loginContext.AccountId);
  173. }
  174. /// <summary>
  175. /// 移动到
  176. /// </summary>
  177. /// <param name="request"></param>
  178. /// <returns></returns>
  179. [HttpPut("move")]
  180. public async Task<bool> MoveToGroup(MoveToGroupRequest request)
  181. {
  182. return await _topicService.MoveToGroupAsync(request);
  183. }
  184. /// <summary>
  185. /// 根据分组ID和姓名查询用户
  186. /// </summary>
  187. /// <param name="request"></param>
  188. /// <returns></returns>
  189. [HttpPost("search")]
  190. public async Task<PagedList<TopicGroupUserResult>> SearchTopicGroupUsers(SearchTopicGroupUsersRequest request)
  191. {
  192. return await _topicGroupUserRepository.SearchTopicGroupUsersAsync(request);
  193. }
  194. /// <summary>
  195. /// 删除话题
  196. /// </summary>
  197. /// <param name="id"></param>
  198. /// <returns></returns>
  199. [HttpDelete("{id}")]
  200. public async Task<bool> Delete(int id)
  201. {
  202. return await _topicService.DeleteAsync(id);
  203. }
  204. /// <summary>
  205. /// 修改话题
  206. /// </summary>
  207. /// <param name="request"></param>
  208. /// <returns></returns>
  209. [HttpPut("update")]
  210. public async Task<bool> Update(TopicUpdateRequest request)
  211. {
  212. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  213. // request.Content = StringUtils.RemoveEmoji(request.Content);
  214. // request.Title = StringUtils.RemoveEmoji(request.Title);
  215. request.UserId = _loginContext.AccountId;
  216. return await _topicService.UpdateAsync(request);
  217. }
  218. /// <summary>
  219. ///最新 小组话题分页列表
  220. /// </summary>
  221. /// <param name="request"></param>
  222. /// <returns></returns>
  223. [HttpPost("page")]
  224. public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
  225. {
  226. request.UserId = _loginContext.AccountId;
  227. return await _topicService.GetGroupTopicPageAsync(request);
  228. }
  229. }
  230. }