using HuanMeng.DotNetCore.Base;
using HuanMeng.MiaoYu.Code.Cache;
using HuanMeng.MiaoYu.Code.Character;
using HuanMeng.MiaoYu.Code.Chat;
using HuanMeng.MiaoYu.Model.Dto.Character;
using HuanMeng.MiaoYu.Model.Dto.Chat;
using HuanMeng.MiaoYu.Model.Dto.Shop;
using HuanMeng.MiaoYu.WebApi.Base;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace HuanMeng.MiaoYu.WebApi.Controllers
{
///
/// 首页聊天
///
[Route("api/[controller]/[action]")]
[ApiController]
public class ChatController : MiaoYuControllerBase
{
private ChatBLL _chatBLL;
///
///
///
///
public ChatController(IServiceProvider _serviceProvider) : base(_serviceProvider)
{
_chatBLL = new ChatBLL(_serviceProvider);
}
///
/// 首页 - 获取角色Id
///
///
[HttpGet]
[AllowAnonymous]
public BaseResponse> GetCharacterIdList()
{
CharacterBLL characterBLL = new CharacterBLL(ServiceProvider);
var obj = characterBLL.GetCharacters();
return obj;
}
///
/// 首页 - 获取角色人物信息
///
///
[HttpGet]
[AllowAnonymous]
public async Task> GetCharacterInfo([FromQuery] RequestCharacterInfo requestCharacterInfo)
{
CharacterBLL characterBLL = new CharacterBLL(ServiceProvider);
var obj = await characterBLL.GetCharacterInfo(requestCharacterInfo);
return obj;
}
///
/// 聊天-获取聊天记录
///
///
///
[HttpGet]
[AllowAnonymous]
public async Task>> GetChatInfo(int characterId)
{
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
var list = await chatBLL.GetChatMessage(characterId);
return list;
}
///
/// 聊天-发送消息接口
///
///
///
[HttpPost]
public async Task> SendMessage([FromBody] RequestMessage requestMessage)
{
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
var obj = await chatBLL.Message(requestMessage.CharacterId, requestMessage.Message);
return obj;
}
///
/// 聊天-删除聊天记录
///
///
///
///
[HttpPost]
[AllowAnonymous]
public async Task> DelChatByIds([FromBody] DelChat delChat)
{
if (delChat.Id == null || delChat.CharacterId == 0)
{
throw new ArgumentNullException();
}
//ChatBLL chatBLL = new ChatBLL(ServiceProvider);
var obj = await _chatBLL.DelChatByIds(delChat.Id, delChat.CharacterId);
return new BaseResponse(ResonseCode.Success, "", obj);
}
///
/// 聊天-清空聊天记录
///
/// 人物id
///
[HttpPost]
[AllowAnonymous]
public async Task> DelChat([FromBody] DelChatList delChatList)
{
//ChatBLL chatBLL = new ChatBLL(ServiceProvider);
var obj = await _chatBLL.DelChat(delChatList.CharacterId);
return new BaseResponse(ResonseCode.Success, "", obj);
}
///
/// 聊天-获取消息页面的聊天记录列表
///
///
[HttpGet]
[AllowAnonymous]
public async Task>> GetChatHistoryList()
{
var obj = await _chatBLL.GetChatHistoryList();
return obj;
}
///
/// 获取记忆卡列表
///
///
[HttpGet]
[AllowAnonymous]
public async Task>> GetMemoryCardInfo()
{
var obj = JsonConvert.DeserializeObject>("[{\"PropId\":\"1\",\"PropName\":\"记忆卡1\",\"ImgUrl\":\"\"},{\"PropId\":\"2\",\"PropName\":\"记忆卡2\",\"ImgUrl\":\"\"}]");
return new BaseResponse>(ResonseCode.Success, "", obj);
}
}
}