mirror of
https://github.com/Shchoholiev/shopping-assistant-api.git
synced 2025-04-03 16:19:46 +00:00
- Change OpenAI prompt - Update logic OpenAI response handling - Start refactoring of SearchProductAsync() - Add GetWishlistMessagesAsync() to MessagesRepository to retrieve all messages for wishlist
30 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|