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 GxPress.Service.Interface.AddressBookGroup;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.Extensions.Logging;
  14. namespace GxPress.Api.AppControllers
  15. {
  16. /// <summary>
  17. /// 通讯录用户信息
  18. /// </summary>
  19. [Route("api/web/address-book-group-user")]
  20. [ApiController]
  21. [Authorize]
  22. public class WebAddressBookGroupUserController : ControllerBase
  23. {
  24. private readonly ILogger<AppVersionController> _logger;
  25. private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository;
  26. private readonly ILoginContext _loginContext;
  27. private readonly IFriendsRepository friendsRepository;
  28. private readonly IAddressBookGroupService addressBookGroupService;
  29. public WebAddressBookGroupUserController(ILogger<AppVersionController> logger,
  30. IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository, IAddressBookGroupService addressBookGroupService)
  31. {
  32. _logger = logger;
  33. _addressBookGroupUserRepository = addressBookGroupUserRepository;
  34. _loginContext = loginContext;
  35. this.friendsRepository = friendsRepository;
  36. this.addressBookGroupService = addressBookGroupService;
  37. }
  38. /// <summary>
  39. /// 删除
  40. /// </summary>
  41. /// <param name="id"></param>
  42. /// <returns></returns>
  43. [HttpDelete("{id}")]
  44. public async Task<bool> Delete(int id)
  45. {
  46. return await _addressBookGroupUserRepository.DeleteAsync(id);
  47. }
  48. /// <summary>
  49. /// 删除自建分组用户
  50. /// </summary>
  51. /// <returns></returns>
  52. [HttpPost("delete")]
  53. public async Task<bool> Deletes(AddressBookGroupUserDeleteRequest request)
  54. {
  55. request.UserId = _loginContext.AccountId;
  56. return await addressBookGroupService.DeleteAddressBookGroupUserAsync(request);
  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. }