Files
IM_NEW/MessageService.Infrastructure/Reposities/ConversationReposity.cs
T
2026-05-09 17:06:30 +08:00

49 lines
1.5 KiB
C#

using MessageService.Domain.Entities;
using MessageService.Domain.IReposities;
using Microsoft.EntityFrameworkCore;
namespace MessageService.Infrastructure.Reposities
{
public class ConversationReposity : IConversationReposity
{
private readonly MessageDbContext db;
public ConversationReposity(MessageDbContext db)
{
this.db = db;
}
public void Create(Conversation conversation)
{
db.Conversations.Add(conversation);
}
public async Task<IEnumerable<string>> FindAllStreamKeyAsync(Guid userId)
{
return await db.Conversations.Where(x => x.UserId == userId)
.Select(s => s.StreamKey)
.ToListAsync();
}
public async Task<Conversation?> FindByIdAsync(Guid id)
{
return await db.Conversations.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task<IEnumerable<Conversation>> FindByStreamKeyAsync(string streamKey)
{
return await db.Conversations.Where(x => x.StreamKey == streamKey).ToListAsync();
}
public async Task<IEnumerable<Conversation>> FindByTargetIdAsync(Guid targetId)
{
return await db.Conversations.Where(x => x.TargetId == targetId).ToListAsync();
}
public async Task<IEnumerable<Conversation>> FindByUserIdAsync(Guid userId)
{
return await db.Conversations.Where(x => x.UserId == userId).ToListAsync();
}
}
}