WebTopicController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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.WebControllers
  18. {
  19. /// <summary>
  20. /// web话题
  21. /// </summary>
  22. [Route("api/web/topic")]
  23. [ApiController]
  24. [Authorize]
  25. public class WebTopicController : Controller
  26. {
  27. private readonly ILogger<WebTopicController> _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 WebTopicController(ILogger<WebTopicController> 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. [AllowAnonymous]
  93. public async Task<PagedList<TopicListPageResult>> GetTopicListPage(TopicPageSearchRequest request)
  94. {
  95. request.UserId = _loginContext.AccountId;
  96. return await _topicService.GetTopicPageAsync(request);
  97. }
  98. /// <summary>
  99. /// Web小组话题分页列表
  100. /// </summary>
  101. /// <param name="request"></param>
  102. /// <returns></returns>
  103. [HttpPost("user-list-page")]
  104. public async Task<PagedList<TopicListPageResult>> GetTopicByGroupAsync(TopicPageSearchRequest request)
  105. {
  106. request.UserId = _loginContext.AccountId;
  107. return await _topicService.GetTopicByGroupAsync(request);
  108. }
  109. /// <summary>
  110. ///最新 小组话题分页列表
  111. /// </summary>
  112. /// <param name="request"></param>
  113. /// <returns></returns>
  114. [HttpPost("page")]
  115. [AllowAnonymous]
  116. public async Task<PagedList<TopicListPageResult>> GetGroupTopicPageAsync(TopicDetailListRequest request)
  117. {
  118. request.UserId = _loginContext.AccountId;
  119. return await _topicService.GetGroupTopicPageAsync(request);
  120. }
  121. /// <summary>
  122. /// 获取用户话题分组
  123. /// </summary>
  124. /// <returns></returns>
  125. [HttpGet("group")]
  126. public async Task<IEnumerable<TopicGroup>> GetTopicGroups()
  127. {
  128. return await topicGroupService.GetTopicGroupsAsync(_loginContext.AccountId);
  129. }
  130. /// <summary>
  131. /// 获取用户话题分组集合
  132. /// </summary>
  133. /// <returns></returns>
  134. [HttpGet("list-group")]
  135. public async Task<IEnumerable<TopicGroup>> GetListTopicGroupsAsync()
  136. {
  137. return await topicGroupService.GetListTopicGroupsAsync(_loginContext.AccountId);
  138. }
  139. /// <summary>
  140. /// 添加话题分组
  141. /// </summary>
  142. /// <param name="request"></param>
  143. /// <returns></returns>
  144. [HttpPut("add-group")]
  145. public async Task<AppResultJson<TopicGroup>> InsertTopicGroup(TopicGroupInRequest request)
  146. {
  147. var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
  148. return await _topicGroupRepository.InsertAsync(topicGroup);
  149. }
  150. /// <summary>
  151. /// 修改分组名称
  152. /// </summary>
  153. /// <param name="request"></param>
  154. /// <returns></returns>
  155. [HttpPut("update-group")]
  156. public async Task<bool> UpdateGroup(TopicGroupInRequest request)
  157. {
  158. return await _topicGroupRepository.UpdateAsync(request);
  159. }
  160. /// <summary>
  161. /// 根据话题分组Id删除数据
  162. /// </summary>
  163. /// <param name="request"></param>
  164. /// <returns></returns>
  165. [HttpDelete("delete_group")]
  166. public async Task<bool> DeleteTopicGroup([FromBody] TopicGroupDeRequest request)
  167. {
  168. return await _topicService.DeleteTopicGroupAsync(request.Ids);
  169. }
  170. /// <summary>
  171. /// 根据分组ID查询用户
  172. /// </summary>
  173. /// <param name="id"></param>
  174. /// <returns></returns>
  175. [HttpGet("{id}")]
  176. public async Task<PagedList<TopicGroupUserResult>> GetTopicGroupUserById(int id)
  177. {
  178. return await _topicGroupUserRepository.GetTopicGroupUserById(id);
  179. }
  180. /// <summary>
  181. /// 添加话题小组成员
  182. /// </summary>
  183. /// <param name="request"></param>
  184. /// <returns></returns>
  185. [HttpPost("add-group-user")]
  186. public async Task<bool> InsertAsync([FromBody] TopicGroupUserInRequest request)
  187. {
  188. return await _topicService.InsertTopicGroupUserAsync(request.UserIds.Distinct().ToList(), request.TopicGroupId);
  189. }
  190. /// <summary>
  191. /// 根据ID删除话题分组成员
  192. /// </summary>
  193. /// <param name="request"></param>
  194. /// <returns></returns>
  195. [HttpDelete("group-user")]
  196. public async Task<bool> DeleteUser(TopicGroupDeRequest request)
  197. {
  198. return await _topicService.DeleteTopicGroupUserAsync(request.Ids);
  199. }
  200. /// <summary>
  201. /// 排序
  202. /// </summary>
  203. /// <param name="request"></param>
  204. /// <returns></returns>
  205. [HttpPut("sort")]
  206. public async Task<bool> MoveSort(TopicMoveSortRequest request)
  207. {
  208. return await _topicGroupRepository.MoveSortAsync(request.FirstId, request.SecondId, _loginContext.AccountId);
  209. }
  210. /// <summary>
  211. /// 移动到
  212. /// </summary>
  213. /// <param name="request"></param>
  214. /// <returns></returns>
  215. [HttpPut("move")]
  216. public async Task<bool> MoveToGroup(MoveToGroupRequest request)
  217. {
  218. return await _topicService.MoveToGroupAsync(request);
  219. }
  220. /// <summary>
  221. /// 根据分组ID和姓名查询用户
  222. /// </summary>
  223. /// <param name="request"></param>
  224. /// <returns></returns>
  225. [HttpPost("search")]
  226. public async Task<PagedList<TopicGroupUserResult>> SearchTopicGroupUsers(SearchTopicGroupUsersRequest request)
  227. {
  228. return await _topicGroupUserRepository.SearchTopicGroupUsersAsync(request);
  229. }
  230. /// <summary>
  231. /// 删除话题
  232. /// </summary>
  233. /// <param name="id"></param>
  234. /// <returns></returns>
  235. [HttpDelete("{id}")]
  236. public async Task<bool> Delete(int id)
  237. {
  238. return await _topicService.DeleteAsync(id);
  239. }
  240. /// <summary>
  241. /// 修改话题
  242. /// </summary>
  243. /// <param name="request"></param>
  244. /// <returns></returns>
  245. [HttpPut("update")]
  246. public async Task<bool> Update(TopicUpdateRequest request)
  247. {
  248. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  249. // request.Content = StringUtils.RemoveEmoji(request.Content);
  250. // request.Title = StringUtils.RemoveEmoji(request.Title);
  251. request.UserId = _loginContext.AccountId;
  252. return await _topicService.UpdateAsync(request);
  253. }
  254. /// <summary>
  255. /// 删除草稿箱
  256. /// </summary>
  257. /// <param name="groupId"></param>
  258. /// <returns></returns>
  259. [HttpDelete("clear-draft/{groupId}")]
  260. public async Task<bool> ClearDraftAsync(int groupId)
  261. {
  262. return await _topicRepository.ClearDraftAsync(_loginContext.AccountId, groupId);
  263. }
  264. }
  265. }