using System.Linq.Expressions; using MongoDB.Bson; using MongoDB.Driver; using ShoppingAssistantApi.Application.IRepositories; using ShoppingAssistantApi.Domain.Entities; using ShoppingAssistantApi.Persistance.Database; namespace ShoppingAssistantApi.Persistance.Repositories; public class MessagesRepository : BaseRepository, IMessagesRepository { public MessagesRepository(MongoDbContext db) : base(db, "Messages") { } public async Task> GetPageStartingFromEndAsync(int pageNumber, int pageSize, Expression> predicate, CancellationToken cancellationToken) { return await _collection.Find(Builders.Filter.Where(predicate) & Builders.Filter.Where(x => !x.IsDeleted)) .SortByDescending(x => x.CreatedDateUtc) .Skip((pageNumber - 1) * pageSize) .Limit(pageSize) .ToListAsync(cancellationToken); } public Task> GetWishlistMessagesAsync(ObjectId wishlistId, CancellationToken cancellationToken) { return _collection .Find(x => !x.IsDeleted && x.WishlistId == wishlistId) .ToListAsync(cancellationToken); } }