Correction Lien Quote Controlleur
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
parent 5b01d086ad
commit 8471e6cfd5

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -48,12 +49,13 @@ namespace Contextlib
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 = _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(); .ToList();
Quote quote = _repo.GetById(date.DayNumber % quotes.Count()) ?? quotes.First(); if (quotes.Count() == 0) return null;
Quote quote = quotes[ date.DayNumber % quotes.Count() ] ;
return quote; return quote;
} }
@ -113,51 +115,115 @@ 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) // A changer Suggestion Random
{ {
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)
//.OrderBy(q=> new 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();
public async Task RemoveQuote(int quoteId) return new PaginationResult<Quote>(quotes.Count, index, pageSize, quotes);
{
throw new NotImplementedException();
} }
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)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage==(LangEnum)lang && (item.Character.Name).Contains(character))
.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>> SearchByContent(string content, int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> SearchByContent(string content, int index, int pageSize, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Content).Contains(content))
.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>> SearchBySource(string source, int index, int pageSize, int lang) public async Task<PaginationResult<Quote>> SearchBySource(string source, int index, int pageSize, int lang)
{ {
throw new NotImplementedException(); List<Quote> quotes = _context.quotes.Where(item => item.IsValid && item.Langage == (LangEnum)lang && (item.Source.Title).Contains(source))
.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 RemoveQuote(int quoteId)
{
_repo.Delete( _repo.GetById(quoteId) );
await _context.SaveChangesAsync();
} }
public async Task UpdateQuote(int quoteId, Quote quote) public async Task UpdateQuote(int quoteId, Quote quote)
{ {
throw new NotImplementedException(); Quote? q = _repo.GetById(quoteId);
if (q != null)
{
bool change = false;
if (quote.IdSource != 0)
{
q.IdSource = quote.IdSource;
change = true;
}
if (quote.IdCharacter != 0)
{
q.IdCharacter = quote.IdCharacter;
change = true;
}
if (quote.IdSource != 0)
{
q.IdSource = quote.IdSource;
change = true;
}
if (quote.IdUsersPropose !=0)
{
q.IdUsersPropose = quote.IdUsersPropose;
change = true;
}
if (quote.Content != null || quote.Content =="")
{
q.Content = quote.Content;
change = true;
}
_repo.Update(q);
if (change) _context.SaveChanges();
}
return ;
} }
public async Task ValidateQuote(int quoteId, bool isValidate) public async Task ValidateQuote(int quoteId, bool isValidate)
{ {
throw new NotImplementedException(); Quote? q = _repo.GetById(quoteId);
if (q != null)
{
q.IsValid = isValidate;
_repo.Update(q);
_context.SaveChanges();
}
return;
} }
} }
} }

@ -14,7 +14,6 @@ namespace Contextlib
//public DbSet<Admin> admins { get; set; } //public DbSet<Admin> admins { get; set; }
public DbSet<Character> characters { get; set; } public DbSet<Character> characters { get; set; }
public DbSet<Commentary> comments { get; set; } public DbSet<Commentary> comments { get; set; }
public DbSet<DailyQuote> dailyquotes { get; set; }
public DbSet<Favorite> favorites { get; set; } public DbSet<Favorite> favorites { get; set; }
public DbSet<Images> images { get; set; } public DbSet<Images> images { get; set; }
public DbSet<Question> question { get; set; } public DbSet<Question> question { get; set; }

@ -9,7 +9,6 @@ namespace DTO
public enum TypeLangageDTO public enum TypeLangageDTO
{ {
vo, vo,
vf, vf
ve
} }
} }

@ -225,7 +225,6 @@ namespace Dto2Entities
{ {
case LangEnum.vf: return TypeLangageDTO.vf; case LangEnum.vf: return TypeLangageDTO.vf;
case LangEnum.vo: return TypeLangageDTO.vo; case LangEnum.vo: return TypeLangageDTO.vo;
case LangEnum.ve: return TypeLangageDTO.ve;
default: return TypeLangageDTO.vo; default: return TypeLangageDTO.vo;
} }
} }
@ -456,7 +455,6 @@ namespace Dto2Entities
{ {
case TypeLangageDTO.vf: return LangEnum.vf; case TypeLangageDTO.vf: return LangEnum.vf;
case TypeLangageDTO.vo: return LangEnum.vo; case TypeLangageDTO.vo: return LangEnum.vo;
case TypeLangageDTO.ve: return LangEnum.ve;
default: return LangEnum.vo; default: return LangEnum.vo;
} }
} }

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entity
{
public class DailyQuote
{
[Key]
[ForeignKey(nameof(Quote))]
public int IdQuote { get; set; }
public Quote Quote { get; set; } = null!;
}
}

