删除聊天记录接口
This commit is contained in:
parent
4fe894fb6f
commit
8db46fb36d
|
|
@ -1,4 +1,6 @@
|
|||
using HuanMeng.DotNetCore.Base;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -24,13 +26,32 @@ namespace HuanMeng.MiaoYu.Code.Chat
|
|||
/// <returns></returns>
|
||||
public async Task<bool> DelChatByIds(List<int> id,int characterId)
|
||||
{
|
||||
var chatsToDelete = Dao.daoDbMiaoYu.context.T_Chat.Where(t => id.Contains(t.Id)).ToList();
|
||||
var chatsToDelete = await Dao.daoDbMiaoYu.context.T_Chat.Where(t => id.Contains(t.Id)).ToListAsync();
|
||||
if (chatsToDelete.Count <= 0)
|
||||
{
|
||||
throw new Exception("");
|
||||
}
|
||||
var chatList = chatsToDelete.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.IsDel == false).ToList();
|
||||
Dao.daoDbMiaoYu.context.T_Chat.RemoveRange(chatList);
|
||||
var chatList = chatsToDelete.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.IsDel == false).ToList();
|
||||
if (chatList.Count > 0)
|
||||
{
|
||||
chatList.ForEach(t=>t.IsDel = true);
|
||||
}
|
||||
Dao.daoDbMiaoYu.context.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空聊天记录
|
||||
/// </summary>
|
||||
/// <param name="characterId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DelChat(int characterId)
|
||||
{
|
||||
var tempList = await Dao.daoDbMiaoYu.context.T_Chat.Where(t=>t.UserId == _UserId && t.CharacterId==characterId && t.IsDel == false).ToListAsync();
|
||||
if (tempList.Count > 0)
|
||||
{
|
||||
tempList.ForEach(t => t.IsDel = true);
|
||||
}
|
||||
Dao.daoDbMiaoYu.context.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,4 +96,31 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home
|
|||
{
|
||||
public List<ChatMessageDto> ChatList { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除聊天
|
||||
/// </summary>
|
||||
public class DelChat
|
||||
{
|
||||
/// <summary>
|
||||
/// 聊天记录id
|
||||
/// </summary>
|
||||
public List<int> id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人物id
|
||||
/// </summary>
|
||||
public int characterId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空聊天记录
|
||||
/// </summary>
|
||||
public class DelChatList
|
||||
{
|
||||
/// <summary>
|
||||
/// 人物id
|
||||
/// </summary>
|
||||
public int characterId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,18 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace HuanMeng.MiaoYu.WebApi.Controllers
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 首页聊天
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ChatController : MiaoYuControllerBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_serviceProvider"></param>
|
||||
public ChatController(IServiceProvider _serviceProvider) : base(_serviceProvider)
|
||||
{
|
||||
}
|
||||
|
|
@ -22,6 +29,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<CharacterInfoDto>> GetCharacterInfo()
|
||||
{
|
||||
var obj = JsonConvert.DeserializeObject<CharacterInfoDto>("{\"Icon\":\"\",\"Intimacy\":10,\"CharacterId\":2,\"CharacterName\":\"许荷姻\",\"Gender\":1,\"LookCount\":2,\"BgUrl\":\"\",\"Biography\":\"你那商业联姻得来的妻子,原本的天才女孩,聪明伶俐,生的漂亮、端庄,不知贵圈多少人梦寐以求的存在。\",\"Prologue\":\"坐在轮椅上,眼神平静的看着你,语气也同样平静)你回来了。饭菜在桌上,我刚刚热了。(说到这,又垂下眸子道)我还做了碗醒酒汤,记得喝\",\"Label\":[{\"Id\":1,\"Name\":\"美女\"},{\"Id\":2,\"Name\":\"二次元\"}],\"RemainingChatCount\":1}");
|
||||
|
|
@ -35,6 +43,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<ChatListDto>> GetChatInfo()
|
||||
{
|
||||
var obj = JsonConvert.DeserializeObject<ChatListDto>("{\"ChatList\":[{\"Id\":\"1\",\"Role\":\"user\",\"Content\":\"Hello, how are you?\",\"Timestamp\":\"2022-03-01 12:00:00 \",\"MessageType\":0,\"UserIcon\":\"\"},{\"Id\":\"2\",\"Role\":\"assistant\",\"Content\":\"I'm fine, thanks!\",\"Timestamp\":\"2022-03-01 12:05:00 \",\"UserIcon\":\"\"}]}");
|
||||
|
|
@ -44,18 +53,33 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|||
/// <summary>
|
||||
/// 删除聊天记录
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="characterId"></param>
|
||||
/// <param name="delChat"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<bool>> DelChatByIds(List<int> id, int characterId)
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<bool>> DelChatByIds([FromBody] DelChat delChat)
|
||||
{
|
||||
if(id == null || characterId == 0)
|
||||
if (delChat.id == null || delChat.characterId == 0)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
||||
var obj =await chatBLL.DelChatByIds(id, characterId);
|
||||
var obj = await chatBLL.DelChatByIds(delChat.id, delChat.characterId);
|
||||
return new BaseResponse<bool>(ResonseCode.Success, "", obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空聊天记录
|
||||
/// </summary>
|
||||
/// <param name="characterId">人物id</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<bool>> DelChat([FromBody] DelChatList delChatList)
|
||||
{
|
||||
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
||||
var obj = await chatBLL.DelChat(delChatList.characterId);
|
||||
return new BaseResponse<bool>(ResonseCode.Success, "", obj);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user