From 1412c07fa279774837f188ba153e98f098d49445 Mon Sep 17 00:00:00 2001 From: cuqmbr Date: Sun, 15 Oct 2023 13:32:35 +0300 Subject: [PATCH] fix: return oredered wishlist messages Before that there was a possibility of returning pages with incorrectly ordered messages --- .../PersistanceExtentions/DbInitialaizer.cs | 10 +++++----- .../Repositories/MessagesRepository.cs | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ShoppingAssistantApi.Persistance/PersistanceExtentions/DbInitialaizer.cs b/ShoppingAssistantApi.Persistance/PersistanceExtentions/DbInitialaizer.cs index 6233c86..cd43f63 100644 --- a/ShoppingAssistantApi.Persistance/PersistanceExtentions/DbInitialaizer.cs +++ b/ShoppingAssistantApi.Persistance/PersistanceExtentions/DbInitialaizer.cs @@ -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 { diff --git a/ShoppingAssistantApi.Persistance/Repositories/MessagesRepository.cs b/ShoppingAssistantApi.Persistance/Repositories/MessagesRepository.cs index 801963e..02d309d 100644 --- a/ShoppingAssistantApi.Persistance/Repositories/MessagesRepository.cs +++ b/ShoppingAssistantApi.Persistance/Repositories/MessagesRepository.cs @@ -33,6 +33,7 @@ public class MessagesRepository : BaseRepository, IMessagesRepository } return await _collection.Find(predicate) + .SortBy(x => x.CreatedDateUtc) .Skip((numberOfPages - pageNumber) * pageSize) .Limit(pageSize) .ToListAsync(cancellationToken);