mise en fonction de certaine routes

pull/6/head
Kevin MONDEJAR 3 weeks ago
parent 5b01d086ad
commit 42face1ba2

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Entity; using Entity;
@ -42,18 +43,24 @@ namespace Contextlib
public async Task<PaginationResult<Quote>> GetAllQuoteLang(int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> GetAllQuoteLang(int index, int pageSize, int lang)
{ {
List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) List<Quote> quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
.Skip(index * pageSize).Take(pageSize).ToList(); .Skip(index * pageSize).Take(pageSize).ToListAsync();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes); 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)
{ {
List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang) List<Quote> quotes = await _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite) .Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
.ToList(); .ToListAsync();
Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First();
Quote quote = quotes[date.DayNumber % quotes.Count()];
/*Quote quote = await _context.quotes.Where(item => item.Id == date.DayNumber % quotes.Count())
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images).Include(q => q.Favorite)
.FirstOrDefaultAsync() ?? quotes.First();*/
//Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First();
return quote; return quote;
} }
@ -113,17 +120,29 @@ namespace Contextlib
public async Task<PaginationResult<Quote>> GetSomeQuote(int index, int pageSize) public async Task<PaginationResult<Quote>> GetSomeQuote(int index, int pageSize)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
.Skip(index * pageSize).Take(pageSize).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<PaginationResult<Quote>> GetSuggestions(int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> GetSuggestions(int index, int pageSize, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images) // rajouter un mélange random
.Skip(index * pageSize).Take(pageSize).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
public async Task<PaginationResult<Quote>> GetValidQuote(int index, int pageSize) public async Task<PaginationResult<Quote>> GetValidQuote(int index, int pageSize)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid)
.Include(q => q.Source).Include(q => q.Character).ThenInclude(c => c.Images)
.Skip(index * pageSize).Take(pageSize).ToList();
return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
} }
@ -132,7 +151,8 @@ namespace Contextlib
public async Task RemoveQuote(int quoteId) public async Task RemoveQuote(int quoteId)
{ {
throw new NotImplementedException(); _repo.Delete(quoteId);
await _context.SaveChangesAsync();
} }
public async Task<PaginationResult<Quote>> SearchByCharacter(string character, int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> SearchByCharacter(string character, int index, int pageSize, int lang)

@ -164,6 +164,7 @@ namespace Dto2Entities
quote.ImagePath = item.Character.Images.ImgPath; quote.ImagePath = item.Character.Images.ImgPath;
quote.Like = item.Likes; quote.Like = item.Likes;
quote.Type = item.Source.TypeSrc.ToDto(); quote.Type = item.Source.TypeSrc.ToDto();
quote.IsValide = item.IsValid;
return quote; return quote;
} }

@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class myFirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: true);
}
}
}

@ -739,7 +739,7 @@ namespace StubbedContextLib.Migrations
IdCharacter = 10, IdCharacter = 10,
IdSource = 4, IdSource = 4,
IdUsersPropose = 1, IdUsersPropose = 1,
IsValid = true, IsValid = false,
Langage = 1, Langage = 1,
Likes = 11025 Likes = 11025
}); });

@ -87,6 +87,7 @@ namespace WfApi.Controllers
if (result != null) if (result != null)
{ {
return await Task.FromResult<IActionResult>(Ok(result)); return await Task.FromResult<IActionResult>(Ok(result));
//return Ok(result));
} }
else else
{ {

@ -14,8 +14,8 @@ builder.Services.AddScoped<IQuoteService<QuoteDTO>, QuoteService>();
builder.Services.AddScoped<ICommentaryService<CommentaryDTO>, CommentaryService>(); builder.Services.AddScoped<ICommentaryService<CommentaryDTO>, CommentaryService>();
builder.Services.AddScoped<ICharacterService<CharacterDTO>, CharacterService>(); builder.Services.AddScoped<ICharacterService<CharacterDTO>, CharacterService>();
builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>(); builder.Services.AddScoped<IImagesService<ImageDTO>, ImageService>();
builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>(); /*builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>(); builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>();*/
//EF //EF
@ -27,8 +27,8 @@ builder.Services.AddScoped<IQuoteService<Quote>, DbQuoteManager>();
builder.Services.AddScoped<ICommentaryService<Commentary>, DbCommentaryManager>(); builder.Services.AddScoped<ICommentaryService<Commentary>, DbCommentaryManager>();
builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>(); builder.Services.AddScoped<ICharacterService<Character>, DbCharacterManager>();
builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>(); builder.Services.AddScoped<IImagesService<Images>, DbImagesManager>();
builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>(); /*builder.Services.AddScoped<ISourceService<SourceDTO>, SourceService>();
builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>(); builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>();*/
//... //...
// Add services to the container. // Add services to the container.

Loading…
Cancel
Save