Avancement DbQuoteManager

pull/6/head
kekentin 3 weeks ago
parent 4b1edf0e16
commit b7a0800b08

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Entity; using Entity;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Shared; using Shared;
namespace Contextlib namespace Contextlib
@ -35,43 +36,80 @@ namespace Contextlib
public async Task<PaginationResult<Quote>> GetAllQuote() public async Task<PaginationResult<Quote>> GetAllQuote()
{ {
List<Quote> quotes = _repo.GetItems(0, _repo.Count(), [nameof(Quote.Id)]).ToList(); List<Quote> quotes = _repo.GetItems(item=> item.IsValid,
0, _repo.Count(), []
).ToList();
return new PaginationResult<Quote>(quotes.Count, 0, quotes.Count, quotes); return new PaginationResult<Quote>(quotes.Count, 0, quotes.Count, quotes);
} }
public async Task<PaginationResult<Quote>> GetAllQuoteLang(int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> GetAllQuoteLang(int index, int pageSize, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _repo.GetItems(item => item.IsValid && item.Langage==(LangEnum)lang ,
index, pageSize, []
).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<Quote> GetDailyQuote(DateOnly date, int lang) public async Task<Quote> GetDailyQuote(DateOnly date, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _repo.GetItems(item => item.IsValid && item.Langage == (LangEnum)lang,
0, _repo.Count(), []
).ToList();
Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First();
return quote;
} }
public async Task<PaginationResult<Quote>> GetFavorites(int index, int pageSize, int UserId) public async Task<PaginationResult<Quote>> GetFavorites(int index, int pageSize, int UserId)
{ {
throw new NotImplementedException(); List<Quote> quotes = _repo.GetItems(item => item.IsValid && item.Favorite.Where(p=>p.Id==UserId)!=null ,
index, pageSize, [nameof(Quote.Favorite)]
).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<PaginationResult<Quote>> GetInvalidQuote(int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> GetInvalidQuote(int index, int pageSize, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _repo.GetItems(item => !item.IsValid && item.Langage == (LangEnum)lang,
index, pageSize, []
).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<PaginationResult<Quote>> GetInvalidQuote(int index, int pageSize) public async Task<PaginationResult<Quote>> GetInvalidQuote(int index, int pageSize)
{ {
throw new NotImplementedException(); List<Quote> quotes = _repo.GetItems(item => !item.IsValid,
index, pageSize, []
).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<int> GetLastQuoteId() public async Task<int> GetLastQuoteId()
{ {
throw new NotImplementedException(); PaginationResult<Quote> users = await GetAllQuote();
int lastQuoteId = 0;
foreach (Quote quote in users.items)
{
if (quote.Id >= lastQuoteId)
{
lastQuoteId = quote.Id + 1;
}
}
return lastQuoteId;
} }
public async Task<Quote> GetQuoteById(int id) public async Task<Quote> GetQuoteById(int id)
{ {
throw new NotImplementedException(); Quote? quote = _repo.GetById(id, item => item.Id == id, []);
if (quote == null)
{
throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}.");
}
return quote;
} }
public async Task<PaginationResult<Quote>> GetSomeQuote(int index, int pageSize) public async Task<PaginationResult<Quote>> GetSomeQuote(int index, int pageSize)

@ -13,6 +13,7 @@ builder.Services.AddScoped<IQuoteService<QuoteDTO>, QuoteService>();
//EF //EF
builder.Services.AddScoped<WTFContext, StubWTFContext>(); builder.Services.AddScoped<WTFContext, StubWTFContext>();
builder.Services.AddScoped<IUserService<Users>, DbUsersManager>(); builder.Services.AddScoped<IUserService<Users>, DbUsersManager>();
builder.Services.AddScoped<IQuoteService<Quote>, DbQuoteManager>(); builder.Services.AddScoped<IQuoteService<Quote>, DbQuoteManager>();
//builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>(); //builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>();

Loading…
Cancel
Save