OftenContactController.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System.Threading.Tasks;
  2. using GxPress.Auth;
  3. using GxPress.Repository.Interface;
  4. using GxPress.Request.App.OftenContact;
  5. using GxPress.Result.App.OftenContact;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using GxPress.Service.Interface.OftenContact;
  10. using System.Collections.Generic;
  11. using GxPress.Result.Chat;
  12. using GxPress.Service.Interface.Chat;
  13. namespace GxPress.Api.AppControllers
  14. {
  15. /// <summary>
  16. /// 好友
  17. /// </summary>
  18. [Route("api/app/often-contact")]
  19. [ApiController]
  20. [Authorize]
  21. public partial class OftenContactController : ControllerBase
  22. {
  23. private readonly ILogger<OftenContactController> _logger;
  24. private readonly IOftenContactRepository _repository;
  25. private readonly ILoginContext _loginContext;
  26. private readonly IOftenContactService _oftenContactService;
  27. private readonly IChatSearchService chatSearchService;
  28. public OftenContactController(ILogger<OftenContactController> logger, IOftenContactRepository repository, ILoginContext loginContext, IOftenContactService oftenContactService, IChatSearchService chatSearchService)
  29. {
  30. _logger = logger;
  31. _repository = repository;
  32. _loginContext = loginContext;
  33. _oftenContactService = oftenContactService;
  34. this.chatSearchService = chatSearchService;
  35. }
  36. /// <summary>
  37. /// 根据文件ID获取用户和下面的数据
  38. /// </summary>
  39. /// <param name="request"></param>
  40. /// <returns></returns>
  41. [HttpPost("list")]
  42. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAsync(OftenContactSearchRequest request)
  43. {
  44. request.UserId = _loginContext.AccountId;
  45. return await _oftenContactService.GetOftenContacts(request);
  46. }
  47. /// <summary>
  48. /// 获取聊天界面和验证最新时间
  49. /// </summary>
  50. /// <param name="individualGroupId"></param>
  51. /// <returns></returns>
  52. [HttpGet("list/{individualGroupId}")]
  53. public async Task<OftenContactInfoGenericResult> GetOftenContactInfoGenericResult(int individualGroupId)
  54. {
  55. var request = new OftenContactSearchRequest()
  56. {
  57. UserId = _loginContext.AccountId,
  58. IndividualGroupId = individualGroupId
  59. };
  60. return await _oftenContactService.GetOftenContactInfoGenericResult(request);
  61. }
  62. /// <summary>
  63. /// 根据文件ID获取用户和下面的数据
  64. /// </summary>
  65. /// <param name="request"></param>
  66. /// <returns></returns>
  67. [HttpPost("all-list")]
  68. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactAllAsync(OftenContactSearchRequest request)
  69. {
  70. request.UserId = _loginContext.AccountId;
  71. return await _oftenContactService.GetOftenContactsAll(request);
  72. }
  73. /// <summary>
  74. /// 添加
  75. /// </summary>
  76. /// <param name="request"></param>
  77. /// <returns></returns>
  78. [HttpPost("add")]
  79. public async Task<OftenContactDto> Insert(OftenContactInRequest request)
  80. {
  81. var result = new OftenContactDto();
  82. result = await _oftenContactService.InsertAsync(request, _loginContext.AccountId);
  83. return result;
  84. }
  85. /// <summary>
  86. /// /// 移除文件夹关系
  87. /// </summary>
  88. /// <param name="request"></param>
  89. /// <returns></returns>
  90. [HttpPost("remove")]
  91. public async Task<bool> RemoveOftenContact(OftenContactDeRequest request)
  92. {
  93. return await _repository.RemoveOftenContactAsync(request);
  94. }
  95. /// <summary>
  96. /// 设置置顶
  97. /// </summary>
  98. /// <param name="request"></param>
  99. /// <returns></returns>
  100. [HttpPost("is-top")]
  101. public async Task<bool> SetOftenContactIsTop(OftenContactDeRequest request)
  102. {
  103. return await _repository.SetOftenContactIsTopAsync(request);
  104. }
  105. /// <summary>
  106. /// 移动到文件夹
  107. /// </summary>
  108. /// <param name="request"></param>
  109. /// <returns></returns>
  110. [HttpPost("move")]
  111. public async Task<bool> MoveOftenContactToIndividualGroup(OftenContactUpRequest request)
  112. {
  113. return await _repository.MoveOftenContactToIndividualGroupAsync(request);
  114. }
  115. /// <summary>
  116. /// 删除聊天界面
  117. /// </summary>
  118. /// <param name="oftenContactIds"></param>
  119. /// <returns></returns>
  120. [HttpPost("delete")]
  121. public async Task<bool> DeleteAsync(OftenContactsDeRequest oftenContactIds)
  122. {
  123. return await _repository.DeleteAsync(oftenContactIds.OftenContactIds);
  124. }
  125. /// <summary>
  126. /// 搜索单聊
  127. /// </summary>
  128. /// <param name="keyWord"></param>
  129. /// <returns></returns>
  130. [HttpGet("search/{keyWord}")]
  131. public async Task<IEnumerable<ChatSearchResult>> GetChatSearchAsync(string keyWord)
  132. {
  133. var result = new List<ChatSearchResult>();
  134. //搜索文件夹
  135. result.AddRange(await chatSearchService.GetChatFolderNameSearchAsync(keyWord, _loginContext.AccountId));
  136. //群聊
  137. result.AddRange(await chatSearchService.GetGroupChatNameSearchAsync(keyWord, _loginContext.AccountId));
  138. //单聊
  139. result.AddRange(await chatSearchService.GetChatSearchAsync(keyWord, _loginContext.AccountId));
  140. //好友
  141. result.AddRange(await chatSearchService.GetFriendUserInfoResult(keyWord, _loginContext.AccountId));
  142. return result;
  143. }
  144. }
  145. }