OftenContactController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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<System.Collections.Generic.IEnumerable<OftenContactInfo>> GetOftenContactsAsync(OftenContactSearchRequest request)
  43. {
  44. request.UserId = _loginContext.AccountId;
  45. return await _oftenContactService.GetOftenContacts(request);
  46. }
  47. /// <summary>
  48. /// 根据文件ID获取用户和下面的数据
  49. /// </summary>
  50. /// <param name="request"></param>
  51. /// <returns></returns>
  52. [HttpPost("all-list")]
  53. public async Task<System.Collections.Generic.IEnumerable<OftenContactInfo>> GetOftenContactAllAsync(OftenContactSearchRequest request)
  54. {
  55. request.UserId = _loginContext.AccountId;
  56. return await _oftenContactService.GetOftenContactsAll(request);
  57. }
  58. /// <summary>
  59. /// 添加
  60. /// </summary>
  61. /// <param name="request"></param>
  62. /// <returns></returns>
  63. [HttpPost("add")]
  64. public async Task<OftenContactDto> Insert(OftenContactInRequest request)
  65. {
  66. var result = new OftenContactDto();
  67. result = await _oftenContactService.InsertAsync(request, _loginContext.AccountId);
  68. return result;
  69. }
  70. /// <summary>
  71. /// /// 移除文件夹关系
  72. /// </summary>
  73. /// <param name="request"></param>
  74. /// <returns></returns>
  75. [HttpPost("remove")]
  76. public async Task<bool> RemoveOftenContact(OftenContactDeRequest request)
  77. {
  78. return await _repository.RemoveOftenContactAsync(request);
  79. }
  80. /// <summary>
  81. /// 设置置顶
  82. /// </summary>
  83. /// <param name="request"></param>
  84. /// <returns></returns>
  85. [HttpPost("is-top")]
  86. public async Task<bool> SetOftenContactIsTop(OftenContactDeRequest request)
  87. {
  88. return await _repository.SetOftenContactIsTopAsync(request);
  89. }
  90. /// <summary>
  91. /// 移动到文件夹
  92. /// </summary>
  93. /// <param name="request"></param>
  94. /// <returns></returns>
  95. [HttpPost("move")]
  96. public async Task<bool> MoveOftenContactToIndividualGroup(OftenContactUpRequest request)
  97. {
  98. return await _repository.MoveOftenContactToIndividualGroupAsync(request);
  99. }
  100. /// <summary>
  101. /// 删除聊天界面
  102. /// </summary>
  103. /// <param name="oftenContactIds"></param>
  104. /// <returns></returns>
  105. [HttpPost("delete")]
  106. public async Task<bool> DeleteAsync(OftenContactsDeRequest oftenContactIds)
  107. {
  108. return await _repository.DeleteAsync(oftenContactIds.OftenContactIds);
  109. }
  110. /// <summary>
  111. /// 搜索单聊
  112. /// </summary>
  113. /// <param name="keyWord"></param>
  114. /// <returns></returns>
  115. [HttpGet("search/{keyWord}")]
  116. public async Task<IEnumerable<ChatSearchResult>> GetChatSearchAsync(string keyWord)
  117. {
  118. var result = new List<ChatSearchResult>();
  119. result.AddRange(await chatSearchService.GetChatFolderNameSearchAsync(keyWord, _loginContext.AccountId));
  120. result.AddRange(await chatSearchService.GetGroupChatNameSearchAsync(keyWord, _loginContext.AccountId));
  121. result.AddRange(await chatSearchService.GetChatSearchAsync(keyWord, _loginContext.AccountId));
  122. result.AddRange(await chatSearchService.GetFriendUserInfoResult(keyWord, _loginContext.AccountId));
  123. return result;
  124. }
  125. }
  126. }