Files
criminalmindsapi/server/Persistence/Repositories/QuoteRepository.cs
T

45 lines
1.1 KiB
C#
Raw Normal View History

2022-06-23 13:26:21 -05:00
using MongoDB.Driver;
using MongoDB.Driver.Linq;
2022-06-23 13:26:21 -05:00
using server.Models;
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-23 13:26:21 -05:00
try
{
var query = _context.Quotes.AsQueryable();
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;
}
}
// TODO: Implement GetQuoteByIdAsync() method.
public Task<Quote> GetQuoteByIdAsync(int id)
{
throw new NotImplementedException();
}
}
}