Skip to content

Commit

Permalink
fix: query for youngest relationship when sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tnotheis committed Apr 24, 2024
1 parent ad7b421 commit 2ef0ab7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Backbone.Modules.Messages.Application.Infrastructure.Persistence.Repos

public interface IRelationshipsRepository
{
Task<Relationship?> FindRelationship(IdentityAddress identityA, IdentityAddress identityB, CancellationToken cancellationToken);
Task<Relationship?> FindYoungestRelationship(IdentityAddress identityA, IdentityAddress identityB, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private async Task<List<RecipientInformation>> ValidateRecipients(SendMessageCom

foreach (var recipientDto in request.Recipients)
{
var relationshipBetweenSenderAndRecipient = await _relationshipsRepository.FindRelationship(sender, recipientDto.Address, cancellationToken);
var relationshipBetweenSenderAndRecipient = await _relationshipsRepository.FindYoungestRelationship(sender, recipientDto.Address, cancellationToken);

if (relationshipBetweenSenderAndRecipient == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.EntityFrameworkCore;

namespace Backbone.Modules.Messages.Infrastructure.Persistence.Database.Repository;

public class RelationshipsRepository : IRelationshipsRepository
{
private readonly MessagesDbContext _dbContext;
Expand All @@ -24,11 +25,12 @@ public RelationshipsRepository(MessagesDbContext dbContext)
.FirstOrDefaultAsync();
}

public Task<Relationship?> FindRelationship(IdentityAddress sender, IdentityAddress recipient, CancellationToken cancellationToken)
public Task<Relationship?> FindYoungestRelationship(IdentityAddress sender, IdentityAddress recipient, CancellationToken cancellationToken)
{
return _dbContext.Relationships
.AsNoTracking()
.WithParticipants(sender, recipient)
.OrderByDescending(r => r.CreatedAt)
.FirstOrDefaultAsync(cancellationToken);
}
}

0 comments on commit 2ef0ab7

Please sign in to comment.