@ -9,7 +9,6 @@ namespace Entity
public enum LangEnum public enum LangEnum
{ {
vo, vo,
vf, vf
ve
} }
} }

@ -46,8 +46,6 @@ namespace Entity
public Character Character { get; set; } = null!; public Character Character { get; set; } = null!;
public ICollection<DailyQuote> DailyQuotes { get; set; } = new List<DailyQuote>();
public ICollection<Commentary> Commentarys { get; set; } = new List<Commentary>(); public ICollection<Commentary> Commentarys { get; set; } = new List<Commentary>();
public ICollection<Users> Favorite { get; } = new List<Users>(); public ICollection<Users> Favorite { get; } = new List<Users>();

@ -0,0 +1,61 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class suprDailyQuote : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "dailyquotes");
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "dailyquotes",
columns: table => new
{
IdQuote = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_dailyquotes", x => x.IdQuote);
table.ForeignKey(
name: "FK_dailyquotes_quotes_IdQuote",
column: x => x.IdQuote,
principalTable: "quotes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "dailyquotes",
column: "IdQuote",
values: new object[]
{
1,
5
});
migrationBuilder.UpdateData(
table: "quotes",
keyColumn: "Id",
keyValue: 10,
column: "IsValid",
value: true);
}
}
}

@ -173,26 +173,6 @@ namespace StubbedContextLib.Migrations
}); });
}); });
modelBuilder.Entity("Entity.DailyQuote", b =>
{
b.Property<int>("IdQuote")
.HasColumnType("int");
b.HasKey("IdQuote");
b.ToTable("dailyquotes");
b.HasData(
new
{
IdQuote = 1
},
new
{
IdQuote = 5
});
});
modelBuilder.Entity("Entity.Favorite", b => modelBuilder.Entity("Entity.Favorite", b =>
{ {
b.Property<int>("IdQuote") b.Property<int>("IdQuote")
@ -739,7 +719,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
}); });
@ -976,17 +956,6 @@ namespace StubbedContextLib.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Entity.DailyQuote", b =>
{
b.HasOne("Entity.Quote", "Quote")
.WithMany("DailyQuotes")
.HasForeignKey("IdQuote")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Quote");
});
modelBuilder.Entity("Entity.Favorite", b => modelBuilder.Entity("Entity.Favorite", b =>
{ {
b.HasOne("Entity.Quote", "Quote") b.HasOne("Entity.Quote", "Quote")
@ -1085,8 +1054,6 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entity.Quote", b => modelBuilder.Entity("Entity.Quote", b =>
{ {
b.Navigation("Commentarys"); b.Navigation("Commentarys");
b.Navigation("DailyQuotes");
}); });
modelBuilder.Entity("Entity.Source", b => modelBuilder.Entity("Entity.Source", b =>

@ -77,10 +77,6 @@ namespace StubbedContextLib
new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUser = 3 } new Commentary() { Id = 2, Comment = "Very good", DateCommentary = new DateTime(2025, 3, 11), IdQuote = 1, IdUser = 3 }
); );
modelBuilder.Entity<DailyQuote>().HasData(
new DailyQuote() { IdQuote = 1},
new DailyQuote() { IdQuote = 5}
);
modelBuilder.Entity<Favorite>().HasData( modelBuilder.Entity<Favorite>().HasData(
new Favorite() { IdQuote = 2, IdUsers = 8 }, new Favorite() { IdQuote = 2, IdUsers = 8 },

@ -196,7 +196,7 @@ namespace WfApi.Controllers
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
} }
} }
[HttpGet("searchByCharac")] [HttpGet("searchBySource")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesResponseType(StatusCodes.Status500InternalServerError)]

@ -5,6 +5,7 @@ using Contextlib;
using Entity; using Entity;
using StubbedContextLib; using StubbedContextLib;
using ServicesApi; using ServicesApi;
using Microsoft.EntityFrameworkCore;
//API //API
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -14,7 +15,7 @@ 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>();
@ -27,8 +28,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<Source>, DbSourceManager>();
builder.Services.AddScoped<IQuestionService<QuestionDTO>, QuestionService>(); builder.Services.AddScoped<IQuestionService<Question>, DbQuestionManager>();
//... //...
// Add services to the container. // Add services to the container.

Loading…
Cancel
Save