diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs new file mode 100644 index 0000000..f8b0fea --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteDTO.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.DataProtection.KeyManagement; +using System; + +namespace WF_WebAdmin.Converter +{ + public class QuoteDTO + { + public int Id { get; set; } + public string Content { get; set; } + public int Likes { get; set; } + public string Langue { 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 QuoteDTO(int id_quote, string content, int likes, string langue, bool isValide, string? reason, int id_caracter, int id_source, int? id_user_verif) + { + this.Id = id_quote; + this.Content = content; + this.Likes = likes; + this.Langue = langue; + this.IsValide = isValide; + this.Reason = reason; + this.IdCaracter = id_caracter; + this.IdSource = id_source; + this.IdUserVerif = id_user_verif; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs new file mode 100644 index 0000000..0f3b187 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/QuoteExtension.cs @@ -0,0 +1,19 @@ +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Converter +{ + public class QuoteExtension + { + public QuoteDTO QuoteToDTO(Quote q) + { + QuoteDTO quote = new QuoteDTO(q.Id, q.Content, q.Likes, q.Langue, q.IsValide, q.Reason, q.IdCaracter, q.IdSource, q.IdUserVerif); + return quote; + } + + public Quote DTOToQuote(QuoteDTO q) + { + Quote quote = new Quote(q.Id, q.Content, q.Likes, q.Langue, q.IsValide, q.Reason, q.IdCaracter, q.IdSource, q.IdUserVerif); + return quote; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/UserDTO.cs b/WF-WebAdmin/WF-WebAdmin/Converter/UserDTO.cs new file mode 100644 index 0000000..e1b64da --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/UserDTO.cs @@ -0,0 +1,20 @@ +namespace WF_WebAdmin.Converter +{ + public class UserDTO + { + public int Id { get; set; } + public string Image { get; set; } + public string Name { get; set; } + public string Email { get; set; } + public DateTime DateCreation { get; set; } + + public UserDTO(int id, string image, string name, string email, DateTime dateCreation) + { + this.Id = id; + this.Image = image; + this.Name = name; + this.Email = email; + this.DateCreation = dateCreation; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs b/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs new file mode 100644 index 0000000..4ff0937 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Converter/UserExtension.cs @@ -0,0 +1,19 @@ +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Converter +{ + public class UserExtension + { + public User UserToDTO(UserDTO u) + { + User user = new User(u.Id, u.Image, u.Name, u.Email, u.DateCreation); + return user; + } + + public UserDTO DTOToUser(User u) + { + UserDTO user = new UserDTO(u.Id, u.Image, u.Name, u.Email, u.DateCreation); + return user; + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs index dc1b304..c640723 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/Quote.cs @@ -4,21 +4,27 @@ { public int Id { get; set; } public string Content { get; set; } - public string Charac { get; set; } - public string ImgPath { get; set; } - public string TitleSrc { get; set; } - public DateTime DateSrc { get; set; } - public int Like { get; set; } + public int Likes { 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; + } + public Quote(int id, string content, int likes, string langue, bool isValide, string? reason, int idCaracter, int idSource, int? idUserVerif) { Id = id; @@ -31,6 +37,5 @@ IdSource = idSource; IdUserVerif = idUserVerif; } ->>>>>>> Stashed changes } } diff --git a/WF-WebAdmin/WF-WebAdmin/Model/User.cs b/WF-WebAdmin/WF-WebAdmin/Model/User.cs index 05671ab..6d74ac9 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/User.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/User.cs @@ -9,7 +9,14 @@ public string Email { get; set; } public DateTime DateCreation { get; set; } - public Boolean IsAdmin { get; set; } - public List Comments { get; set; } + + public User(int id, string image, string name, string email, DateTime dateCreation) + { + this.Id = id; + this.Image = image; + this.Name = name; + this.Email = email; + this.DateCreation = dateCreation; + } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor index da423b0..57f8ecc 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor @@ -21,13 +21,12 @@ else

ID : @quote.Id

Contenu : @quote.Content

Langue : @quote.Langue

-

Likes : @quote.Like

Personnage : @quote.Charac

Image : @quote.ImgPath

Source : @quote.TitleSrc

Date de source : @quote.DateSrc.ToShortDateString()

-

Utilisateur proposition : @quote.UserProposition

+

Utilisateur : @quote.UserProposition

diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs new file mode 100644 index 0000000..a76b4b0 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs @@ -0,0 +1,27 @@ +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Service +{ + public interface IQuoteService + { + public Task addQuote(Quote quote); + + public Task removeQuote(Quote quote); + + public Task validQuote(Quote quote); + + public Task updateQuote(Quote quote); + + public Task> getAllQuote(); + + public Task> getSomeQuote(int nb, int page); + + public Task> getOnequote(int id); + + public Task> reserchQuote(string reserch, List argument); + + public Task> getAllQuoteInvalid(); + + public Task> getSomeQuoteInvalid(int nb, int page); + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs new file mode 100644 index 0000000..1742e10 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs @@ -0,0 +1,21 @@ +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Service +{ + public interface IUserService + { + public void removeUser(User user); + + public void updateRole(User user); + + public void downgradeRole(User user); + + public List getAllUser(); + + public List getSomeUser(int nb, int page); + + public User getOneUser(int id); + + public List reserchUsers(string reserch, List args); + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs new file mode 100644 index 0000000..433e5d4 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs @@ -0,0 +1,119 @@ +using WF_WebAdmin.Converter; +using WF_WebAdmin.Model; +using Npgsql; + +namespace WF_WebAdmin.Service +{ + public class QuoteServiceLocal: IQuoteService + { + private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3"; + + + + + public async Task AddQuoteAsync(Quote quote) + { + QuoteExtension extension = new QuoteExtension(); + QuoteDTO quoteDTO = extension.QuoteToDTO(quote); + + // Utilisation de NpgsqlConnection pour PostgreSQL + using (var connection = new NpgsqlConnection(_connectionString)) + { + // Définir la requête SQL d'insertion + var commandText = "INSERT INTO Quote (content, langue, reason, id_source, id_caracter, id_user_verif, img_path) " + + "VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)"; + + // Créer une commande Npgsql + var command = new NpgsqlCommand(commandText, connection); + + // Ajouter des paramètres à la commande + command.Parameters.AddWithValue("@content", quote.Content); + command.Parameters.AddWithValue("@langue", quote.Langue); + command.Parameters.AddWithValue("@reason", "À vérifier"); // Vous pouvez changer ça si nécessaire + command.Parameters.AddWithValue("@source", quote.Source); + command.Parameters.AddWithValue("@character", quote.Character); + command.Parameters.AddWithValue("@user", quote.User); // Assurez-vous que `quote.User` est correctement défini + command.Parameters.AddWithValue("@img_path", quote.ImgPath); + + try + { + // Ouvrir la connexion à la base de données + await connection.OpenAsync(); + + // Exécuter la commande d'insertion + await command.ExecuteNonQueryAsync(); + } + catch (Exception ex) + { + // Gérer les erreurs ici (par exemple, afficher ou enregistrer les erreurs) + Console.WriteLine($"Une erreur est survenue lors de l'ajout de la citation : {ex.Message}"); + } + finally + { + // Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus) + await connection.CloseAsync(); + } + } + + // Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application + return quoteDTO; + } + } + + public Task RemoveQuote(Quote quote) + { + QuoteExtension extension = new QuoteExtension(); + QuoteDTO quoteDTO = extension.QuoteToDTO(quote); + + return Task.FromResult(quoteDTO); + } + + public Task validQuote(Quote quote) + { + QuoteExtension extension = new QuoteExtension(); + QuoteDTO quoteDTO = extension.QuoteToDTO(quote); + + return Task.FromResult(quoteDTO); + } + + public Task updateQuote(Quote quote) + { + QuoteExtension extension = new QuoteExtension(); + QuoteDTO quoteDTO = extension.QuoteToDTO(quote); + + return Task.FromResult(quoteDTO); + } + + public Task> getAllQuote() + { + + } + + public Task> getSomeQuote(int nb, int page) + { + + } + + public Task> getOnequote(int id) + { + + } + + public Task> reserchQuote(string reserch, List argument) + { + + } + + public Task> getAllQuoteInvalid() + { + + } + + public Task> getSomeQuoteInvalid(int nb, int page) + { + + } + + + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs index e3e9f5d..c603989 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using WF_WebAdmin.Model; using static System.Net.WebRequestMethods; @@ -12,5 +12,5 @@ namespace WF_WebAdmin.Service [Inject] public NavigationManager NavigationManager { get; set; } - } + } diff --git a/WF-WebAdmin/WF-WebAdmin/_Imports.razor b/WF-WebAdmin/WF-WebAdmin/_Imports.razor index f261bea..cbc1f08 100644 --- a/WF-WebAdmin/WF-WebAdmin/_Imports.razor +++ b/WF-WebAdmin/WF-WebAdmin/_Imports.razor @@ -9,3 +9,4 @@ @using WF_WebAdmin @using WF_WebAdmin.Shared @using Blazorise.DataGrid + diff --git a/WF-WebAdmin/WF-WebAdmin/appsettings.json b/WF-WebAdmin/WF-WebAdmin/appsettings.json index 4d56694..3ec194b 100644 --- a/WF-WebAdmin/WF-WebAdmin/appsettings.json +++ b/WF-WebAdmin/WF-WebAdmin/appsettings.json @@ -1,9 +1,12 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres" } - }, - "AllowedHosts": "*" }