Broker implementation updated.
This commit is contained in:
@ -0,0 +1,49 @@
|
||||
using MessengerApi.Factories;
|
||||
using MessengerBroker.Configuration.Model;
|
||||
using MessengerBroker.Factories;
|
||||
using MessengerBroker.Model.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MessengerBroker.Handlers.Endpoint
|
||||
{
|
||||
public class MessagesEndpointHandler
|
||||
{
|
||||
private readonly BrokerConfiguration configuration;
|
||||
private readonly BrokerDbContextFactory brokerDbContextFactory;
|
||||
private readonly DbContextFactory messengerDbContextFactory;
|
||||
|
||||
public MessagesEndpointHandler(
|
||||
BrokerConfiguration configuration,
|
||||
BrokerDbContextFactory brokerDbContextFactory,
|
||||
DbContextFactory messengerDbContextFactory)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.brokerDbContextFactory = brokerDbContextFactory;
|
||||
this.messengerDbContextFactory = messengerDbContextFactory;
|
||||
}
|
||||
|
||||
public async Task<Messages.MessagesResponse> GetMessages(Messages.MessagesRequest request)
|
||||
{
|
||||
using var broCtx = this.brokerDbContextFactory.CreateDbContext();
|
||||
|
||||
var brokerMessageIdCollection = broCtx.Messages
|
||||
.Where(x => x.BrokerId == request.OwnerBrokerId)
|
||||
.Select(x => x.Id)
|
||||
.Take(1000)
|
||||
.ToArray();
|
||||
|
||||
using var apiCtx = this.messengerDbContextFactory.CreateDbContext();
|
||||
|
||||
var messages = apiCtx.Messages
|
||||
.Where(x => x.CreatedUtc >= request.SinceUtc && brokerMessageIdCollection.Contains(x.Id))
|
||||
.ToArray();
|
||||
|
||||
var response = new Messages.MessagesResponse
|
||||
{
|
||||
Messages = messages
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user