WebTopicController.cs 9.7 KB

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