using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Repository.Interface;
using GxPress.Request.App.OftenContact;
using GxPress.Result.App.OftenContact;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using GxPress.Service.Interface.OftenContact;
using System.Collections.Generic;
using GxPress.Result.Chat;
using GxPress.Service.Interface.Chat;
namespace GxPress.Api.AppControllers
{
///
/// 好友
///
[Route("api/app/often-contact")]
[ApiController]
[Authorize]
public partial class OftenContactController : ControllerBase
{
private readonly ILogger _logger;
private readonly IOftenContactRepository _repository;
private readonly ILoginContext _loginContext;
private readonly IOftenContactService _oftenContactService;
private readonly IChatSearchService chatSearchService;
public OftenContactController(ILogger logger, IOftenContactRepository repository, ILoginContext loginContext, IOftenContactService oftenContactService, IChatSearchService chatSearchService)
{
_logger = logger;
_repository = repository;
_loginContext = loginContext;
_oftenContactService = oftenContactService;
this.chatSearchService = chatSearchService;
}
///
/// 根据文件ID获取用户和下面的数据
///
///
///
[HttpPost("list")]
public async Task> GetOftenContactsAsync(OftenContactSearchRequest request)
{
request.UserId = _loginContext.AccountId;
return await _oftenContactService.GetOftenContacts(request);
}
///
/// 获取聊天界面和验证最新时间
///
///
///
[HttpGet("list/{individualGroupId}")]
public async Task GetOftenContactInfoGenericResult(int individualGroupId)
{
var request = new OftenContactSearchRequest()
{
UserId = _loginContext.AccountId,
IndividualGroupId = individualGroupId
};
return await _oftenContactService.GetOftenContactInfoGenericResult(request);
}
///
/// 根据文件ID获取用户和下面的数据
///
///
///
[HttpPost("all-list")]
public async Task> GetOftenContactAllAsync(OftenContactSearchRequest request)
{
request.UserId = _loginContext.AccountId;
return await _oftenContactService.GetOftenContactsAll(request);
}
///
/// 添加
///
///
///
[HttpPost("add")]
public async Task Insert(OftenContactInRequest request)
{
var result = new OftenContactDto();
result = await _oftenContactService.InsertAsync(request, _loginContext.AccountId);
return result;
}
///
/// /// 移除文件夹关系
///
///
///
[HttpPost("remove")]
public async Task RemoveOftenContact(OftenContactDeRequest request)
{
return await _repository.RemoveOftenContactAsync(request);
}
///
/// 设置置顶
///
///
///
[HttpPost("is-top")]
public async Task SetOftenContactIsTop(OftenContactDeRequest request)
{
return await _repository.SetOftenContactIsTopAsync(request);
}
///
/// 移动到文件夹
///
///
///
[HttpPost("move")]
public async Task MoveOftenContactToIndividualGroup(OftenContactUpRequest request)
{
return await _repository.MoveOftenContactToIndividualGroupAsync(request);
}
///
/// 删除聊天界面
///
///
///
[HttpPost("delete")]
public async Task DeleteAsync(OftenContactsDeRequest oftenContactIds)
{
return await _repository.DeleteAsync(oftenContactIds.OftenContactIds);
}
///
/// 搜索单聊
///
///
///
[HttpGet("search/{keyWord}")]
public async Task> GetChatSearchAsync(string keyWord)
{
var result = new List();
//搜索文件夹
result.AddRange(await chatSearchService.GetChatFolderNameSearchAsync(keyWord, _loginContext.AccountId));
//群聊
result.AddRange(await chatSearchService.GetGroupChatNameSearchAsync(keyWord, _loginContext.AccountId));
//单聊
result.AddRange(await chatSearchService.GetChatSearchAsync(keyWord, _loginContext.AccountId));
//好友
result.AddRange(await chatSearchService.GetFriendUserInfoResult(keyWord, _loginContext.AccountId));
return result;
}
}
}