From 37aaf55c4a1d5cf87a43a63306e9e209b691ee2c Mon Sep 17 00:00:00 2001 From: "maxime.rocher" Date: Fri, 10 Jan 2025 08:22:04 +0100 Subject: [PATCH] jsp --- .../WF-WebAdmin/Converter/DailyQuoteDTO.cs | 12 ++ .../Converter/DailyQuoteExtension.cs | 13 ++ WF-WebAdmin/WF-WebAdmin/Model/DailyQuote.cs | 12 ++ WF-WebAdmin/WF-WebAdmin/Model/Quote.cs | 21 +++ .../WF-WebAdmin/Pages/ValidQuote.razor.cs | 125 +----------------- .../WF-WebAdmin/Service/QuoteServiceStub.cs | 16 +++ 6 files changed, 75 insertions(+), 124 deletions(-) create mode 100644 WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDTO.cs create mode 100644 WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs create mode 100644 WF-WebAdmin/WF-WebAdmin/Model/DailyQuote.cs create mode 100644 WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDTO.cs b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDTO.cs new file mode 100644 index 0000000..0fb7042 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteDTO.cs @@ -0,0 +1,12 @@ +namespace WF_WebAdmin.Converter +{ + public class DailyQuoteDTO + { + private int Id { get; set; } + + public DailyQuoteDTO(int id) + { + this.Id = id; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs new file mode 100644 index 0000000..63ec57e --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/DailyQuoteExtension.cs @@ -0,0 +1,13 @@ +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Converter +{ + public class DailyQuoteExtension + { + public DailyQuoteDTO DailyQuoteToDTO(DailyQuote dq) + { + DailyQuoteDTO dailyQuote = new DailyQuoteDTO(dq.Id); + return dailyQuote; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/DailyQuote.cs b/WF-WebAdmin/WF-WebAdmin/Model/DailyQuote.cs new file mode 100644 index 0000000..a60d8a7 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/DailyQuote.cs @@ -0,0 +1,12 @@ +namespace WF_WebAdmin.Model +{ + public class DailyQuote + { + public int Id { get; set; } + + public DailyQuote(int Id) + { + this.Id = Id; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs index 9fcb751..dc1b304 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs @@ -10,6 +10,27 @@ public DateTime DateSrc { get; set; } public int Like { get; set; } public string Langue { get; set; } +<<<<<<< Updated upstream public string UserProposition { get; set; } +======= + public bool IsValide { get; set; } + public string? Reason { get; set; } + public int IdCaracter { get; set; } + public int IdSource { get; set; } + public int? IdUserVerif { get; set; } + + public Quote(int id, string content, int likes, string langue, bool isValide, string? reason, int idCaracter, int idSource, int? idUserVerif) + { + Id = id; + Content = content; + Likes = likes; + Langue = langue; + IsValide = isValide; + Reason = reason; + IdCaracter = idCaracter; + IdSource = idSource; + IdUserVerif = idUserVerif; + } +>>>>>>> Stashed changes } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs index a42112a..070ee4e 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -11,129 +11,6 @@ namespace WF_WebAdmin.Pages { public partial class ValidQuote { - // Chaîne de connexion à adapter - private const string connectionString = - "Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres"; - - private List quotes; - - protected override async Task OnInitializedAsync() - { - // On charge toutes les citations dont isValide = false - quotes = await LoadNotValidatedQuotesAsync(); - } - - /// - /// Charge toutes les citations non validées (isValide = false) - /// et mappe les colonnes vers ton modèle. - /// - private async Task> LoadNotValidatedQuotesAsync() - { - var result = new List(); - - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - // Sélection des colonnes réellement présentes en DB - // + placeholders pour les autres - var sql = @" - SELECT - id_quote AS Id, - content AS Content, - likes AS ""Like"", - langue AS Langue, - -- Champs pas vraiment en DB : placeholders - '' AS Charac, - '' AS ImgPath, - '' AS TitleSrc, - now() AS DateSrc, - '' AS UserProposition - FROM quote - WHERE isValide = false - "; - - using var cmd = new NpgsqlCommand(sql, con); - using var reader = await cmd.ExecuteReaderAsync(); - - while (await reader.ReadAsync()) - { - var q = new Quote - { - Id = reader.GetInt32(reader.GetOrdinal("Id")), - Content = reader.GetString(reader.GetOrdinal("Content")), - Like = reader.GetInt32(reader.GetOrdinal("Like")), - Langue = reader.GetString(reader.GetOrdinal("Langue")), - // placeholders - Charac = reader.GetString(reader.GetOrdinal("Charac")), - ImgPath = reader.GetString(reader.GetOrdinal("ImgPath")), - TitleSrc = reader.GetString(reader.GetOrdinal("TitleSrc")), - DateSrc = reader.GetDateTime(reader.GetOrdinal("DateSrc")), - UserProposition = reader.GetString(reader.GetOrdinal("UserProposition")) - }; - result.Add(q); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] LoadNotValidatedQuotesAsync : {ex.Message}"); - } - - return result; - } - - /// - /// Met à jour isValide = true pour la citation. - /// - private async Task ValiderQuote(int quoteId) - { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "UPDATE quote SET isValide = true WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - // Supprime la quote de la liste pour l'enlever de l'affichage - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] ValiderQuote : {ex.Message}"); - } - } - - /// - /// Supprime complètement la citation de la base. - /// - private async Task RejeterQuote(int quoteId) - { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "DELETE FROM quote WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] RejeterQuote : {ex.Message}"); - } - } + } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs new file mode 100644 index 0000000..e3e9f5d --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Model; +using static System.Net.WebRequestMethods; + +namespace WF_WebAdmin.Service +{ + public class QuoteServiceStub : IQuoteService + { + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + } +}