fix: return oredered wishlist messages

Before that there was a possibility of returning pages with incorrectly ordered messages
This commit is contained in:
cuqmbr 2023-10-15 13:32:35 +03:00
parent b9a58a963a
commit 1412c07fa2
Signed by: cuqmbr
GPG Key ID: 2D72ED98B6CB200F
2 changed files with 6 additions and 5 deletions

View File

@ -218,7 +218,7 @@ public class DbInitialaizer
Text = "Message 2",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId1,
CreatedDateUtc = DateTime.UtcNow
CreatedDateUtc = DateTime.UtcNow.AddSeconds(5)
},
new Message
{
@ -226,14 +226,14 @@ public class DbInitialaizer
Role = MessageRoles.User.ToString(),
WishlistId = wishlistId1,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
CreatedDateUtc = DateTime.UtcNow.AddSeconds(20)
},
new Message
{
Text = "Message 4",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId1,
CreatedDateUtc = DateTime.UtcNow
CreatedDateUtc = DateTime.UtcNow.AddSeconds(25)
},
new Message
{
@ -241,14 +241,14 @@ public class DbInitialaizer
Role = MessageRoles.User.ToString(),
WishlistId = wishlistId1,
CreatedById = user1.Id,
CreatedDateUtc = DateTime.UtcNow
CreatedDateUtc = DateTime.UtcNow.AddSeconds(45)
},
new Message
{
Text = "Message 6",
Role = MessageRoles.Application.ToString(),
WishlistId = wishlistId1,
CreatedDateUtc = DateTime.UtcNow
CreatedDateUtc = DateTime.UtcNow.AddSeconds(50)
},
new Message
{

View File

@ -33,6 +33,7 @@ public class MessagesRepository : BaseRepository<Message>, IMessagesRepository
}
return await _collection.Find(predicate)
.SortBy(x => x.CreatedDateUtc)
.Skip((numberOfPages - pageNumber) * pageSize)
.Limit(pageSize)
.ToListAsync(cancellationToken);