2022-06-23 13:26:21 -05:00
|
|
|
using MongoDB.Driver;
|
2022-06-23 15:43:39 -05:00
|
|
|
using MongoDB.Driver.Linq;
|
2022-06-23 13:26:21 -05:00
|
|
|
using server.Models;
|
2022-06-22 11:28:44 -05:00
|
|
|
|
|
|
|
|
namespace server.Persistence.Repositories
|
|
|
|
|
{
|
|
|
|
|
public class QuoteRepository : IQuoteRepository
|
|
|
|
|
{
|
|
|
|
|
private readonly IDbContext _context;
|
|
|
|
|
|
|
|
|
|
public QuoteRepository(IDbContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 13:26:21 -05:00
|
|
|
// TODO: Implement optional, but possible filters for query.
|
|
|
|
|
public async Task<List<Quote>> GetQuotesAsync(QuoteFilter filter)
|
2022-06-22 11:28:44 -05:00
|
|
|
{
|
2022-06-23 13:26:21 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var query = _context.Quotes.AsQueryable();
|
2022-06-23 15:43:39 -05:00
|
|
|
|
|
|
|
|
if (filter?.Narrator != null)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(quote => quote.Narrator!.ToLower().Contains(filter.Narrator.ToLower()));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 13:26:21 -05:00
|
|
|
return await query.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2022-06-22 11:28:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Implement GetQuoteByIdAsync() method.
|
|
|
|
|
public Task<Quote> GetQuoteByIdAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|