add(conversationSerivice):后端新增消息会话服务add(main):完善主面板
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IM_API.Services
|
||||
{
|
||||
public class ConversationService : IConversationService
|
||||
{
|
||||
private readonly ImContext _context;
|
||||
public ConversationService(ImContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
#region 删除用户会话
|
||||
public async Task<bool> ClearConversationsAsync(int userId)
|
||||
{
|
||||
await _context.Conversations.Where(x => x.UserId == userId).ExecuteDeleteAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#region 获取用户会话列表
|
||||
public async Task<List<Conversation>> GetConversationsAsync(int userId)
|
||||
{
|
||||
return await _context.Conversations.Where(x => x.UserId == userId)
|
||||
.ToListAsync();
|
||||
}
|
||||
#endregion
|
||||
#region 删除单个会话
|
||||
public async Task<bool> DeleteConversationAsync(int conversationId)
|
||||
{
|
||||
var conversation = await _context.Conversations.FirstOrDefaultAsync(x => x.Id == conversationId);
|
||||
if (conversation == null) throw new BaseException(CodeDefine.CONVERSATION_NOT_FOUND);
|
||||
_context.Conversations.Remove(conversation);
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user