AddressBookGroupController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/app/address-book-group")]
  18. [ApiController]
  19. [Authorize]
  20. public class AddressBookGroupController : ControllerBase
  21. {
  22. private readonly ILogger<AddressBookGroupController> _logger;
  23. private readonly IAddressBookGroupRepository _addressBookGroupRepository;
  24. private readonly IAddressBookGroupService addressBookGroupService;
  25. private readonly ILoginContext _loginContext;
  26. public AddressBookGroupController(ILogger<AddressBookGroupController> logger, IAddressBookGroupRepository addressBookGroupRepository, ILoginContext loginContext, IAddressBookGroupService addressBookGroupService)
  27. {
  28. _logger = logger;
  29. _addressBookGroupRepository = addressBookGroupRepository;
  30. _loginContext = loginContext;
  31. this.addressBookGroupService = addressBookGroupService;
  32. }
  33. /// <summary>
  34. /// 删除
  35. /// </summary>
  36. /// <param name="id"></param>
  37. /// <returns></returns>
  38. [HttpDelete("{id}")]
  39. public async Task<bool> Delete(int id)
  40. {
  41. return await _addressBookGroupRepository.DeleteAsync(id);
  42. }
  43. /// <summary>
  44. /// 修改
  45. /// </summary>
  46. /// <param name="request"></param>
  47. /// <returns></returns>
  48. [HttpPost("update")]
  49. public async Task<bool> Update(AddressBookGroupUpRequest request)
  50. {
  51. return await _addressBookGroupRepository.UpdateAsync(request);
  52. }
  53. /// <summary>
  54. /// 获取
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpPost("list")]
  58. public async Task<IEnumerable<AddressBookGroupResult>> GetAddressBookGroupList(AddressBookGroupSearchRequest request)
  59. {
  60. request.UserId = _loginContext.AccountId;
  61. return await _addressBookGroupRepository.GetAddressBookGroupListAsync(request);
  62. }
  63. /// <summary>
  64. /// 添加
  65. /// </summary>
  66. /// <param name="request"></param>
  67. /// <returns></returns>
  68. [HttpPost("add")]
  69. public async Task<Entity.AddressBookGroup> Insert(AddressBookGroupInRequest request)
  70. {
  71. request.UserId = _loginContext.AccountId;
  72. return await addressBookGroupService.InsertAsync(request);
  73. }
  74. /// <summary>
  75. /// 获取用户通讯录组
  76. /// </summary>
  77. /// <returns></returns>
  78. [HttpPost("list-group")]
  79. public async Task<AddressBookListResult> GetAddressBookList()
  80. {
  81. AddressBookListRequest request = new AddressBookListRequest { UserId = _loginContext.AccountId };
  82. return await _addressBookGroupRepository.GetAddressBookListAsync(request);
  83. }
  84. /// <summary>
  85. /// 添加联系人
  86. /// </summary>
  87. /// <param name="request"></param>
  88. /// <returns></returns>
  89. [HttpPost("add-address-book-user")]
  90. public async Task<bool> InsertAddressBookUser(AddressBookInUserRequest request)
  91. {
  92. return await _addressBookGroupRepository.InsertAddressBookUserAsync(request);
  93. }
  94. /// <summary>
  95. /// 自建分组移动排序
  96. /// </summary>
  97. /// <param name="request"></param>
  98. /// <returns></returns>
  99. [HttpPost("sort")]
  100. public async Task<bool> Sort(AddressBookGroupSortRequest request)
  101. {
  102. request.UserId = _loginContext.AccountId;
  103. return await _addressBookGroupRepository.SortAsync(request);
  104. }
  105. }
  106. }