AddressBookGroupController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Repository.Interface;
  5. using GxPress.Request.AddressBookGroup;
  6. using GxPress.Result.AddressBook;
  7. using GxPress.Result.AddressBookGroup;
  8. using GxPress.Service.Interface.AddressBookGroup;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.Extensions.Logging;
  12. namespace GxPress.Api.AppControllers
  13. {
  14. /// <summary>
  15. /// 用户通讯录组
  16. /// </summary>
  17. [Route("api/web/address-book-group")]
  18. [ApiController]
  19. [Authorize]
  20. public class WebAddressBookGroupController : ControllerBase
  21. {
  22. private readonly ILogger<AddressBookGroupController> _logger;
  23. private readonly IAddressBookGroupRepository _addressBookGroupRepository;
  24. private readonly ILoginContext _loginContext;
  25. private readonly IAddressBookGroupService addressBookGroupService;
  26. public WebAddressBookGroupController(ILogger<AddressBookGroupController> logger,
  27. IAddressBookGroupRepository addressBookGroupRepository,
  28. ILoginContext loginContext,IAddressBookGroupService addressBookGroupService)
  29. {
  30. _logger = logger;
  31. _addressBookGroupRepository = addressBookGroupRepository;
  32. _loginContext = loginContext;
  33. this.addressBookGroupService=addressBookGroupService;
  34. }
  35. /// <summary>
  36. /// 删除
  37. /// </summary>
  38. /// <param name="id"></param>
  39. /// <returns></returns>
  40. [HttpDelete("{id}")]
  41. public async Task<bool> Delete(int id)
  42. {
  43. return await _addressBookGroupRepository.DeleteAsync(id);
  44. }
  45. /// <summary>
  46. /// 修改
  47. /// </summary>
  48. /// <param name="request"></param>
  49. /// <returns></returns>
  50. [HttpPost("update")]
  51. public async Task<bool> Update(AddressBookGroupUpRequest request)
  52. {
  53. return await _addressBookGroupRepository.UpdateAsync(request);
  54. }
  55. /// <summary>
  56. /// 获取
  57. /// </summary>
  58. /// <returns></returns>
  59. [HttpPost("list")]
  60. public async Task<IEnumerable<AddressBookGroupResult>> GetAddressBookGroupList(AddressBookGroupSearchRequest request)
  61. {
  62. request.UserId = _loginContext.AccountId;
  63. return await _addressBookGroupRepository.GetAddressBookGroupListAsync(request);
  64. }
  65. /// <summary>
  66. /// 添加
  67. /// </summary>
  68. /// <param name="request"></param>
  69. /// <returns></returns>
  70. [HttpPost("add")]
  71. public async Task<Entity.AddressBookGroup> Insert(AddressBookGroupInRequest request)
  72. {
  73. request.UserId = _loginContext.AccountId;
  74. return await addressBookGroupService.InsertAsync(request);
  75. }
  76. /// <summary>
  77. /// 获取用户通讯录组
  78. /// </summary>
  79. /// <returns></returns>
  80. [HttpPost("list-group")]
  81. public async Task<AddressBookListResult> GetAddressBookList()
  82. {
  83. AddressBookListRequest request = new AddressBookListRequest { UserId = _loginContext.AccountId };
  84. return await _addressBookGroupRepository.GetAddressBookListAsync(request);
  85. }
  86. /// <summary>
  87. /// 添加联系人
  88. /// </summary>
  89. /// <param name="request"></param>
  90. /// <returns></returns>
  91. [HttpPost("add-address-book-user")]
  92. public async Task<bool> InsertAddressBookUser(AddressBookInUserRequest request)
  93. {
  94. return await _addressBookGroupRepository.InsertAddressBookUserAsync(request);
  95. }
  96. /// <summary>
  97. /// 自建分组移动排序
  98. /// </summary>
  99. /// <param name="request"></param>
  100. /// <returns></returns>z
  101. [HttpPost("sort")]
  102. public async Task<bool> Sort(AddressBookGroupSortRequest request)
  103. {
  104. request.UserId = _loginContext.AccountId;
  105. return await _addressBookGroupRepository.SortAsync(request);
  106. }
  107. }
  108. }