using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Datory; using GxPress.Auth; using GxPress.Repository.Interface; using GxPress.Repository.Interface.Friends; using GxPress.Request.AddressBookGroupUser; using GxPress.Result.AddressBookGroupUser; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace GxPress.Api.AppControllers { /// /// 通讯录用户信息 /// [Route("api/web/address-book-group-user")] [ApiController] [Authorize] public class WebAddressBookGroupUserController : ControllerBase { private readonly ILogger _logger; private readonly IAddressBookGroupUserRepository _addressBookGroupUserRepository; private readonly ILoginContext _loginContext; private readonly IFriendsRepository friendsRepository; public WebAddressBookGroupUserController(ILogger logger, IAddressBookGroupUserRepository addressBookGroupUserRepository, ILoginContext loginContext, IFriendsRepository friendsRepository) { _logger = logger; _addressBookGroupUserRepository = addressBookGroupUserRepository; _loginContext = loginContext; this.friendsRepository = friendsRepository; } /// /// 删除 /// /// /// [HttpDelete("{id}")] public async Task Delete(int id) { return await _addressBookGroupUserRepository.DeleteAsync(id); } /// /// 删除自建分组用户 /// /// [HttpPost("delete")] public async Task Deletes(AddressBookGroupUserDeleteRequest request) { if (await _addressBookGroupUserRepository.DeletesAsync(request.Ids)) { var model = await _addressBookGroupUserRepository.GetAllAsync(Q.WhereIn(nameof(Entity.AddressBookGroupUser.Id), request.Ids)); return await friendsRepository.DeleteAsync(model.Select(n => n.UserId), _loginContext.AccountId); } return false; } /// /// 获取 /// /// /// [HttpPost("list")] public async Task GetAddressBookGroupUserList( AddressBookGroupUserSearchRequest request) { var userId = _loginContext.AccountId; return await _addressBookGroupUserRepository.GetAddressBookGroupUserListAsync(request, userId); } /// /// 添加 /// /// /// [HttpPost("add")] public async Task Insert(AddressBookGroupUserInRequest request) { if (await _addressBookGroupUserRepository.InsertAsync(request)) { return await friendsRepository.UpdateAddressBookGroupId(request.UserId, _loginContext.AccountId, request.AddressBookGroupId); } return false; } /// /// 移动分组成员 /// /// /// /// [HttpPost("move")] public async Task AddressBookGroupUserMove(AddressBookGroupUserMoveRequest request) { return await _addressBookGroupUserRepository.AddressBookGroupUserMoveAsync(request); } } }