shopping-assistant-api/ShoppingAssistantApi.Persistance/Repositories/MessagesRepository.cs
shchoholiev 68ab565800 SA-197 Add suggestions to product search
- Change OpenAI prompt
- Update logic OpenAI response handling
- Start refactoring of  SearchProductAsync()
- Add GetWishlistMessagesAsync() to MessagesRepository to retrieve all messages for wishlist
2023-12-11 00:49:08 +00:00

30 lines
1.2 KiB
C#

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<Message>, IMessagesRepository
{
public MessagesRepository(MongoDbContext db) : base(db, "Messages") { }
public async Task<List<Message>> GetPageStartingFromEndAsync(int pageNumber, int pageSize, Expression<Func<Message, bool>> predicate, CancellationToken cancellationToken)
{
return await _collection.Find(Builders<Message>.Filter.Where(predicate) & Builders<Message>.Filter.Where(x => !x.IsDeleted))
.SortByDescending(x => x.CreatedDateUtc)
.Skip((pageNumber - 1) * pageSize)
.Limit(pageSize)
.ToListAsync(cancellationToken);
}
public Task<List<Message>> GetWishlistMessagesAsync(ObjectId wishlistId, CancellationToken cancellationToken)
{
return _collection
.Find(x => !x.IsDeleted && x.WishlistId == wishlistId)
.ToListAsync(cancellationToken);
}
}