AddressBookGroupUserController.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Datory;
  5. using GxPress.Auth;
  6. using GxPress.Repository.Interface;
  7. using GxPress.Repository.Interface.Friends;
  8. using GxPress.Request.AddressBookGroupUser;
  9. using GxPress.Result.AddressBookGroupUser;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.Extensions.Logging;
  13. namespace GxPress.Api.AppControllers
  14. {
  15. /// <summary>
  16. /// 通讯录用户信息
  17. /// </summary>
  18. [Route("api/web/address-book-group-user")]
  19. [ApiController]
  20. [Authorize]
  21. public class WebAddressBookGroupUserController : ControllerBase
  22. {
  23. private readonly ILogger<AppVersionController> _logger;
  24. private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
  25. private readonly ILoginContext _loginContext;
  26. private readonly IFriendsRepository friendsRepository;
  27. public WebAddressBookGroupUserController(ILogger<AppVersionController> logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository)
  28. {
  29. _logger = logger;
  30. _addressBookGroupUserRepository = addressBookGroupUserRepository;
  31. _loginContext = loginContext;
  32. this.friendsRepository = friendsRepository;
  33. }
  34. /// <summary>
  35. /// 删除
  36. /// </summary>
  37. /// <param name="id"></param>
  38. /// <returns></returns>
  39. [HttpDelete("{id}")]
  40. public async Task<bool> Delete(int id)
  41. {
  42. return await _addressBookGroupUserRepository.DeleteAsync(id);
  43. }
  44. /// <summary>
  45. /// 删除自建分组用户
  46. /// </summary>
  47. /// <returns></returns>
  48. [HttpPost("delete")]
  49. public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
  50. {
  51. if (await _addressBookGroupUserRepository.DeletesAsync(request.Ids))
  52. {
  53. var model = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids));
  54. return await friendsRepository.DeleteAsync(model.Select(n => n.UserId), _loginContext.AccountId);
  55. }
  56. return false;
  57. }
  58. /// <summary>
  59. /// 获取
  60. /// </summary>
  61. /// <param name="request"></param>
  62. /// <returns></returns>
  63. [HttpPost("list")]
  64. public async Task<AddressBookGroupUserListResult> GetAddressBookGroupUserList(
  65. AddressBookGroupUserSearchRequest request)
  66. {
  67. var userId = _loginContext.AccountId;
  68. return await _addressBookGroupUserRepository.GetAddressBookGroupUserListAsync(request, userId);
  69. }
  70. /// <summary>
  71. /// 添加
  72. /// </summary>
  73. /// <param name="request"></param>
  74. /// <returns></returns>
  75. [HttpPost("add")]
  76. public async Task<bool> Insert(AddressBookGroupUserInRequest request)
  77. {
  78. if (await _addressBookGroupUserRepository.InsertAsync(request))
  79. {
  80. return await friendsRepository.UpdateAddressBookGroupId(request.UserId, _loginContext.AccountId, request.AddressBookGroupId);
  81. }
  82. return false;
  83. }
  84. /// <summary>
  85. /// 移动分组成员
  86. /// </summary>
  87. /// /// <param name="request"></param>
  88. /// <returns></returns>
  89. [HttpPost("move")]
  90. public async Task<bool> AddressBookGroupUserMove(AddressBookGroupUserMoveRequest request)
  91. {
  92. return await _addressBookGroupUserRepository.AddressBookGroupUserMoveAsync(request);
  93. }
  94. }
  95. }